aboutsummaryrefslogtreecommitdiff
path: root/guix/git.scm
diff options
context:
space:
mode:
authorSimon Tournier <zimon.toutoune@gmail.com>2023-09-06 15:01:00 +0200
committerSimon Tournier <zimon.toutoune@gmail.com>2023-09-22 14:42:56 +0200
commit6d33c1f8061e86d63ab5c9ec75df9c58130c7264 (patch)
treeaa31050ffe8ffcd99a6f1ea81934e9c8decaee23 /guix/git.scm
parentf45c0c82289d409b4fac00464ea8b323839ba53f (diff)
downloadguix-6d33c1f8061e86d63ab5c9ec75df9c58130c7264.tar
guix-6d33c1f8061e86d63ab5c9ec75df9c58130c7264.tar.gz
git: Avoid touching the network unless needed in 'reference-available?'.
Follow-up of 756e336fa008c2469b4a7317ad5c641ed48f25d6 fixing the issue. * guix/git/scm (reference-available?): Address case by case to determine whether the reference exists in the local Git checkout.
Diffstat (limited to 'guix/git.scm')
-rw-r--r--guix/git.scm22
1 files changed, 9 insertions, 13 deletions
diff --git a/guix/git.scm b/guix/git.scm
index 1cb87a4560..1b3355109e 100644
--- a/guix/git.scm
+++ b/guix/git.scm
@@ -5,6 +5,7 @@
;;; Copyright © 2021 Marius Bakke <marius@gnu.org>
;;; Copyright © 2022 Maxime Devos <maximedevos@telenet.be>
;;; Copyright © 2023 Tobias Geerinckx-Rice <me@tobias.gr>
+;;; Copyright © 2023 Simon Tournier <zimon.toutoune@gmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -360,21 +361,16 @@ dynamic extent of EXP."
(define (reference-available? repository ref)
"Return true if REF, a reference such as '(commit . \"cabba9e\"), is
definitely available in REPOSITORY, false otherwise."
- ;; Note: this must not rely on 'resolve-reference', as that procedure always
- ;; resolves the references for branch names such as master. The semantic we
- ;; want here is that unless the reference is exact (e.g. a commit), the
- ;; reference should not be considered available, as it could have changed on
- ;; the remote.
(match ref
- ((or ('commit . commit)
- ('tag-or-commit . (? commit-id? commit)))
- (let ((len (string-length commit))
- (oid (string->oid commit)))
- (false-if-git-not-found
- (->bool (if (< len 40)
- (object-lookup-prefix repository oid len OBJ-COMMIT)
- (commit-lookup repository oid))))))
+ (('commit . (? commit-id? commit))
+ (let ((oid (string->oid commit)))
+ (->bool (commit-lookup repository oid))))
+ ((or ('tag . str)
+ ('tag-or-commit . str))
+ (false-if-git-not-found
+ (->bool (resolve-reference repository ref))))
(_
+ ;; For the others REF as branch or symref, the REF cannot be available
#f)))
(define (clone-from-swh url tag-or-commit output)