diff mbox series

[bug#73126,v2,1/2] download: Add git-source.

Message ID 6857a5838688c629dc90efd5fe3769a7d4301223.1726495443.git.herman@rimm.ee
State New
Headers show
Series Add git-source procedure. | expand

Commit Message

Herman Rimm Sept. 16, 2024, 4:29 p.m. UTC
* guix/git-download.scm (git-source): Add and export procedure.
* doc/guix.texi (origin Reference): Document git-source.

Change-Id: I40c24ff10135e4895c5319f969005ba1c09760db
---
 doc/guix.texi         |  7 +++++++
 guix/git-download.scm | 12 +++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/doc/guix.texi b/doc/guix.texi
index bc4d306c2d..fa64c6a3fc 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -8248,6 +8248,13 @@  origin Reference
 @end lisp
 @end deftp
 
+@deffn {Procedure} git-source hash host author project commit [prefix]
+Return an @code{origin} corresponding to the @var{host}'s repository for
+the @var{author}'s @var{project}.  It is checked out at @var{commit},
+with a consistent @var{prefix} used in some repositories.  @var{hash} is
+the string for a base32-encoded SHA256 hash used by @code{git-fetch}.
+@end deffn
+
 For Mercurial repositories, the module @code{(guix hg-download)} defines
 the @code{hg-fetch} origin method and @code{hg-reference} data type for
 support of the Mercurial version control system.
diff --git a/guix/git-download.scm b/guix/git-download.scm
index ae2073ea06..6de53fec70 100644
--- a/guix/git-download.scm
+++ b/guix/git-download.scm
@@ -59,7 +59,8 @@  (define-module (guix git-download)
             git-fetch/lfs
             git-version
             git-file-name
-            git-predicate))
+            git-predicate
+            git-source))
 
 ;;; Commentary:
 ;;;
@@ -395,4 +396,13 @@  (define* (git-predicate directory #:key (recursive? #t))
             (#f        #f)))))
     (const #f)))
 
+(define* (git-source hash host author project commit #:optional prefix)
+  (origin
+    (method git-fetch)
+    (uri (git-reference
+           (url (string-join (list "https:/" host author project) "/"))
+           (commit (if prefix (string-append prefix commit) commit))))
+    (file-name (git-file-name project commit))
+    (hash (content-hash (base32 hash) sha256))))
+
 ;;; git-download.scm ends here