summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaxim Cournoyer <maxim.cournoyer@gmail.com>2023-09-05 16:30:22 -0400
committerMaxim Cournoyer <maxim.cournoyer@gmail.com>2023-09-05 19:52:20 -0400
commit756e336fa008c2469b4a7317ad5c641ed48f25d6 (patch)
tree483ce9c4c0daba6445b3458a9f1a16f9b7f16be4
parent8ca349006238ea16c4bb4f85792064f079a7e10f (diff)
downloadguix-756e336fa008c2469b4a7317ad5c641ed48f25d6.tar.gz
Revert "guix: git: Avoid touching the network unless needed in 'reference-available?'."
This reverts commit a789dd58656d5f7f1b8edf790d77753fc71670af, which broke
e.g.:

  guix time-machine -C <(echo %default-channels) -- describe

Add an explanatory comment as suggested.

Reported-by: Ludovic Courtès <ludo@gnu.org>
-rw-r--r--guix/git.scm18
1 files changed, 16 insertions, 2 deletions
diff --git a/guix/git.scm b/guix/git.scm
index ebe2600209..a957773873 100644
--- a/guix/git.scm
+++ b/guix/git.scm
@@ -360,8 +360,22 @@ 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."
-  (false-if-git-not-found
-   (->bool (resolve-reference repository ref))))
+  ;; 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, has 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))))))
+    (_
+     #f)))
 
 (define (clone-from-swh url tag-or-commit output)
   "Attempt to clone TAG-OR-COMMIT (a string), which originates from URL, using