Subject: [PATCH 02/21] import: utils: Change git->origin function to git->origin+version.

From: Nicolas Graves <[email-masked]>
Date: Wed, 15 Mar 2023 13:51:11 +0100

---
 guix/import/go.scm    |  2 +-
 guix/import/utils.scm | 50 +++++++++++++++++++++++++++----------------
 2 files changed, 33 insertions(+), 19 deletions(-)

diff --git a/guix/import/go.scm b/guix/import/go.scm
index f264715fbd..3be82ed164 100644
--- a/guix/import/go.scm
+++ b/guix/import/go.scm
@@ -510,7 +510,7 @@ (define* (vcs->origin vcs-type vcs-repo-url version
 which takes version as an input."
   (case vcs-type
     ((git)
-     (git->origin vcs-repo-url `(tag-or-commit . ,version) transform-version))
+      (git->origin vcs-repo-url `(tag-or-commit . ,version) transform-version))
     ((hg)
      `(origin
         (method hg-fetch)
diff --git a/guix/import/utils.scm b/guix/import/utils.scm
index 529d7f11f8..171dca54e8 100644
--- a/guix/import/utils.scm
+++ b/guix/import/utils.scm
@@ -65,6 +65,7 @@ (define-module (guix import utils)
 
             url-fetch
             guix-hash-url
+            git->origin+dir
             git->origin
 
             package-names->package-inputs
@@ -156,9 +157,12 @@ (define (guix-hash-url filename)
   "Return the hash of FILENAME in nix-base32 format."
   (bytevector->nix-base32-string (file-sha256 filename)))
 
-(define* (git->origin repo-url ref #:optional ref->commit)
-  "Generate the `origin' block of a package depending on the git source
-control system. REPO-URL or REF can be null."
+(define* (git->origin+dir repo-url ref #:optional ref->commit)
+  "Returns a generated `origin' block of a package depending on the git source
+control system, and the directory in the store where the package has been
+downloaded, in case further processing is necessary.  REPO-URL or REF can be
+null. REF->COMMIT can be a function or #t, in which case the commit matching
+ref is used. If REF->COMMIT is not used, the value inside REF is used."
   (let-values (((directory commit)
                 (with-store store
                   (latest-repository-commit store repo-url #:ref ref))))
@@ -172,21 +176,31 @@ (define* (git->origin repo-url ref #:optional ref->commit)
                        version)
                       (_
                        (ref->commit version)))))
-      `(origin
-         (method git-fetch)
-         (uri (git-reference
-               (url ,(and (not (eq? repo-url 'null)) repo-url))
-               (commit ,vcommit)))
-         (file-name (git-file-name name version))
-         (sha256
-          (base32
-           ,(if (pair? ref)
-                (bytevector->nix-base32-string
-                 (file-hash* directory
-                             ;; 'git-fetch' already filtered out the '.git' directory.
-                             #:select? (const #true)
-                             #:recursive? #true))
-                #f)))))))
+      (values
+       `(origin
+          (method git-fetch)
+          (uri (git-reference
+                (url ,(and (not (eq? repo-url 'null)) repo-url))
+                (commit ,vcommit)))
+          (file-name (git-file-name name version))
+          (sha256
+           (base32
+            ,(if (pair? ref)
+                 (bytevector->nix-base32-string
+                  (file-hash* directory
+                              ;; 'git-fetch' already filtered out the '.git' directory.
+                              #:select? (const #true)
+                              #:recursive? #true))
+                 #f))))
+       directory))))
+
+(define* (git->origin repo-url ref #:optional ref->commit)
+  "Returns a generated `origin' block of a package depending on the git source
+control system.  REPO-URL or REF can be null. REF->COMMIT can be a function or
+#t, in which case the commit matching ref is used. If REF->COMMIT is not used,
+the value inside REF is used."
+  (let-values (((origin _) (git->origin+dir repo-url ref ref->commit)))
+    origin))
 
 (define %spdx-license-identifiers
   ;; https://spdx.org/licenses/
-- 
2.39.2