From patchwork Sat Sep 4 18:10:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marius Bakke X-Patchwork-Id: 32620 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 7DFCF27BBE3; Sat, 4 Sep 2021 19:11:15 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 4085E27BBE1 for ; Sat, 4 Sep 2021 19:11:15 +0100 (BST) Received: from localhost ([::1]:34422 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mMa8I-0007mE-Aw for patchwork@mira.cbaines.net; Sat, 04 Sep 2021 14:11:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36808) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mMa87-0007f4-0n for guix-patches@gnu.org; Sat, 04 Sep 2021 14:11:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:37002) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mMa86-0003Me-Mp for guix-patches@gnu.org; Sat, 04 Sep 2021 14:11:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mMa86-0003Y2-IK for guix-patches@gnu.org; Sat, 04 Sep 2021 14:11:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50377] [PATCH 1/2] git: 'resolve-reference' handles 'git describe'-style commit IDs. Resent-From: Marius Bakke Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 04 Sep 2021 18:11:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50377 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 50377@debbugs.gnu.org Received: via spool by 50377-submit@debbugs.gnu.org id=B50377.163077904513597 (code B ref 50377); Sat, 04 Sep 2021 18:11:02 +0000 Received: (at 50377) by debbugs.gnu.org; 4 Sep 2021 18:10:45 +0000 Received: from localhost ([127.0.0.1]:48545 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mMa7o-0003XE-W4 for submit@debbugs.gnu.org; Sat, 04 Sep 2021 14:10:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48886) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mMa7n-0003Wz-Io for 50377@debbugs.gnu.org; Sat, 04 Sep 2021 14:10:44 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:39920) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mMa7i-00032M-8m for 50377@debbugs.gnu.org; Sat, 04 Sep 2021 14:10:38 -0400 Received: from host-37-191-231-185.lynet.no ([37.191.231.185]:38034 helo=localhost) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mMa7h-00059v-ST for 50377@debbugs.gnu.org; Sat, 04 Sep 2021 14:10:38 -0400 From: Marius Bakke Date: Sat, 4 Sep 2021 20:10:34 +0200 Message-Id: <20210904181035.24161-1-marius@gnu.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210904180845.23915-1-marius@gnu.org> References: <20210904180845.23915-1-marius@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" X-getmail-retrieved-from-mailbox: Patches * guix/git.scm (resolve-reference): Use REVPARSE-SINGLE for looking up commits. Rewrite tag-or-commit case to recognize 'git describe' style identifiers and resolve them as commits. --- guix/git.scm | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/guix/git.scm b/guix/git.scm index 9c6f326c36..5e52630f5a 100644 --- a/guix/git.scm +++ b/guix/git.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2017, 2020 Mathieu Othacehe ;;; Copyright © 2018, 2019, 2020, 2021 Ludovic Courtès ;;; Copyright © 2021 Kyle Meyer +;;; Copyright © 2021 Marius Bakke ;;; ;;; This file is part of GNU Guix. ;;; @@ -214,24 +215,26 @@ corresponding Git object." (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 - ;; can't be sure it's available. Furthermore, 'string->oid' used to - ;; read out-of-bounds when passed a string shorter than 40 chars, - ;; which is why we delay calls to it below. - (if (< len 40) - (object-lookup-prefix repository (string->oid commit) len) - (object-lookup repository (string->oid commit))))) + (revparse-single repository commit)) (('tag-or-commit . str) - (if (or (> (string-length str) 40) - (not (string-every char-set:hex-digit str))) - (resolve `(tag . ,str)) ;definitely a tag - (catch 'git-error - (lambda () - (resolve `(tag . ,str))) - (lambda _ - ;; There's no such tag, so it must be a commit ID. - (resolve `(commit . ,str)))))) + (cond ((and (> (string-length str) 8) + (string-contains str "-g") + (match (string-split str #\-) + ((components ... g+id) + (string-every char-set:hex-digit + (string-drop g+id 1))) + (_ #f))) + (resolve `(commit . ,str))) ;looks like a 'git describe' style ID + ((or (> (string-length str) 40) + (not (string-every char-set:hex-digit str))) + (resolve `(tag . ,str))) ;definitely a tag + (else + (catch 'git-error + (lambda () + (resolve `(tag . ,str))) + (lambda _ + ;; There's no such tag, so it must be a commit ID. + (resolve `(commit . ,str))))))) (('tag . tag) (let ((oid (reference-name->oid repository (string-append "refs/tags/" tag)))) From patchwork Sat Sep 4 18:10:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marius Bakke X-Patchwork-Id: 32619 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 357F727BBE3; Sat, 4 Sep 2021 19:11:13 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id BB13627BBE1 for ; Sat, 4 Sep 2021 19:11:12 +0100 (BST) Received: from localhost ([::1]:34290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mMa8F-0007gu-S6 for patchwork@mira.cbaines.net; Sat, 04 Sep 2021 14:11:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mMa87-0007fR-Ah for guix-patches@gnu.org; Sat, 04 Sep 2021 14:11:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:37003) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mMa87-0003Mj-2w for guix-patches@gnu.org; Sat, 04 Sep 2021 14:11:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mMa86-0003Y9-Uv for guix-patches@gnu.org; Sat, 04 Sep 2021 14:11:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50377] [PATCH 2/2] transformations: 'git describe' style commit IDs are used as version. Resent-From: Marius Bakke Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 04 Sep 2021 18:11:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50377 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 50377@debbugs.gnu.org Received: via spool by 50377-submit@debbugs.gnu.org id=B50377.163077904913614 (code B ref 50377); Sat, 04 Sep 2021 18:11:02 +0000 Received: (at 50377) by debbugs.gnu.org; 4 Sep 2021 18:10:49 +0000 Received: from localhost ([127.0.0.1]:48548 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mMa7t-0003XW-9f for submit@debbugs.gnu.org; Sat, 04 Sep 2021 14:10:49 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48902) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mMa7r-0003X4-Cu for 50377@debbugs.gnu.org; Sat, 04 Sep 2021 14:10:47 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:39922) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mMa7m-00035s-8Y for 50377@debbugs.gnu.org; Sat, 04 Sep 2021 14:10:42 -0400 Received: from host-37-191-231-185.lynet.no ([37.191.231.185]:38036 helo=localhost) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mMa7k-0005BX-Ax for 50377@debbugs.gnu.org; Sat, 04 Sep 2021 14:10:42 -0400 From: Marius Bakke Date: Sat, 4 Sep 2021 20:10:35 +0200 Message-Id: <20210904181035.24161-2-marius@gnu.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210904181035.24161-1-marius@gnu.org> References: <20210904180845.23915-1-marius@gnu.org> <20210904181035.24161-1-marius@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" X-getmail-retrieved-from-mailbox: Patches * guix/transformations.scm (transform-package-source-commit): Look for 'git describe' style IDs and use it as the version if applicable. * tests/transformations.scm ("options->transformation, with-commit, 'git describe' style version"): New test. --- guix/transformations.scm | 34 +++++++++++++++++++++++++--------- tests/transformations.scm | 19 +++++++++++++++++++ 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/guix/transformations.scm b/guix/transformations.scm index 5122baa403..e91bce3808 100644 --- a/guix/transformations.scm +++ b/guix/transformations.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès +;;; Copyright © 2021 Marius Bakke ;;; ;;; This file is part of GNU Guix. ;;; @@ -278,15 +279,30 @@ strings like \"guile-next=cabba9e\" meaning that packages are built using (define (replace old url commit) (package (inherit old) - (version (if (and (> (string-length commit) 1) - (string-prefix? "v" commit) - (char-set-contains? char-set:digit - (string-ref commit 1))) - (string-drop commit 1) ;looks like a tag like "v1.0" - (string-append "git." - (if (< (string-length commit) 7) - commit - (string-take commit 7))))) + (version (cond ((and (> (string-length commit) 8) + (string-contains commit "-g") + (match (string-split commit #\-) + ((components ... g+id) + (char-set-every (cut char-set-contains? + char-set:hex-digit <>) + (string->char-set + (string-drop g+id 1)))) + (_ #f))) + ;; This looks like a 'git describe' style ID. Drop + ;; the 'v' prefix if applicable. + (if (string-prefix? "v" commit) + (string-drop commit 1) + commit)) + ((and (> (string-length commit) 1) + (string-prefix? "v" commit) + (char-set-contains? char-set:digit + (string-ref commit 1))) + (string-drop commit 1)) ;looks like a tag like "v1.0" + (else + (string-append "git." + (if (< (string-length commit) 7) + commit + (string-take commit 7)))))) (source (git-checkout (url url) (commit commit) (recursive? #t))))) diff --git a/tests/transformations.scm b/tests/transformations.scm index 3417c994ec..44fccffcce 100644 --- a/tests/transformations.scm +++ b/tests/transformations.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2016, 2017, 2019, 2020, 2021 Ludovic Courtès +;;; Copyright © 2021 Marius Bakke ;;; ;;; This file is part of GNU Guix. ;;; @@ -235,6 +236,24 @@ (string=? (package-name dep2) "chbouib") (package-source dep2)))))))) +(test-equal "options->transformation, with-commit, 'git describe' style version" + "1.0-gcabba9e2" + (let* ((p (dummy-package "guix.scm" + (inputs `(("foo" ,grep) + ("bar" ,(dummy-package "chbouib" + (source (origin + (method git-fetch) + (uri (git-reference + (url "https://example.org") + (commit "cabba9e"))) + (sha256 #f))))))))) + (t (options->transformation '((with-commit . "chbouib=v1.0-gcabba9e2"))))) + (let ((new (t p))) + (and (not (eq? new p)) + (match (package-inputs new) + ((("foo" dep1) ("bar" dep2)) + (package-version dep2))))))) + (test-equal "options->transformation, with-git-url" (let ((source (git-checkout (url "https://example.org") (recursive? #t))))