[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#37413] [PATCH v2 02/11] git: 'update-cached-checkout' avoids networ
From: |
Ludovic Courtès |
Subject: |
[bug#37413] [PATCH v2 02/11] git: 'update-cached-checkout' avoids network access when unnecessary. |
Date: |
Sat, 21 Sep 2019 23:12:19 +0200 |
* guix/git.scm (reference-available?): New procedure.
(update-cached-checkout): Avoid call to 'remote-fetch' when REPOSITORY
already contains REF.
---
guix/git.scm | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/guix/git.scm b/guix/git.scm
index de98fed40c..92a7353b5a 100644
--- a/guix/git.scm
+++ b/guix/git.scm
@@ -220,6 +220,21 @@ dynamic extent of EXP."
(G_ "Support for submodules is missing; \
please upgrade Guile-Git.~%"))))
+(define (reference-available? repository ref)
+ "Return true if REF, a reference such as '(commit . \"cabba9e\"), is
+definitely available in REPOSITORY, false otherwise."
+ (match ref
+ (('commit . commit)
+ (catch 'git-error
+ (lambda ()
+ (->bool (commit-lookup repository (string->oid commit))))
+ (lambda (key error . rest)
+ (if (= GIT_ENOTFOUND (git-error-code error))
+ #f
+ (apply throw key error rest)))))
+ (_
+ #f)))
+
(define* (update-cached-checkout url
#:key
(ref '(branch . "master"))
@@ -254,7 +269,8 @@ When RECURSIVE? is true, check out submodules as well, if
any."
(repository-open cache-directory)
(clone* url cache-directory))))
;; Only fetch remote if it has not been cloned just before.
- (when cache-exists?
+ (when (and cache-exists?
+ (not (reference-available? repository ref)))
(remote-fetch (remote-lookup repository "origin")))
(when recursive?
(update-submodules repository #:log-port log-port))
--
2.23.0
- [bug#37413] [PATCH 0/9] Channel news distribution mechanism, (continued)
- [bug#37413] [PATCH 0/9] Channel news distribution mechanism, pelzflorian (Florian Pelz), 2019/09/17
- [bug#37413] [PATCH 0/9] Channel news distribution mechanism, Julien Lepiller, 2019/09/17
- [bug#37413] [PATCH 0/9] Channel news distribution mechanism, pelzflorian (Florian Pelz), 2019/09/17
- [bug#37413] [PATCH 0/9] Channel news distribution mechanism, pelzflorian (Florian Pelz), 2019/09/17
- [bug#37413] [PATCH 0/9] Channel news distribution mechanism, Ludovic Courtès, 2019/09/18
- [bug#37413] [PATCH 0/9] Channel news distribution mechanism, pelzflorian (Florian Pelz), 2019/09/18
- [bug#37413] [PATCH 0/9] Channel news distribution mechanism, Ludovic Courtès, 2019/09/18
- [bug#37413] [PATCH 0/9] Channel news distribution mechanism, Ludovic Courtès, 2019/09/18
[bug#37413] [PATCH v2 00/11] Channel news distribution mechanism, Ludovic Courtès, 2019/09/21
- [bug#37413] [PATCH v2 01/11] pull: '--news' shows the list of channels added or removed., Ludovic Courtès, 2019/09/21
- [bug#37413] [PATCH v2 02/11] git: 'update-cached-checkout' avoids network access when unnecessary.,
Ludovic Courtès <=
- [bug#37413] [PATCH v2 07/11] pull: Display channel news., Ludovic Courtès, 2019/09/21
- [bug#37413] [PATCH v2 06/11] ui: Add 'current-message-language'., Ludovic Courtès, 2019/09/21
- [bug#37413] [PATCH v2 08/11] pull: '-l' displays channel news., Ludovic Courtès, 2019/09/21
- [bug#37413] [PATCH v2 03/11] git: Add 'commit-difference'., Ludovic Courtès, 2019/09/21
- [bug#37413] [PATCH v2 05/11] channels: Allow news entries to refer to a tag., Ludovic Courtès, 2019/09/21
- [bug#37413] [PATCH v2 04/11] channels: Add support for a news file., Ludovic Courtès, 2019/09/21
- [bug#37413] [PATCH v2 10/11] Add '.guix-channel' file., Ludovic Courtès, 2019/09/21
- [bug#37413] [PATCH v2 11/11] DRAFT etc: Add channel news file., Ludovic Courtès, 2019/09/21
- [bug#37413] [PATCH v2 11/11] DRAFT etc: Add channel news file., pelzflorian (Florian Pelz), 2019/09/22
- [bug#37413] [PATCH v2 11/11] DRAFT etc: Add channel news file., Ludovic Courtès, 2019/09/23