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
1 changed files with 42 additions and 37 deletions

View File

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