From patchwork Fri Sep 22 22:27:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 54166 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 1147627BBE2; Fri, 22 Sep 2023 23:29:09 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id C746A27BBE2 for ; Fri, 22 Sep 2023 23:29:07 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qjodt-0001h5-Fn; Fri, 22 Sep 2023 18:28:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qjodq-0001gi-QT for guix-patches@gnu.org; Fri, 22 Sep 2023 18:28:54 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qjodq-0005sl-Cc; Fri, 22 Sep 2023 18:28:54 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qjody-0006kz-Nr; Fri, 22 Sep 2023 18:29:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#65866] [PATCH v2 1/8] git-download: Move fallback code to (guix build git). Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Fri, 22 Sep 2023 22:29:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65866 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 65866@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 65866-submit@debbugs.gnu.org id=B65866.169542173725931 (code B ref 65866); Fri, 22 Sep 2023 22:29:02 +0000 Received: (at 65866) by debbugs.gnu.org; 22 Sep 2023 22:28:57 +0000 Received: from localhost ([127.0.0.1]:37400 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjods-0006jy-Gy for submit@debbugs.gnu.org; Fri, 22 Sep 2023 18:28:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45520) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjodn-0006jF-8k for 65866@debbugs.gnu.org; Fri, 22 Sep 2023 18:28:54 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qjodX-0005lj-23; Fri, 22 Sep 2023 18:28:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=NhkD4LZUlsDDA0ql2tBJERZrS5hCR8P2YozzIJfod8I=; b=AswgeUpg0QCfzZNE2vV2 wgoMscITs749Z21M4txMlu34foKVujOHAwFiuNrPQsgEKHUYMfhdDXi2WVGnhIi7qtVD1xD9JAlUb bJ3TP7+CV+0N6yYNS9wVJzUeyp4OnFgCRsV2Zp+Waengs+Mo93x2vybuBqSLrOaz9I8AXHwQJ9yKI IfYidi7Cu9SMI/FSsfOJEZQIyZf/9/Ao9M6LHo2rGjTZg12Qhs3yhPnpTTNmyJXUyS/nipVArZwpF J95tgfmxo8bdx6ZcAUwZ6iSI540kOcSr6M+i/IpoMyfESG16TZLJSIxYHXls7mOjTBFovmnAdXwKV FakwHR5jxEWH2A==; From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Sat, 23 Sep 2023 00:27:57 +0200 Message-ID: <765792320d841e1e33a11f119ad687094ca2766f.1695421391.git.ludo@gnu.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: <87o7hwas61.fsf@gnu.org> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/build/git.scm (git-fetch-with-fallback): New procedure, with code taken from… * guix/git-download.scm (git-fetch): … here. [modules]: Remove modules that are no longer directly used in ‘build’. [build]: Use ‘git-fetch-with-fallback’. --- guix/build/git.scm | 44 ++++++++++++++++++++++++++++++++++++++-- guix/git-download.scm | 47 ++++++++----------------------------------- 2 files changed, 50 insertions(+), 41 deletions(-) diff --git a/guix/build/git.scm b/guix/build/git.scm index deda10fee8..0ff263c81b 100644 --- a/guix/build/git.scm +++ b/guix/build/git.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2014, 2016, 2019 Ludovic Courtès +;;; Copyright © 2014, 2016, 2019, 2023 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -18,9 +18,12 @@ (define-module (guix build git) #:use-module (guix build utils) + #:autoload (guix build download-nar) (download-nar) + #:autoload (guix swh) (%verify-swh-certificate? swh-download) #:use-module (srfi srfi-34) #:use-module (ice-9 format) - #:export (git-fetch)) + #:export (git-fetch + git-fetch-with-fallback)) ;;; Commentary: ;;; @@ -76,4 +79,41 @@ (define* (git-fetch url commit directory (delete-file-recursively ".git") #t))) + +(define* (git-fetch-with-fallback url commit directory + #:key (git-command "git") recursive?) + "Like 'git-fetch', fetch COMMIT from URL into DIRECTORY, but fall back to +alternative methods when fetching from URL fails: attempt to download a nar, +and if that also fails, download from the Software Heritage archive." + (or (git-fetch url commit directory + #:recursive? recursive? + #:git-command git-command) + (download-nar directory) + + ;; As a last resort, attempt to download from Software Heritage. + ;; Disable X.509 certificate verification to avoid depending + ;; on nss-certs--we're authenticating the checkout anyway. + ;; XXX: Currently recursive checkouts are not supported. + (and (not recursive?) + (parameterize ((%verify-swh-certificate? #f)) + (format (current-error-port) + "Trying to download from Software Heritage...~%") + + (swh-download url commit directory) + (when (file-exists? + (string-append directory "/.gitattributes")) + ;; Perform CR/LF conversion and other changes + ;; specificied by '.gitattributes'. + (invoke git-command "-C" directory "init") + (invoke git-command "-C" directory "config" "--local" + "user.email" "you@example.org") + (invoke git-command "-C" directory "config" "--local" + "user.name" "Your Name") + (invoke git-command "-C" directory "add" ".") + (invoke git-command "-C" directory "commit" "-am" "init") + (invoke git-command "-C" directory "read-tree" "--empty") + (invoke git-command "-C" directory "reset" "--hard") + (delete-file-recursively + (string-append directory "/.git"))))))) + ;;; git.scm ends here diff --git a/guix/git-download.scm b/guix/git-download.scm index d88f4c40ee..8989b1b463 100644 --- a/guix/git-download.scm +++ b/guix/git-download.scm @@ -116,19 +116,16 @@ (define* (git-fetch ref hash-algo hash (define modules (delete '(guix config) (source-module-closure '((guix build git) - (guix build utils) - (guix build download-nar) - (guix swh))))) + (guix build utils))))) (define build (with-imported-modules modules - (with-extensions (list guile-json gnutls ;for (guix swh) + (with-extensions (list guile-json gnutls ;for (guix swh) guile-lzlib) #~(begin (use-modules (guix build git) - (guix build utils) - (guix build download-nar) - (guix swh) + ((guix build utils) + #:select (set-path-environment-variable)) (ice-9 match)) (define recursive? @@ -151,38 +148,10 @@ (define* (git-fetch ref hash-algo hash (setvbuf (current-output-port) 'line) (setvbuf (current-error-port) 'line) - (or (git-fetch (getenv "git url") (getenv "git commit") - #$output - #:recursive? recursive? - #:git-command "git") - (download-nar #$output) - - ;; As a last resort, attempt to download from Software Heritage. - ;; Disable X.509 certificate verification to avoid depending - ;; on nss-certs--we're authenticating the checkout anyway. - ;; XXX: Currently recursive checkouts are not supported. - (and (not recursive?) - (parameterize ((%verify-swh-certificate? #f)) - (format (current-error-port) - "Trying to download from Software Heritage...~%") - - (swh-download (getenv "git url") (getenv "git commit") - #$output) - (when (file-exists? - (string-append #$output "/.gitattributes")) - ;; Perform CR/LF conversion and other changes - ;; specificied by '.gitattributes'. - (invoke "git" "-C" #$output "init") - (invoke "git" "-C" #$output "config" "--local" - "user.email" "you@example.org") - (invoke "git" "-C" #$output "config" "--local" - "user.name" "Your Name") - (invoke "git" "-C" #$output "add" ".") - (invoke "git" "-C" #$output "commit" "-am" "init") - (invoke "git" "-C" #$output "read-tree" "--empty") - (invoke "git" "-C" #$output "reset" "--hard") - (delete-file-recursively - (string-append #$output "/.git")))))))))) + (git-fetch-with-fallback (getenv "git url") (getenv "git commit") + #$output + #:recursive? recursive? + #:git-command "git"))))) (mlet %store-monad ((guile (package->derivation guile system))) (gexp->derivation (or name "git-checkout") build