unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Sarah Morgensen <iskarian@mgsn.dev>
To: 50072@debbugs.gnu.org
Subject: [bug#50072] [PATCH WIP 4/4] upstream: Support updating git-fetch origins.
Date: Sun, 15 Aug 2021 16:25:27 -0700	[thread overview]
Message-ID: <8d1ae518b23fac5b15812a30b11df1c360ab3fbf.1629068119.git.iskarian@mgsn.dev> (raw)
In-Reply-To: <cover.1629068119.git.iskarian@mgsn.dev>

* guix/git-download.scm (checkout-to-store): New procedure.
* guix/upstream.scm (guess-version-transform)
(package-update/git-fetch): New procedures.
(%method-updates): Add GIT-FETCH mapping.
---
 guix/git-download.scm | 18 +++++++++++++++++-
 guix/upstream.scm     | 41 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/guix/git-download.scm b/guix/git-download.scm
index 5e624b9ae9..a7bdc16718 100644
--- a/guix/git-download.scm
+++ b/guix/git-download.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2017 Mathieu Lirzin <mthl@gnu.org>
 ;;; Copyright © 2017 Christopher Baines <mail@cbaines.net>
 ;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
+;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -26,6 +27,7 @@
   #:use-module (guix records)
   #:use-module (guix packages)
   #:use-module (guix modules)
+  #:use-module (guix git)
   #:autoload   (guix build-system gnu) (standard-packages)
   #:autoload   (git bindings)   (libgit2-init!)
   #:autoload   (git repository) (repository-open
@@ -53,7 +55,9 @@
             git-fetch
             git-version
             git-file-name
-            git-predicate))
+            git-predicate
+
+            checkout-to-store))
 
 ;;; Commentary:
 ;;;
@@ -287,4 +291,16 @@ absolute file name and STAT is the result of 'lstat'."
             (#f        #f)))))
     (const #f)))
 
+(define* (checkout-to-store store ref #:key (log (current-error-port)))
+  "Checkout REF to STORE.  Write progress reports to LOG.  RECURSIVE? has the
+same effect as the same-named parameter of 'latest-repository-commit'."
+  ;; XXX: (guix git) does not use shallow clones, so this will be slow
+  ;; for long-running repositories.
+  (match-record ref <git-reference>
+    (url commit recursive?)
+    (latest-repository-commit store url
+                              #:ref `(tag-or-commit . ,commit)
+                              #:recursive? recursive?
+                              #:log-port log)))
+
 ;;; git-download.scm ends here
diff --git a/guix/upstream.scm b/guix/upstream.scm
index 632e9ebc4f..927260cd89 100644
--- a/guix/upstream.scm
+++ b/guix/upstream.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2015 Alex Kost <alezost@gmail.com>
 ;;; Copyright © 2019 Ricardo Wurmus <rekado@elephly.net>
+;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -24,6 +25,7 @@
   #:use-module (guix discovery)
   #:use-module ((guix download)
                 #:select (download-to-store url-fetch))
+  #:use-module (guix git-download)
   #:use-module (guix gnupg)
   #:use-module (guix packages)
   #:use-module (guix diagnostics)
@@ -430,9 +432,46 @@ SOURCE, an <upstream-source>."
                                         #:key-download key-download)))
          (values version tarball source))))))
 
+(define (guess-version-transform commit from-version)
+  "Return a one-argument proc that transforms FROM-VERSION to COMMIT, or #f
+if no such transformation could be determined."
+  ;; Just handle prefixes for now, since that's the most common.
+  (if (string-suffix? from-version commit)
+      (let* ((version-length (string-length from-version))
+             (commit-prefix (string-drop-right commit version-length)))
+        (lambda (version)
+          (string-append commit-prefix version)))
+      #f))
+
+(define* (package-update/git-fetch store package source
+                                   #:key key-download)
+  "Return the version, checkout, and SOURCE, to update PACKAGE to
+SOURCE, an <upstream-source>."
+
+  (define (uri-update/git old-uri old-version url version)
+    (let* ((old-commit (git-reference-commit old-uri))
+           (transform (guess-version-transform old-commit old-version)))
+      (and transform
+           (git-reference
+            (inherit old-uri)
+            (url url)
+            (commit (transform version))))))
+
+  ;; Only use the first element of URLS.
+  (match-record source <upstream-source>
+    (version urls)
+    (let* ((old-uri (origin-uri (package-source package)))
+           (old-version (package-version package))
+           (new-uri (uri-update/git old-uri old-version
+                                    (first urls) version)))
+      (if new-uri
+          (values version (checkout-to-store store new-uri) source)
+          (values #f #f #f)))))
+
 (define %method-updates
   ;; Mapping of origin methods to source update procedures.
-  `((,url-fetch . ,package-update/url-fetch)))
+  `((,url-fetch . ,package-update/url-fetch)
+    (,git-fetch . ,package-update/git-fetch)))
 
 (define* (package-update store package
                          #:optional (updaters (force %updaters))
-- 
2.31.1





  parent reply	other threads:[~2021-08-15 23:26 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-15 23:16 [bug#50072] [PATCH WIP 0/4] Add upstream updater for git-fetch origins Sarah Morgensen
2021-08-15 23:25 ` [bug#50072] [PATCH WIP 1/4] guix hash: Extract file hashing procedures Sarah Morgensen
2021-08-15 23:25 ` [bug#50072] [PATCH WIP 2/4] import: Factorize file hashing Sarah Morgensen
2021-08-15 23:25 ` [bug#50072] [PATCH WIP 3/4] refresh: Support non-tarball sources Sarah Morgensen
2021-08-15 23:25 ` Sarah Morgensen [this message]
2021-08-16 10:46   ` [bug#50072] [PATCH WIP 4/4] upstream: Support updating git-fetch origins Maxime Devos
2021-08-16 13:02     ` Xinglu Chen
2021-08-16 18:15       ` Maxime Devos
2021-08-18 14:45         ` Xinglu Chen
2021-08-16 19:56     ` [bug#50072] [PATCH WIP 0/4] Add upstream updater for " Sarah Morgensen
2021-08-17 10:18       ` Maxime Devos
2021-08-30 21:36         ` Maxime Devos
2021-09-06 10:23         ` Ludovic Courtès
2021-09-06 11:47           ` Maxime Devos
2021-09-07  1:16     ` [bug#50072] [PATCH WIP 4/4] upstream: Support updating " Sarah Morgensen
2021-09-07 10:00       ` Maxime Devos
2021-09-07 17:51         ` Sarah Morgensen
2021-09-07 20:58           ` Maxime Devos
2021-09-06 10:27   ` [bug#50072] [PATCH WIP 0/4] Add upstream updater for " Ludovic Courtès
2021-09-07  1:59     ` Sarah Morgensen
2021-09-29 21:28       ` Ludovic Courtès
2021-11-17 15:03         ` Ludovic Courtès
2022-01-01 17:35 ` Maxime Devos
2022-01-01 20:39 ` [bug#50072] [PATCH v2 " Maxime Devos
2022-01-01 20:39   ` [bug#50072] [PATCH v2 1/4] guix hash: Extract file hashing procedures Maxime Devos
2022-01-01 20:39   ` [bug#50072] [PATCH v2 2/4] import: Factorize file hashing Maxime Devos
2022-01-01 20:39   ` [bug#50072] [PATCH v2 3/4] refresh: Support non-tarball sources Maxime Devos
2022-01-03 13:55     ` Ludovic Courtès
2022-01-01 20:39   ` [bug#50072] [PATCH v2 4/4] upstream: Support updating 'git-fetch' origins Maxime Devos
2022-01-03 14:02     ` Ludovic Courtès
2022-01-04 15:09 ` [bug#50072] [PATCH v3 0/4] Add upstream updater for git-fetch origins Maxime Devos
2022-01-04 15:09   ` [bug#50072] [PATCH v3 1/4] guix hash: Extract file hashing procedures Maxime Devos
2022-01-04 15:09   ` [bug#50072] [PATCH v3 2/4] import: Factorize file hashing Maxime Devos
2022-01-04 15:09   ` [bug#50072] [PATCH v3 3/4] refresh: Support non-tarball sources Maxime Devos
2022-01-04 15:09   ` [bug#50072] [PATCH v3 4/4] upstream: Support updating and fetching 'git-fetch' origins Maxime Devos
2022-01-04 19:05   ` [bug#50072] [PATCH v3 0/4] Add upstream updater for git-fetch origins Maxime Devos
2022-01-04 20:06 ` [bug#50072] [PATCH v4 " Maxime Devos
2022-01-04 20:06   ` [bug#50072] [PATCH v4 1/4] guix hash: Extract file hashing procedures Maxime Devos
2022-01-04 22:22     ` [bug#50072] [PATCH WIP 0/4] Add upstream updater for git-fetch origins zimoun
2022-01-05 10:07       ` Maxime Devos
2022-01-05 11:48         ` zimoun
2022-01-05 12:10           ` Maxime Devos
2022-01-06 10:06             ` Ludovic Courtès
2022-01-05 12:27           ` Maxime Devos
2022-01-05 12:58             ` zimoun
2022-01-05 14:06               ` Maxime Devos
2022-01-05 15:08                 ` zimoun
2022-01-05 15:54                   ` Maxime Devos
2022-01-06 10:13                 ` Ludovic Courtès
2022-01-06 10:32                   ` Maxime Devos
2022-01-06 11:19                   ` zimoun
2022-01-05 10:09       ` Maxime Devos
2022-01-04 20:06   ` [bug#50072] [PATCH v4 2/4] import: Factorize file hashing Maxime Devos
2022-01-04 20:06   ` [bug#50072] [PATCH v4 3/4] refresh: Support non-tarball sources Maxime Devos
2022-01-04 20:06   ` [bug#50072] [PATCH v4 4/4] upstream: Support updating and fetching 'git-fetch' origins Maxime Devos
2022-01-05 14:07 ` [bug#50072] [PATCH v5 1/4] guix hash: Extract file hashing procedures Maxime Devos
2022-01-05 14:07   ` [bug#50072] [PATCH v5 2/4] import: Factorize file hashing Maxime Devos
2022-01-05 14:07   ` [bug#50072] [PATCH v5 3/4] refresh: Support non-tarball sources Maxime Devos
2022-01-05 14:07   ` [bug#50072] [PATCH v5 4/4] upstream: Support updating and fetching 'git-fetch' origins Maxime Devos
2022-01-05 15:57   ` [bug#50072] [PATCH v5 1/4] guix hash: Extract file hashing procedures zimoun
2022-01-05 15:56 ` Maxime Devos
2022-01-05 15:56   ` [bug#50072] [PATCH v5 2/4] import: Factorize file hashing Maxime Devos
2022-01-05 15:56   ` [bug#50072] [PATCH v5 3/4] refresh: Support non-tarball sources Maxime Devos
2022-01-05 15:56   ` [bug#50072] [PATCH v5 4/4] upstream: Support updating and fetching 'git-fetch' origins Maxime Devos
2022-01-06 10:20     ` bug#50072: [PATCH WIP 0/4] Add upstream updater for git-fetch origins Ludovic Courtès
2022-01-06 14:12       ` [bug#50072] " Maxime Devos

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8d1ae518b23fac5b15812a30b11df1c360ab3fbf.1629068119.git.iskarian@mgsn.dev \
    --to=iskarian@mgsn.dev \
    --cc=50072@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).