[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02/11: git: Factorize 'commit-id?' predicate.
From: |
guix-commits |
Subject: |
02/11: git: Factorize 'commit-id?' predicate. |
Date: |
Tue, 11 Oct 2022 10:16:00 -0400 (EDT) |
civodul pushed a commit to branch master
in repository guix.
commit 602527ab9778165ca9a8f9cb62036038b5354688
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Tue Oct 11 10:42:43 2022 +0200
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.
---
guix/git.scm | 10 ++++++++--
guix/inferior.scm | 4 ++--
2 files changed, 10 insertions(+), 4 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
diff --git a/guix/inferior.scm b/guix/inferior.scm
index 20a86bbfda..cbb3c0a36e 100644
--- a/guix/inferior.scm
+++ b/guix/inferior.scm
@@ -40,7 +40,7 @@
#:use-module (guix search-paths)
#:use-module (guix profiles)
#:use-module (guix channels)
- #:use-module ((guix git) #:select (update-cached-checkout))
+ #:use-module ((guix git) #:select (update-cached-checkout commit-id?))
#:use-module (guix monads)
#:use-module (guix store)
#:use-module (guix derivations)
@@ -833,7 +833,7 @@ CHANNEL's 'commit' field is a full SHA1, return it as-is;
if it's a SHA1
prefix, resolve it; and if 'commit' is unset, fetch CHANNEL's branch tip."
(let ((commit (channel-commit channel))
(branch (channel-branch channel)))
- (if (and commit (= (string-length commit) 40))
+ (if (and commit (commit-id? commit))
commit
(let* ((ref (if commit `(commit . ,commit) `(branch . ,branch)))
(cache commit relation
- branch master updated (f78cfcd7d3 -> 68d79a8b60), guix-commits, 2022/10/11
- 01/11: guix import: Add a blank line after each package definition., guix-commits, 2022/10/11
- 02/11: git: Factorize 'commit-id?' predicate.,
guix-commits <=
- 03/11: Revert "guix system: Remove unused 'read-operating-system' procedure.", guix-commits, 2022/10/11
- 04/11: gnu: emacs-guix: Update to cf5b7a4., guix-commits, 2022/10/11
- 05/11: gnu: emacs-guix: Remove input labels., guix-commits, 2022/10/11
- 06/11: gnu: python-pydyf: Update to 0.3.0., guix-commits, 2022/10/11
- 10/11: gnu: profanity: Update to 0.13.0., guix-commits, 2022/10/11
- 07/11: gnu: gtkwave: Update to 3.3.113., guix-commits, 2022/10/11
- 09/11: gnu: libstrophe: Update to 0.12.2., guix-commits, 2022/10/11
- 11/11: gnu: Add libskk., guix-commits, 2022/10/11
- 08/11: gnu: mmg: Add dependency on Perl., guix-commits, 2022/10/11