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.
This commit is contained in:
Ludovic Courtès 2019-07-26 10:59:24 +02:00
parent 422e187fb4
commit c4c2449fea
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 36 additions and 25 deletions

View File

@ -139,29 +139,40 @@ of SHA1 string."
"Switch to REPOSITORY's branch, commit or tag specified by REF. Return the "Switch to REPOSITORY's branch, commit or tag specified by REF. Return the
OID (roughly the commit hash) corresponding to REF." OID (roughly the commit hash) corresponding to REF."
(define obj (define obj
(match ref (let resolve ((ref ref))
(('branch . branch) (match ref
(let ((oid (reference-target (('branch . branch)
(branch-lookup repository branch BRANCH-REMOTE)))) (let ((oid (reference-target
(object-lookup repository oid))) (branch-lookup repository branch BRANCH-REMOTE))))
(('commit . commit) (object-lookup repository oid)))
(let ((len (string-length commit))) (('commit . commit)
;; 'object-lookup-prefix' appeared in Guile-Git in Mar. 2018, so we (let ((len (string-length commit)))
;; can't be sure it's available. Furthermore, 'string->oid' used to ;; 'object-lookup-prefix' appeared in Guile-Git in Mar. 2018, so we
;; read out-of-bounds when passed a string shorter than 40 chars, ;; can't be sure it's available. Furthermore, 'string->oid' used to
;; which is why we delay calls to it below. ;; read out-of-bounds when passed a string shorter than 40 chars,
(if (< len 40) ;; which is why we delay calls to it below.
(if (module-defined? (resolve-interface '(git object)) (if (< len 40)
'object-lookup-prefix) (if (module-defined? (resolve-interface '(git object))
(object-lookup-prefix repository (string->oid commit) len) 'object-lookup-prefix)
(raise (condition (object-lookup-prefix repository (string->oid commit) len)
(&message (raise (condition
(message "long Git object ID is required"))))) (&message
(object-lookup repository (string->oid commit))))) (message "long Git object ID is required")))))
(('tag . tag) (object-lookup repository (string->oid commit)))))
(let ((oid (reference-name->oid repository (('tag-or-commit . str)
(string-append "refs/tags/" tag)))) (if (or (> (string-length str) 40)
(object-lookup repository oid))))) (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) (reset repository obj RESET_HARD)
(object-id obj)) (object-id obj))
@ -218,8 +229,8 @@ please upgrade Guile-Git.~%"))))
values: the cache directory name, and the SHA1 commit (a string) corresponding values: the cache directory name, and the SHA1 commit (a string) corresponding
to REF. to REF.
REF is pair whose key is [branch | commit | tag] and value the associated REF is pair whose key is [branch | commit | tag | tag-or-commit ] and value
data, respectively [<branch name> | <sha1> | <tag name>]. the associated data: [<branch name> | <sha1> | <tag name> | <string>].
When RECURSIVE? is true, check out submodules as well, if any." When RECURSIVE? is true, check out submodules as well, if any."
(define canonical-ref (define canonical-ref