Subject: [bug#32094] [PATCH] git: Call 'url-cache-directory' outside 'update-cached-checkout' body.

From: Oleg Pykhalov <[email-masked]>
Date: Tue, 10 Jul 2018 06:39:22 +0300

Hello Ludovic,

Thank you for review.

[email-masked] (Ludovic Courtès) writes:

> Oleg Pykhalov <[email-masked]> skribis:
>
>> * guix/git.scm (update-cached-checkout): Call 'url-cache-directory' in
>> 'cache-directory' key argument.
>
> ‘latest-repository-commit’ would need to be adjusted accordingly.
>
> Could you do that and make sure ‘guix pull’ still behaves the same as
> before?

When I adjusted ‘latest-repository-commit’ I thought about removing
‘url-cache-directory’ call from ‘update-cached-checkout’ instead of
moving ‘url-cache-directory’ call to ‘cache-directory’ argument.

I'm not sure it's possible to call ‘url-cache-directory’ in argument of
‘update-cached-checkout’, because ‘url-cache-directory’ requires ‘url’
argument which itself is the argument of ‘update-cached-checkout’.

(define* (url-cache-directory url
                              #:optional (cache-directory
                                          (%repository-cache-directory)))
  …)

(define* (update-cached-checkout url
                                 #:key
                                 (ref '(branch . "origin/master"))
                                 (cache-directory
                                  (%repository-cache-directory)))
  …)

Here is an updated patch which was successfully tested with ‘guix pull’.

From b3466c2e8569c30a83e81598657706b3bbbbc282 Mon Sep 17 00:00:00 2001
From: Oleg Pykhalov <[email-masked]>
Date: Sun, 8 Jul 2018 13:15:41 +0300
Subject: [PATCH] git: Call 'url-cache-directory' outside
 'update-cached-checkout'.

* guix/git.scm (update-cached-checkout): Remove 'url-cache-directory' call.
(latest-repository-commit): Call 'url-cache-directory'.
---
 guix/git.scm | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/guix/git.scm b/guix/git.scm
index 9e89cc006..297b086ad 100644
--- a/guix/git.scm
+++ b/guix/git.scm
@@ -122,11 +122,10 @@ to REF.
 REF is pair whose key is [branch | commit | tag] and value the associated
 data, respectively [<branch name> | <sha1> | <tag name>]."
   (with-libgit2
-   (let* ((cache-dir     (url-cache-directory url cache-directory))
-          (cache-exists? (openable-repository? cache-dir))
+   (let* ((cache-exists? (openable-repository? cache-directory))
           (repository    (if cache-exists?
-                             (repository-open cache-dir)
-                             (clone* url cache-dir))))
+                             (repository-open cache-directory)
+                             (clone* url cache-directory))))
      ;; Only fetch remote if it has not been cloned just before.
      (when cache-exists?
        (remote-fetch (remote-lookup repository "origin")))
@@ -138,7 +137,7 @@ data, respectively [<branch name> | <sha1> | <tag name>]."
                               'repository-close!)
          (repository-close! repository))
 
-       (values cache-dir (oid->string oid))))))
+       (values cache-directory (oid->string oid))))))
 
 (define* (latest-repository-commit store url
                                    #:key
@@ -157,12 +156,14 @@ Git repositories are kept in the cache directory specified by
     (and (string=? (basename file) ".git")
          (eq? 'directory (stat:type stat))))
 
-  (let*-values (((checkout commit)
-                 (update-cached-checkout url
-                                         #:ref ref
-                                         #:cache-directory cache-directory))
-                ((name)
-                 (url+commit->name url commit)))
+  (let*-values
+      (((checkout commit)
+        (update-cached-checkout url
+                                #:ref ref
+                                #:cache-directory
+                                (url-cache-directory url cache-directory)))
+       ((name)
+        (url+commit->name url commit)))
     (values (add-to-store store name #t "sha256" checkout
                           #:select? (negate dot-git?))
             commit)))
-- 
2.18.0