From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:bcc0::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 2JhcI70gcWAoDQEAgWs5BA (envelope-from ) for ; Sat, 10 Apr 2021 05:51:25 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id qDkpHb0gcWCMMAAAB5/wlQ (envelope-from ) for ; Sat, 10 Apr 2021 03:51:25 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id C6F6AEC0A for ; Sat, 10 Apr 2021 05:51:23 +0200 (CEST) Received: from localhost ([::1]:48004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lV4eY-00085C-Dk for larch@yhetil.org; Fri, 09 Apr 2021 23:51:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lV4eE-000853-Nh for bug-guix@gnu.org; Fri, 09 Apr 2021 23:51:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:39709) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lV4eE-0006xO-Gc for bug-guix@gnu.org; Fri, 09 Apr 2021 23:51:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lV4eE-0006vm-4t for bug-guix@gnu.org; Fri, 09 Apr 2021 23:51:02 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#45187: git download defaults to origin/master References: <878sa4vyxb.fsf@elephly.net> Resent-From: Kyle Meyer Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Sat, 10 Apr 2021 03:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45187 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 45187-submit@debbugs.gnu.org id=B45187.161802662626597 (code B ref 45187); Sat, 10 Apr 2021 03:51:02 +0000 Received: (at 45187) by debbugs.gnu.org; 10 Apr 2021 03:50:26 +0000 Received: from localhost ([127.0.0.1]:51255 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lV4dd-0006uv-6e for submit@debbugs.gnu.org; Fri, 09 Apr 2021 23:50:25 -0400 Received: from out1.migadu.com ([91.121.223.63]:31784) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lV4da-0006uj-9z for 45187@debbugs.gnu.org; Fri, 09 Apr 2021 23:50:24 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kyleam.com; s=key1; t=1618026620; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to; bh=/A3BJGfm4TYOo3jO5mJ5FZljiZQApIAww+nM6rsEF4Y=; b=G9dRPMrAJIv1UBTIDIEj4qlZcOnG7mp3N6PhUpcCKiMv9FUj+ACNDDd8fsnWcWv45HiWTX fuxwH58mZGdB1tlW2O43KkO7hygl59+r5/zGi8xgFV5+MIAHt54RzIcgGhNgiU57P5z7Va wAT/2OspWauOQ6vBF5dAJ51ypfenKXKJnQ9gtrN9X55yA8F8AoXV6GeajsW4lzKeZVBhdS 0APcrS1YkSS6lvKRF4dWXOPBB73wCsxRwdu3PlKf6ZnqMsaGVijHDdg5tGtZqOBb5nQv8G niJpwTRLXR1nhxZfUkn0wXeTWpyM97pK+QpVsNmyX3qpekmuJOTKTNHNjkhc5Q== From: Kyle Meyer In-Reply-To: <87fszz7ej2.fsf_-_@gnu.org> Date: Fri, 09 Apr 2021 23:50:13 -0400 Message-ID: <87v98ussqy.fsf@kyleam.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Migadu-Auth-User: kyle@kyleam.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ricardo Wurmus , 45187@debbugs.gnu.org Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: "bug-Guix" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1618026684; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=/A3BJGfm4TYOo3jO5mJ5FZljiZQApIAww+nM6rsEF4Y=; b=L15Y85DU7Sut3W+DFBgYkpc0XVUg85WIxK8x55RCCoASwXNwGeHOCpOyMPwgBn+UzWFrtQ rYExdHOjz3Rm6A4Z/RTnC4aUs63gPRvklHA3us0oYESj7ZBJ1adfYISSSNft8y/RNLRIpV fA5u84lrTFZweNUjQOPmBMKXuprQENTadSUIi8AAF099W3zjJf295RvMJhzpOtq6zEHKJ0 liixIile2vUnhGBOUFjVRmjTg3I1kMy6MRNTpdPowndlovQ3h+gigFGWEw66yMawye6KCB Gc4ZsyYfoIQquiagAoDTHEPHYBKo/J46XN6KewdzfeibcHpbS5ODqNZ9ovPDww== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1618026684; a=rsa-sha256; cv=none; b=jwZgmhiwq9h33CgAIFyUu0OTivBfyYAkA+29ociBtAcxv6TRWSG16JAO8+i/xT4UbrKD4h /TqRif7JeayD3yF9OYj94Lcksu+M5XJszcPb1qu41gXF9mxdowDKd3SZpYsVEhtoDQgigt wRGZ40DDPozsPhYbmQyHVzcQyvpds9JZ3C4sGy4bCfuR7fst6fgqvvzO5O4ROSMIAQa4mE cRtDFu3dQg8japOz989/754mK6XCjMbkIhJl+MnZj7BWrm2oWrrT5EN14W+/gGatAj8ETV HKufeZ62xklTjegtwrqgYu2Hh5Ne1+NlRgNEpv/yFMWKAIb5q4lEDkR5BakaWw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=kyleam.com header.s=key1 header.b=G9dRPMrA; spf=pass (aspmx1.migadu.com: domain of bug-guix-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=bug-guix-bounces@gnu.org X-Migadu-Spam-Score: 0.06 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=kyleam.com header.s=key1 header.b=G9dRPMrA; dmarc=none; spf=pass (aspmx1.migadu.com: domain of bug-guix-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=bug-guix-bounces@gnu.org X-Migadu-Queue-Id: C6F6AEC0A X-Spam-Score: 0.06 X-Migadu-Scanner: scn0.migadu.com X-TUID: LxG76WTpw+wc Ludovic Court=C3=A8s writes: > Kyle Meyer 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=E2=80=99s established Git jargon, but =E2=80=9Csymref=E2=80=9D = looks obscure to me. > I find it OK for =E2=80=98update-cached-checkout=E2=80=99, because it=E2= =80=99s an =E2=80=9Cinternal=E2=80=9D > 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 =E2=80=98symref=E2=80=99 field an= d instead, when > =E2=80=98branch=E2=80=99 and =E2=80=98commit=E2=80=99 are both #f, transl= ate 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 defau= lt. Fixes . Reported by Ricardo Wurmus . update-cached-checkout hard codes "master" as the default branch, leading t= o a failure when the clone doesn't have a "master" branch. Instead use the rem= ote 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. (): 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 =C2=A9 2017, 2020 Mathieu Othacehe ;;; Copyright =C2=A9 2018, 2019, 2020, 2021 Ludovic Court=C3=A8s +;;; Copyright =C2=A9 2021 Kyle Meyer ;;; ;;; 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) =20 (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 =20 REF is pair whose key is [branch | commit | tag | tag-or-commit ] and value the associated data: [ | | | ]. +IF REF is the empty list, the remote HEAD is used. =20 When RECURSIVE? is true, check out submodules as well, if any. =20 @@ -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. T= he 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 [ | | ]. +data, respectively [ | | ]. IF REF is the e= mpty +list, the remote HEAD is used. =20 When RECURSIVE? is true, check out submodules as well, if any. =20 @@ -548,7 +555,7 @@ (define-record-type* 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))) =20 @@ -587,9 +594,11 @@ (define-gexp-compiler (git-checkout-compiler (checkout= ) (match 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))))) =20 base-commit: f68bcc1bc3aa0a8d1829e2eb5d9ef256c817c17c --=20 2.31.1