From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id yDDgNZUj/2QfZwAAauVa8A:P1 (envelope-from ) for ; Mon, 11 Sep 2023 16:26:30 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id yDDgNZUj/2QfZwAAauVa8A (envelope-from ) for ; Mon, 11 Sep 2023 16:26:29 +0200 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 AF69C478FB for ; Mon, 11 Sep 2023 16:26:29 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=BlO+gHNP; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1694442389; 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=NhkD4LZUlsDDA0ql2tBJERZrS5hCR8P2YozzIJfod8I=; b=fG/CkE/im6Pimiv5nlzGOCJUSGcFEkjsq+qad+49oaDOeipombnLVsYRv/uvTDxBIp3Qcp hmXxiMKZ+LR/i9qKcWBJPsNur7sbY8lAO559wEuR3qJ1bNTWx+e8t375KU5q1ZhHtboA4W i5Hj9BQjALFMDwBys7Oz7AqNyFiMINUSzd5OGNrBCiwOd3N1+kobJVWX9oixABrMZ2qj1z 2JPRF4K42i1MMh6FhA5vyjL9rQQFdmyh8JSUW3v7oxSVRE3wkyByi52eAjXqYZOS+8k1NQ UeYqc5KxiERIafeY7mJj5aaZtDPOXqpjOLq9fUW19cq9xxwlurlxQld6Ub8S4w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=BlO+gHNP; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1694442389; a=rsa-sha256; cv=none; b=dmkpCui31OPg2/B7c0NLPro0UXLF3F3BnlRmdjja7Kt0e8n6FZJkMqtDQq9cFXb6xOz11a J2uCpMG6XqY1qx+L346bgoLeFjXRsdoIpr4eKL7+i1mPKJ0K+r/4w72KYdxEsGhv8tOQl8 qkEuE8aXHkhdTzmVt8sddCkoGdxu3r3U9PzSLl9WUdB+McJsJQCbK/bpR2igA3WxRCpXd6 3kGaaWIouxQs+SREBr9wsQ3RGlVjcv8bwUkVYLlmIRaoTcROIrXwGqlEXot+sKbiE1tymc b7CsttFyDe2z36fAWbhDuP/d90ui6w+/ZFCvUPdRK0NdWaovZNz54NxmJk0bmA== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qfhrc-0003sw-Nc; Mon, 11 Sep 2023 10:26:08 -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 1qfhrX-0003qX-Ex for guix-patches@gnu.org; Mon, 11 Sep 2023 10:26:03 -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 1qfhrW-00035t-4p; Mon, 11 Sep 2023 10:26:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qfhrV-0006gz-R0; Mon, 11 Sep 2023 10:26:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#65866] [PATCH 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: Mon, 11 Sep 2023 14:26:01 +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.169444235125649 (code B ref 65866); Mon, 11 Sep 2023 14:26:01 +0000 Received: (at 65866) by debbugs.gnu.org; 11 Sep 2023 14:25:51 +0000 Received: from localhost ([127.0.0.1]:54260 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qfhrL-0006fW-1i for submit@debbugs.gnu.org; Mon, 11 Sep 2023 10:25:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54974) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qfhrJ-0006f7-4k for 65866@debbugs.gnu.org; Mon, 11 Sep 2023 10:25:49 -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 1qfhr9-0002xL-Lx; Mon, 11 Sep 2023 10:25:39 -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=BlO+gHNPGdjPFbkWr6nz pzBLctux9qRsmOWlilsAMK5arxWUvitoXbjuhHAxm7dkL+dAT6DfFh+zTSu6ZMmXc5O6+Uxnp6ddl qjsMKIigHK5CR30NghNL8zKHBLlyXWjFl0Bcrb+A7sbW1DACjrolJq5Xsmg4mXHZDWftP7ELl0N2y bHAaDkfTiNH5OxQSRuZ/8XlQ7mshdXx2COVOhXsveAwHUqp/LJAD0XLQF5KLS73ZpIqEigW41S/oE jWsTQhkCIoSwx95S7xzWhbsW88b3jjzHx2KpqYH0riz/xK2s2ZjahCHolH7tFPpdRc89045Mscvqm UKi/45n7RK1oWw==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Mon, 11 Sep 2023 16:25:19 +0200 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx1.migadu.com X-Migadu-Spam-Score: -4.42 X-Spam-Score: -4.42 X-Migadu-Queue-Id: AF69C478FB X-TUID: ehNBroirOz47 * 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 -- 2.41.0