all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kyle Meyer <kyle@kyleam.com>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: Ricardo Wurmus <rekado@elephly.net>, 45187@debbugs.gnu.org
Subject: bug#45187: git download defaults to origin/master
Date: Fri, 09 Apr 2021 23:50:13 -0400	[thread overview]
Message-ID: <87v98ussqy.fsf@kyleam.com> (raw)
In-Reply-To: <87fszz7ej2.fsf_-_@gnu.org>

Ludovic Courtès writes:

> Kyle Meyer <kyle@kyleam.com> skribis:
[...]
>>    git-checkout make-git-checkout
>>    git-checkout?
>>    (url     git-checkout-url)
>> -  (branch  git-checkout-branch (default "master"))
>> +  (branch  git-checkout-branch (default #f))
>> +  (symref  git-checkout-symref (default "HEAD"))
>
> I know it’s established Git jargon, but “symref” looks obscure to me.
> I find it OK for ‘update-cached-checkout’, because it’s an “internal”
> procedure for die-hard hackers, but a bit ugly here.

Agreed.  As mentioned upthread, I don't like it either.

> Another option would be to not add this ‘symref’ field and instead, when
> ‘branch’ and ‘commit’ are both #f, translate that to '(symref . "HEAD").
>
> WDYT?

Thanks for the suggestion.  Dropping the field and translating
downstream sounds good to me.

Working through the patch update, I ended up moving things even more
internally, making update-cached-checkout translate the empty list into
(symref . "refs/remotes/origin/HEAD") for resolve-reference.  I don't
think there will be a use for symrefs other than HEAD, so it seemed
reasonable to add the special case (or rather shift the special case all
the way down into update-cached-checkout).  Let me know if you'd rather
use a (symref . "HEAD") default for update-cached-checkout.

> The rest of the patch LGTM, thanks!

Thanks for the review.

-- >8 --
Subject: [PATCH v2] git: Update cached checkout to the remote HEAD by default.

Fixes <https://bugs.gnu.org/45187>.
Reported by Ricardo Wurmus <rekado@elephly.net>.

update-cached-checkout hard codes "master" as the default branch, leading to a
failure when the clone doesn't have a "master" branch.  Instead use the remote
HEAD symref as an indicator of what the primary branch is.

* guix/git.scm (resolve-reference): Support resolving symrefs.
(update-cached-checkout, latest-repository-commit): Change the default for REF
to the empty list and translate it to the remote HEAD symref.
(<git-checkout>): Change branch field's default to #f.
(git-checkout-compiler): When branch and commit fields are both #f, call
latest-repository-commit* with the empty list as the ref.
---
 guix/git.scm | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/guix/git.scm b/guix/git.scm
index 1820036f25..5d9f0bf205 100644
--- a/guix/git.scm
+++ b/guix/git.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2017, 2020 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2021 Kyle Meyer <kyle@kyleam.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -209,6 +210,9 @@ (define (resolve-reference repository ref)
        (let ((oid (reference-target
                    (branch-lookup repository branch BRANCH-REMOTE))))
          (object-lookup repository oid)))
+      (('symref . symref)
+       (let ((oid (reference-name->oid repository symref)))
+         (object-lookup repository oid)))
       (('commit . commit)
        (let ((len (string-length commit)))
          ;; 'object-lookup-prefix' appeared in Guile-Git in Mar. 2018, so we
@@ -340,7 +344,7 @@ (define (delete-checkout directory)
 
 (define* (update-cached-checkout url
                                  #:key
-                                 (ref '(branch . "master"))
+                                 (ref '())
                                  recursive?
                                  (check-out? #t)
                                  starting-commit
@@ -356,6 +360,7 @@ (define* (update-cached-checkout url
 
 REF is pair whose key is [branch | commit | tag | tag-or-commit ] and value
 the associated data: [<branch name> | <sha1> | <tag name> | <string>].
+IF REF is the empty list, the remote HEAD is used.
 
 When RECURSIVE? is true, check out submodules as well, if any.
 
@@ -374,6 +379,7 @@ (define* (update-cached-checkout url
     ;; made little sense since the cache should be transparent to them.  So
     ;; here we append "origin/" if it's missing and otherwise keep it.
     (match ref
+      (() '(symref . "refs/remotes/origin/HEAD"))
       (('branch . branch)
        `(branch . ,(if (string-prefix? "origin/" branch)
                        branch
@@ -433,12 +439,13 @@ (define* (latest-repository-commit store url
                                    (log-port (%make-void-port "w"))
                                    (cache-directory
                                     (%repository-cache-directory))
-                                   (ref '(branch . "master")))
+                                   (ref '()))
   "Return two values: the content of the git repository at URL copied into a
 store directory and the sha1 of the top level commit in this directory.  The
 reference to be checkout, once the repository is fetched, is specified by REF.
 REF is pair whose key is [branch | commit | tag] and value the associated
-data, respectively [<branch name> | <sha1> | <tag name>].
+data, respectively [<branch name> | <sha1> | <tag name>].  IF REF is the empty
+list, the remote HEAD is used.
 
 When RECURSIVE? is true, check out submodules as well, if any.
 
@@ -548,7 +555,7 @@ (define-record-type* <git-checkout>
   git-checkout make-git-checkout
   git-checkout?
   (url     git-checkout-url)
-  (branch  git-checkout-branch (default "master"))
+  (branch  git-checkout-branch (default #f))
   (commit  git-checkout-commit (default #f))      ;#f | tag | commit
   (recursive? git-checkout-recursive? (default #f)))
 
@@ -587,9 +594,11 @@ (define-gexp-compiler (git-checkout-compiler (checkout <git-checkout>)
   (match checkout
     (($ <git-checkout> url branch commit recursive?)
      (latest-repository-commit* url
-                                #:ref (if commit
-                                          `(tag-or-commit . ,commit)
-                                          `(branch . ,branch))
+                                #:ref (cond (commit
+                                             `(tag-or-commit . ,commit))
+                                            (branch
+                                             `(branch . ,branch))
+                                            (else '()))
                                 #:recursive? recursive?
                                 #:log-port (current-error-port)))))
 

base-commit: f68bcc1bc3aa0a8d1829e2eb5d9ef256c817c17c
-- 
2.31.1





  reply	other threads:[~2021-04-10  3:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-11 21:02 bug#45187: git download defaults to origin/master Ricardo Wurmus
2020-12-11 23:02 ` Kyle Meyer
2020-12-13 21:52   ` Marius Bakke
2020-12-14  4:49     ` Kyle Meyer
2020-12-14 10:27     ` Ludovic Courtès
2020-12-14 10:28   ` Ludovic Courtès
2020-12-15  6:07     ` Kyle Meyer
2021-04-08 16:21       ` Ricardo Wurmus
2021-04-09  5:10         ` bug#45187: [PATCH] git: Update cached checkout to the remote HEAD by default Kyle Meyer
2021-04-09 13:50           ` bug#45187: git download defaults to origin/master Ludovic Courtès
2021-04-10  3:50             ` Kyle Meyer [this message]
2021-04-10  5:51               ` Kyle Meyer
2021-04-10 19:33               ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v98ussqy.fsf@kyleam.com \
    --to=kyle@kyleam.com \
    --cc=45187@debbugs.gnu.org \
    --cc=ludo@gnu.org \
    --cc=rekado@elephly.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.