Archived
1
0
Fork 0

git: Factorize 'resolve-reference'.

* guix/git.scm (resolve-reference): New procedure.
(switch-to-ref): Use it.
This commit is contained in:
Ludovic Courtès 2020-07-15 23:58:29 +02:00
parent 9e0d896bf3
commit 1c058c382a
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -150,10 +150,9 @@ of SHA1 string."
(last (string-split url #\/)) ".git" "") (last (string-split url #\/)) ".git" "")
"-" (string-take sha1 7))) "-" (string-take sha1 7)))
(define (switch-to-ref repository ref) (define (resolve-reference repository ref)
"Switch to REPOSITORY's branch, commit or tag specified by REF. Return the "Resolve the branch, commit or tag specified by REF, and return the
OID (roughly the commit hash) corresponding to REF." corresponding Git object."
(define obj
(let resolve ((ref ref)) (let resolve ((ref ref))
(match ref (match ref
(('branch . branch) (('branch . branch)
@ -192,6 +191,12 @@ OID (roughly the commit hash) corresponding to REF."
;; object, whatever that is. ;; object, whatever that is.
(object-lookup repository oid)))))) (object-lookup repository oid))))))
(define (switch-to-ref repository ref)
"Switch to REPOSITORY's branch, commit or tag specified by REF. Return the
OID (roughly the commit hash) corresponding to REF."
(define obj
(resolve-reference repository ref))
(reset repository obj RESET_HARD) (reset repository obj RESET_HARD)
(object-id obj)) (object-id obj))