From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id aVJ3FqqiGWGKKgEAgWs5BA (envelope-from ) for ; Mon, 16 Aug 2021 01:26:34 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id mNO5EaqiGWGNSgAA1q6Kng (envelope-from ) for ; Sun, 15 Aug 2021 23:26:34 +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 B5233E988 for ; Mon, 16 Aug 2021 01:26:33 +0200 (CEST) Received: from localhost ([::1]:58088 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mFPWS-0000N9-PR for larch@yhetil.org; Sun, 15 Aug 2021 19:26:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37848) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mFPVz-0008Jn-Fg for guix-patches@gnu.org; Sun, 15 Aug 2021 19:26:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:36405) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mFPVz-0004yp-9A for guix-patches@gnu.org; Sun, 15 Aug 2021 19:26:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mFPVz-0001qu-5x for guix-patches@gnu.org; Sun, 15 Aug 2021 19:26:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50072] [PATCH WIP 4/4] upstream: Support updating git-fetch origins. Resent-From: Sarah Morgensen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 15 Aug 2021 23:26:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50072 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 50072@debbugs.gnu.org Received: via spool by 50072-submit@debbugs.gnu.org id=B50072.16290699417072 (code B ref 50072); Sun, 15 Aug 2021 23:26:03 +0000 Received: (at 50072) by debbugs.gnu.org; 15 Aug 2021 23:25:41 +0000 Received: from localhost ([127.0.0.1]:47948 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mFPVc-0001pt-M6 for submit@debbugs.gnu.org; Sun, 15 Aug 2021 19:25:41 -0400 Received: from out0.migadu.com ([94.23.1.103]:31077) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mFPVa-0001pZ-D7 for 50072@debbugs.gnu.org; Sun, 15 Aug 2021 19:25:39 -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=mgsn.dev; s=key1; t=1629069937; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SaBFF2tRm7PZlrCixzWhD5HmIJdo0elYCu26DpndMPE=; b=dYLKoTk49hRJ19rfQYYfqNKaWd9X0R6fYgzpstssHtb/XZIq3EMi172z11IVqhPsIXGsY8 xq3uPcxRKHwCpB5UknK7kd20P19lcX0xvlrbqhtgCp4g/+RPYmR287UpiPtpL58fwe0PDU xEOmetKcpXJK0zb/1cSDMete83ra7f8= From: Sarah Morgensen Date: Sun, 15 Aug 2021 16:25:27 -0700 Message-Id: <8d1ae518b23fac5b15812a30b11df1c360ab3fbf.1629068119.git.iskarian@mgsn.dev> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Auth-User: iskarian@mgsn.dev 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" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1629069993; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=SaBFF2tRm7PZlrCixzWhD5HmIJdo0elYCu26DpndMPE=; b=kqJ4O+WfhsGnWejeJ+XgPYum6RIflU9N74CjzeAf0Lepuy25ZqWf/fGpBx3EXlX5JLOIUL LEkcdWoxIlze3lZGT7yalr2Q7hSm0Cq5yM65nRMRRpCtLRkajJRd59clkb+136X2VKw0nM EeOv/9Ys20lZMYg4AgXOPGfckIlaX3Ss5ODRtt7m0i0HcoNbMhFFcxRR4FQt7SkBL/8FPQ ozX9lS4qnsZClbvcm0QfbwiS3hhwTCOs9Pd9mfRXAo3pNr2IyyeWDlf1KODFM8+9jebbQR WBjrUN88pP1NIUET82t2yl4bDq8iR+byZaXhqw21YzJArUtzp8vlhjiuge98pA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1629069993; a=rsa-sha256; cv=none; b=EDc076VwBp3ZMcKwB/nEwKanpBcgq187/+7jazeWWYiGCz4pmvTlEg3X6r0pxDqonyhMTv K4iNNtXGwqB2iKvaQsARFDukSpn/QZ4swgyLMbk631xb0nbmnnxD58NI7t+K+g/eKfZVwe pbvgdRl7xhgHuy3u3y5LDJlTjYaNX1vGf9bhMsUmrMWhUb6tqifeEYiWw6ARSHoBbCkfkh wem+BPYEFP4ylTk3Z56uVpTkuKX+VVGzgJCeEYUXUieotuFkfx6Sd1GTB2cwR0OxvLNIQ6 t7GIz417tyIPSEQu2Ml/rW3QhVXk3s0v2UUfG0hC/TdtHLEHMt12hd+SgCR0lw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=mgsn.dev header.s=key1 header.b=dYLKoTk4; dmarc=fail reason="SPF not aligned (relaxed)" header.from=mgsn.dev (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -0.31 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=mgsn.dev header.s=key1 header.b=dYLKoTk4; dmarc=fail reason="SPF not aligned (relaxed)" header.from=mgsn.dev (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: B5233E988 X-Spam-Score: -0.31 X-Migadu-Scanner: scn0.migadu.com X-TUID: xMy87n68wHpS * guix/git-download.scm (checkout-to-store): New procedure. * guix/upstream.scm (guess-version-transform) (package-update/git-fetch): New procedures. (%method-updates): Add GIT-FETCH mapping. --- guix/git-download.scm | 18 +++++++++++++++++- guix/upstream.scm | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/guix/git-download.scm b/guix/git-download.scm index 5e624b9ae9..a7bdc16718 100644 --- a/guix/git-download.scm +++ b/guix/git-download.scm @@ -3,6 +3,7 @@ ;;; Copyright © 2017 Mathieu Lirzin ;;; Copyright © 2017 Christopher Baines ;;; Copyright © 2020 Jakub Kądziołka +;;; Copyright © 2021 Sarah Morgensen ;;; ;;; This file is part of GNU Guix. ;;; @@ -26,6 +27,7 @@ #:use-module (guix records) #:use-module (guix packages) #:use-module (guix modules) + #:use-module (guix git) #:autoload (guix build-system gnu) (standard-packages) #:autoload (git bindings) (libgit2-init!) #:autoload (git repository) (repository-open @@ -53,7 +55,9 @@ git-fetch git-version git-file-name - git-predicate)) + git-predicate + + checkout-to-store)) ;;; Commentary: ;;; @@ -287,4 +291,16 @@ absolute file name and STAT is the result of 'lstat'." (#f #f))))) (const #f))) +(define* (checkout-to-store store ref #:key (log (current-error-port))) + "Checkout REF to STORE. Write progress reports to LOG. RECURSIVE? has the +same effect as the same-named parameter of 'latest-repository-commit'." + ;; XXX: (guix git) does not use shallow clones, so this will be slow + ;; for long-running repositories. + (match-record ref + (url commit recursive?) + (latest-repository-commit store url + #:ref `(tag-or-commit . ,commit) + #:recursive? recursive? + #:log-port log))) + ;;; git-download.scm ends here diff --git a/guix/upstream.scm b/guix/upstream.scm index 632e9ebc4f..927260cd89 100644 --- a/guix/upstream.scm +++ b/guix/upstream.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès ;;; Copyright © 2015 Alex Kost ;;; Copyright © 2019 Ricardo Wurmus +;;; Copyright © 2021 Sarah Morgensen ;;; ;;; This file is part of GNU Guix. ;;; @@ -24,6 +25,7 @@ #:use-module (guix discovery) #:use-module ((guix download) #:select (download-to-store url-fetch)) + #:use-module (guix git-download) #:use-module (guix gnupg) #:use-module (guix packages) #:use-module (guix diagnostics) @@ -430,9 +432,46 @@ SOURCE, an ." #:key-download key-download))) (values version tarball source)))))) +(define (guess-version-transform commit from-version) + "Return a one-argument proc that transforms FROM-VERSION to COMMIT, or #f +if no such transformation could be determined." + ;; Just handle prefixes for now, since that's the most common. + (if (string-suffix? from-version commit) + (let* ((version-length (string-length from-version)) + (commit-prefix (string-drop-right commit version-length))) + (lambda (version) + (string-append commit-prefix version))) + #f)) + +(define* (package-update/git-fetch store package source + #:key key-download) + "Return the version, checkout, and SOURCE, to update PACKAGE to +SOURCE, an ." + + (define (uri-update/git old-uri old-version url version) + (let* ((old-commit (git-reference-commit old-uri)) + (transform (guess-version-transform old-commit old-version))) + (and transform + (git-reference + (inherit old-uri) + (url url) + (commit (transform version)))))) + + ;; Only use the first element of URLS. + (match-record source + (version urls) + (let* ((old-uri (origin-uri (package-source package))) + (old-version (package-version package)) + (new-uri (uri-update/git old-uri old-version + (first urls) version))) + (if new-uri + (values version (checkout-to-store store new-uri) source) + (values #f #f #f))))) + (define %method-updates ;; Mapping of origin methods to source update procedures. - `((,url-fetch . ,package-update/url-fetch))) + `((,url-fetch . ,package-update/url-fetch) + (,git-fetch . ,package-update/git-fetch))) (define* (package-update store package #:optional (updaters (force %updaters)) -- 2.31.1