From c4c2449fea9b7fd78f61ffb9bbe19ab2ef6c8b41 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 26 Jul 2019 10:59:24 +0200 Subject: git: 'update-cached-checkout' supports a 'tag-or-commit' type of ref. * guix/git.scm (switch-to-ref)[obj]: Wrap in 'resolve' lambda. Add 'tag-or-commit' case. (update-cached-checkout): Document it. --- guix/git.scm | 61 +++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 25 deletions(-) (limited to 'guix/git.scm') diff --git a/guix/git.scm b/guix/git.scm index 289537dedf..fb2df2de07 100644 --- a/guix/git.scm +++ b/guix/git.scm @@ -139,29 +139,40 @@ of SHA1 string." "Switch to REPOSITORY's branch, commit or tag specified by REF. Return the OID (roughly the commit hash) corresponding to REF." (define obj - (match ref - (('branch . branch) - (let ((oid (reference-target - (branch-lookup repository branch BRANCH-REMOTE)))) - (object-lookup repository oid))) - (('commit . commit) - (let ((len (string-length commit))) - ;; 'object-lookup-prefix' appeared in Guile-Git in Mar. 2018, so we - ;; can't be sure it's available. Furthermore, 'string->oid' used to - ;; read out-of-bounds when passed a string shorter than 40 chars, - ;; which is why we delay calls to it below. - (if (< len 40) - (if (module-defined? (resolve-interface '(git object)) - 'object-lookup-prefix) - (object-lookup-prefix repository (string->oid commit) len) - (raise (condition - (&message - (message "long Git object ID is required"))))) - (object-lookup repository (string->oid commit))))) - (('tag . tag) - (let ((oid (reference-name->oid repository - (string-append "refs/tags/" tag)))) - (object-lookup repository oid))))) + (let resolve ((ref ref)) + (match ref + (('branch . branch) + (let ((oid (reference-target + (branch-lookup repository branch BRANCH-REMOTE)))) + (object-lookup repository oid))) + (('commit . commit) + (let ((len (string-length commit))) + ;; 'object-lookup-prefix' appeared in Guile-Git in Mar. 2018, so we + ;; can't be sure it's available. Furthermore, 'string->oid' used to + ;; read out-of-bounds when passed a string shorter than 40 chars, + ;; which is why we delay calls to it below. + (if (< len 40) + (if (module-defined? (resolve-interface '(git object)) + 'object-lookup-prefix) + (object-lookup-prefix repository (string->oid commit) len) + (raise (condition + (&message + (message "long Git object ID is required"))))) + (object-lookup repository (string->oid commit))))) + (('tag-or-commit . str) + (if (or (> (string-length str) 40) + (not (string-every char-set:hex-digit str))) + (resolve `(tag . ,str)) ;definitely a tag + (catch 'git-error + (lambda () + (resolve `(tag . ,str))) + (lambda _ + ;; There's no such tag, so it must be a commit ID. + (resolve `(commit . ,str)))))) + (('tag . tag) + (let ((oid (reference-name->oid repository + (string-append "refs/tags/" tag)))) + (object-lookup repository oid)))))) (reset repository obj RESET_HARD) (object-id obj)) @@ -218,8 +229,8 @@ please upgrade Guile-Git.~%")))) values: the cache directory name, and the SHA1 commit (a string) corresponding to REF. -REF is pair whose key is [branch | commit | tag] and value the associated -data, respectively [ | | ]. +REF is pair whose key is [branch | commit | tag | tag-or-commit ] and value +the associated data: [ | | | ]. When RECURSIVE? is true, check out submodules as well, if any." (define canonical-ref -- cgit v1.2.3 From 177fecb57c0c9e15249bf6a49244c9dc6eb8439c Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 26 Jul 2019 11:09:56 +0200 Subject: git: allows tags in its 'commit' field. Fixes . Reported by Tobias Geerinckx-Rice . * guix/git.scm (git-checkout-compiler): Pass 'tag-or-commit' to 'latest-repository-commit*'. * doc/guix.texi (Package Transformation Options): Update '--with-commit' documentation accordingly. * tests/guix-build-branch.sh: Add test. --- doc/guix.texi | 2 +- guix/git.scm | 4 ++-- tests/guix-build-branch.sh | 8 +++++++- 3 files changed, 10 insertions(+), 4 deletions(-) (limited to 'guix/git.scm') diff --git a/doc/guix.texi b/doc/guix.texi index c2da4ce173..96448c24e5 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -8048,7 +8048,7 @@ guix build --with-branch=guile-sqlite3=master cuirass @item --with-commit=@var{package}=@var{commit} This is similar to @code{--with-branch}, except that it builds from @var{commit} rather than the tip of a branch. @var{commit} must be a valid -Git commit SHA1 identifier. +Git commit SHA1 identifier or a tag. @end table @node Additional Build Options diff --git a/guix/git.scm b/guix/git.scm index fb2df2de07..85252629fc 100644 --- a/guix/git.scm +++ b/guix/git.scm @@ -330,7 +330,7 @@ Log progress and checkout info to LOG-PORT." git-checkout? (url git-checkout-url) (branch git-checkout-branch (default "master")) - (commit git-checkout-commit (default #f)) + (commit git-checkout-commit (default #f)) ;#f | tag | commit (recursive? git-checkout-recursive? (default #f))) (define* (latest-repository-commit* url #:key ref recursive? log-port) @@ -369,7 +369,7 @@ Log progress and checkout info to LOG-PORT." (($ url branch commit recursive?) (latest-repository-commit* url #:ref (if commit - `(commit . ,commit) + `(tag-or-commit . ,commit) `(branch . ,branch)) #:recursive? recursive? #:log-port (current-error-port))))) diff --git a/tests/guix-build-branch.sh b/tests/guix-build-branch.sh index e64782c831..0cec7c75db 100644 --- a/tests/guix-build-branch.sh +++ b/tests/guix-build-branch.sh @@ -1,5 +1,5 @@ # GNU Guix --- Functional package management for GNU -# Copyright © 2018 Ludovic Courtès +# Copyright © 2018, 2019 Ludovic Courtès # # This file is part of GNU Guix. # @@ -52,5 +52,11 @@ guix gc -R "$v0_1_0_drv" | grep guile-gcrypt-git.9e3eacd test "$v0_1_0_drv" != "$latest_drv" test "$v0_1_0_drv" != "$orig_drv" +v0_1_0_drv="`guix build guix --with-commit=guile-gcrypt=v0.1.0 -d`" +guix gc -R "$v0_1_0_drv" | grep guile-gcrypt-git.v0.1.0 +guix gc -R "$v0_1_0_drv" | grep guile-gcrypt-8fe64e8 # this is the *tag* ID +test "$v0_1_0_drv" != "$latest_drv" +test "$v0_1_0_drv" != "$orig_drv" + if guix build guix --with-commit=guile-gcrypt=000 -d then false; else true; fi -- cgit v1.2.3 From 10a8c2bbc6754bddb0e5d668b3ecc9050efd820b Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 26 Jul 2019 11:16:10 +0200 Subject: git: 'switch-to-ref' resolves tag targets. * guix/git.scm (switch-to-ref): In the 'tag' case, resolve the target of the tag. * tests/guix-build-branch.sh: Adjust test accordingly. --- guix/git.scm | 6 +++++- tests/guix-build-branch.sh | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'guix/git.scm') diff --git a/guix/git.scm b/guix/git.scm index 85252629fc..de98fed40c 100644 --- a/guix/git.scm +++ b/guix/git.scm @@ -172,7 +172,11 @@ OID (roughly the commit hash) corresponding to REF." (('tag . tag) (let ((oid (reference-name->oid repository (string-append "refs/tags/" tag)))) - (object-lookup repository oid)))))) + ;; Get the commit that the tag at OID refers to. This is not + ;; strictly needed, but it's more consistent to always return the + ;; OID of a commit. + (object-lookup repository + (tag-target-id (tag-lookup repository oid)))))))) (reset repository obj RESET_HARD) (object-id obj)) diff --git a/tests/guix-build-branch.sh b/tests/guix-build-branch.sh index 0cec7c75db..3d2a7dddf5 100644 --- a/tests/guix-build-branch.sh +++ b/tests/guix-build-branch.sh @@ -54,7 +54,7 @@ test "$v0_1_0_drv" != "$orig_drv" v0_1_0_drv="`guix build guix --with-commit=guile-gcrypt=v0.1.0 -d`" guix gc -R "$v0_1_0_drv" | grep guile-gcrypt-git.v0.1.0 -guix gc -R "$v0_1_0_drv" | grep guile-gcrypt-8fe64e8 # this is the *tag* ID +guix gc -R "$v0_1_0_drv" | grep guile-gcrypt-9e3eacd test "$v0_1_0_drv" != "$latest_drv" test "$v0_1_0_drv" != "$orig_drv" -- cgit v1.2.3