diff options
author | Ludovic Courtès <ludo@gnu.org> | 2022-10-11 10:42:43 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2022-10-11 16:05:31 +0200 |
commit | 602527ab9778165ca9a8f9cb62036038b5354688 (patch) | |
tree | b4d2b261cbcc1e78c4893f80a50959373496aecc /guix/git.scm | |
parent | 7d9fd1d7b7a328555adda4f72d7eec8906f28880 (diff) |
git: Factorize 'commit-id?' predicate.
* guix/git.scm (commit-id?): New procedure, copied from (guix swh).
(resolve-reference): Use it instead of inline code.
* guix/inferior.scm (channel-full-commit): Likewise.
Diffstat (limited to 'guix/git.scm')
-rw-r--r-- | guix/git.scm | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/guix/git.scm b/guix/git.scm index 53e7219c8c..d7fd320f50 100644 --- a/guix/git.scm +++ b/guix/git.scm @@ -62,6 +62,7 @@ commit-difference commit-relation commit-descendant? + commit-id? remote-refs @@ -219,6 +220,12 @@ of SHA1 string." (last (string-split url #\/)) ".git" "") "-" (string-take sha1 7))) +(define (commit-id? str) + "Return true if STR is likely a Git commit ID, false otherwise---e.g., if it +is a tag name. This is based on a simple heuristic so use with care!" + (and (= (string-length str) 40) + (string-every char-set:hex-digit str))) + (define (resolve-reference repository ref) "Resolve the branch, commit or tag specified by REF, and return the corresponding Git object." @@ -254,8 +261,7 @@ corresponding Git object." #f)) (_ #f))) => (lambda (commit) (resolve `(commit . ,commit)))) - ((or (> (string-length str) 40) - (not (string-every char-set:hex-digit str))) + ((not (commit-id? str)) (resolve `(tag . ,str))) ;definitely a tag (else (catch 'git-error |