summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2020-05-20 17:57:54 +0200
committerLudovic Courtès <ludo@gnu.org>2020-05-25 00:00:28 +0200
commit8d1d56578aa95118650ed2197bfb7fac40f4218a (patch)
treed2d27f204da98f3f4fc43a757ca910e724acab81
parent9b049de84ed101e2c0a5d071e76f424b3bc46bd9 (diff)
git: 'update-cached-checkout' returns the commit relation.
* guix/git.scm (update-cached-checkout): Add #:starting-commit parameter. Call 'commit-relation' when #:starting-commit is true. Always return the relation or #f as the third value. (latest-repository-commit): Adjust accordingly. * guix/import/opam.scm (get-opam-repository): Likewise. * tests/channels.scm ("latest-channel-instances includes channel dependencies") ("latest-channel-instances excludes duplicate channel dependencies"): Update mock of 'update-cached-checkout' accordingly.
-rw-r--r--guix/channels.scm2
-rw-r--r--guix/git.scm22
-rw-r--r--guix/import/opam.scm2
-rw-r--r--tests/channels.scm12
4 files changed, 25 insertions, 13 deletions
diff --git a/guix/channels.scm b/guix/channels.scm
index e0a7a84f55d..75b767a94c5 100644
--- a/guix/channels.scm
+++ b/guix/channels.scm
@@ -218,7 +218,7 @@ result is unspecified."
218 (and (string=? (basename file) ".git") 218 (and (string=? (basename file) ".git")
219 (eq? 'directory (stat:type stat)))) 219 (eq? 'directory (stat:type stat))))
220 220
221 (let-values (((checkout commit) 221 (let-values (((checkout commit relation)
222 (update-cached-checkout (channel-url channel) 222 (update-cached-checkout (channel-url channel)
223 #:ref (channel-reference channel)))) 223 #:ref (channel-reference channel))))
224 (when (guix-channel? channel) 224 (when (guix-channel? channel)
diff --git a/guix/git.scm b/guix/git.scm
index 249d6227561..ab3b5075b18 100644
--- a/guix/git.scm
+++ b/guix/git.scm
@@ -262,14 +262,16 @@ definitely available in REPOSITORY, false otherwise."
262 #:key 262 #:key
263 (ref '(branch . "master")) 263 (ref '(branch . "master"))
264 recursive? 264 recursive?
265 starting-commit
265 (log-port (%make-void-port "w")) 266 (log-port (%make-void-port "w"))
266 (cache-directory 267 (cache-directory
267 (url-cache-directory 268 (url-cache-directory
268 url (%repository-cache-directory) 269 url (%repository-cache-directory)
269 #:recursive? recursive?))) 270 #:recursive? recursive?)))
270 "Update the cached checkout of URL to REF in CACHE-DIRECTORY. Return two 271 "Update the cached checkout of URL to REF in CACHE-DIRECTORY. Return three
271values: the cache directory name, and the SHA1 commit (a string) corresponding 272values: the cache directory name, and the SHA1 commit (a string) corresponding
272to REF. 273to REF, and the relation of the new commit relative to STARTING-COMMIT (if
274provided) as returned by 'commit-relation'.
273 275
274REF is pair whose key is [branch | commit | tag | tag-or-commit ] and value 276REF is pair whose key is [branch | commit | tag | tag-or-commit ] and value
275the associated data: [<branch name> | <sha1> | <tag name> | <string>]. 277the associated data: [<branch name> | <sha1> | <tag name> | <string>].
@@ -302,7 +304,17 @@ When RECURSIVE? is true, check out submodules as well, if any."
302 (remote-fetch (remote-lookup repository "origin")))) 304 (remote-fetch (remote-lookup repository "origin"))))
303 (when recursive? 305 (when recursive?
304 (update-submodules repository #:log-port log-port)) 306 (update-submodules repository #:log-port log-port))
305 (let ((oid (switch-to-ref repository canonical-ref))) 307
308 ;; Note: call 'commit-relation' from here because it's more efficient
309 ;; than letting users re-open the checkout later on.
310 (let* ((oid (switch-to-ref repository canonical-ref))
311 (new (and starting-commit
312 (commit-lookup repository oid)))
313 (old (and starting-commit
314 (commit-lookup repository
315 (string->oid starting-commit))))
316 (relation (and starting-commit
317 (commit-relation old new))))
306 318
307 ;; Reclaim file descriptors and memory mappings associated with 319 ;; Reclaim file descriptors and memory mappings associated with
308 ;; REPOSITORY as soon as possible. 320 ;; REPOSITORY as soon as possible.
@@ -310,7 +322,7 @@ When RECURSIVE? is true, check out submodules as well, if any."
310 'repository-close!) 322 'repository-close!)
311 (repository-close! repository)) 323 (repository-close! repository))
312 324
313 (values cache-directory (oid->string oid)))))) 325 (values cache-directory (oid->string oid) relation)))))
314 326
315(define* (latest-repository-commit store url 327(define* (latest-repository-commit store url
316 #:key 328 #:key
@@ -343,7 +355,7 @@ Log progress and checkout info to LOG-PORT."
343 355
344 (format log-port "updating checkout of '~a'...~%" url) 356 (format log-port "updating checkout of '~a'...~%" url)
345 (let*-values 357 (let*-values
346 (((checkout commit) 358 (((checkout commit _)
347 (update-cached-checkout url 359 (update-cached-checkout url
348 #:recursive? recursive? 360 #:recursive? recursive?
349 #:ref ref 361 #:ref ref
diff --git a/guix/import/opam.scm b/guix/import/opam.scm
index ae7df8a8b57..9cda3da0066 100644
--- a/guix/import/opam.scm
+++ b/guix/import/opam.scm
@@ -115,7 +115,7 @@
115(define (get-opam-repository) 115(define (get-opam-repository)
116 "Update or fetch the latest version of the opam repository and return the 116 "Update or fetch the latest version of the opam repository and return the
117path to the repository." 117path to the repository."
118 (receive (location commit) 118 (receive (location commit _)
119 (update-cached-checkout "https://github.com/ocaml/opam-repository") 119 (update-cached-checkout "https://github.com/ocaml/opam-repository")
120 location)) 120 location))
121 121
diff --git a/tests/channels.scm b/tests/channels.scm
index 910088ba157..3578b57204c 100644
--- a/tests/channels.scm
+++ b/tests/channels.scm
@@ -136,11 +136,11 @@
136 (url "test"))) 136 (url "test")))
137 (test-dir (channel-instance-checkout instance--simple))) 137 (test-dir (channel-instance-checkout instance--simple)))
138 (mock ((guix git) update-cached-checkout 138 (mock ((guix git) update-cached-checkout
139 (lambda* (url #:key ref) 139 (lambda* (url #:key ref starting-commit)
140 (match url 140 (match url
141 ("test" (values test-dir "caf3cabba9e")) 141 ("test" (values test-dir "caf3cabba9e" #f))
142 (_ (values (channel-instance-checkout instance--no-deps) 142 (_ (values (channel-instance-checkout instance--no-deps)
143 "abcde1234"))))) 143 "abcde1234" #f)))))
144 (with-store store 144 (with-store store
145 (let ((instances (latest-channel-instances store (list channel)))) 145 (let ((instances (latest-channel-instances store (list channel))))
146 (and (eq? 2 (length instances)) 146 (and (eq? 2 (length instances))
@@ -155,11 +155,11 @@
155 (url "test"))) 155 (url "test")))
156 (test-dir (channel-instance-checkout instance--with-dupes))) 156 (test-dir (channel-instance-checkout instance--with-dupes)))
157 (mock ((guix git) update-cached-checkout 157 (mock ((guix git) update-cached-checkout
158 (lambda* (url #:key ref) 158 (lambda* (url #:key ref starting-commit)
159 (match url 159 (match url
160 ("test" (values test-dir "caf3cabba9e")) 160 ("test" (values test-dir "caf3cabba9e" #f))
161 (_ (values (channel-instance-checkout instance--no-deps) 161 (_ (values (channel-instance-checkout instance--no-deps)
162 "abcde1234"))))) 162 "abcde1234" #f)))))
163 (with-store store 163 (with-store store
164 (let ((instances (latest-channel-instances store (list channel)))) 164 (let ((instances (latest-channel-instances store (list channel))))
165 (and (= 2 (length instances)) 165 (and (= 2 (length instances))