From patchwork Sun Nov 5 23:00:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Tournier X-Patchwork-Id: 55963 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 4914527BBE2; Sun, 5 Nov 2023 23:01:54 +0000 (GMT) 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_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,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 D494327BBE9 for ; Sun, 5 Nov 2023 23:01:52 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qzm7X-000634-N6; Sun, 05 Nov 2023 18:01:31 -0500 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 1qzm7W-00062p-2B for guix-patches@gnu.org; Sun, 05 Nov 2023 18:01:30 -0500 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 1qzm7V-00062r-48; Sun, 05 Nov 2023 18:01:29 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qzm81-0006ss-ND; Sun, 05 Nov 2023 18:02:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#66961] [PATCH] scripts: hash: Handle repository with different VCS folders. Resent-From: Simon Tournier 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: Sun, 05 Nov 2023 23:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 66961 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 66961@debbugs.gnu.org Cc: Simon Tournier , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-To: guix-patches@gnu.org 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 submit@debbugs.gnu.org id=B.169922531526446 (code B ref -1); Sun, 05 Nov 2023 23:02:01 +0000 Received: (at submit) by debbugs.gnu.org; 5 Nov 2023 23:01:55 +0000 Received: from localhost ([127.0.0.1]:38338 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qzm7u-0006sS-U5 for submit@debbugs.gnu.org; Sun, 05 Nov 2023 18:01:55 -0500 Received: from lists.gnu.org ([2001:470:142::17]:45354) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qzm7r-0006sE-Vn for submit@debbugs.gnu.org; Sun, 05 Nov 2023 18:01:53 -0500 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 1qzm7B-00061I-G5 for guix-patches@gnu.org; Sun, 05 Nov 2023 18:01:09 -0500 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qzm79-0005vp-0c for guix-patches@gnu.org; Sun, 05 Nov 2023 18:01:09 -0500 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-408fd07bb78so4976355e9.1 for ; Sun, 05 Nov 2023 15:01:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699225265; x=1699830065; darn=gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=pLqWwnXmtS1revD+osuVniPpZQCkZqNiibmgdQ7aHK4=; b=KUe7sf2tPZPjiLT1CJ6ALjfw0AmX7NZDxBlTgQcwDqGEonbkatPpoL8vL7VKgcibZb NWbn8tVqjHpuWtbV+lcyGyLosaPfFCw1FsPlupCKypyr5hbPMxDQWctcvGi55+gfFQu8 dDGciqbfoJ7cFFw7cM9AYLO21JoUc9v4KOm2g/z8mDqr3LBYdIDOk2hc+1+7lhZi9oOV Hrn2CqHYdSgjZx9nBjv0IVNo7kU2kBr2hPFzg9+DohXdMOSj8Mk+Wg+ieX00YjKLULCW /L64yL9b5jNRUOusBQslk5mDplMgRuZu95Ym4S0Ky5IiDSWsREtgq+Q0kapzJNk+Edwk 5HRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699225265; x=1699830065; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pLqWwnXmtS1revD+osuVniPpZQCkZqNiibmgdQ7aHK4=; b=xCb8eN1GbYcwdBDt7esXeC7Xzj4UHWJTP2cpUmZ/lSpRLpBka53DKttQ+NqdtDPlNC OrJm90GICrE3RCGAM5MhvA5xT4MUVqj+qR6mzgQClmis6Ijld2kDhgAWFzfhl2cc20Nz tGIHHKCW2s3UXplkK6rgCULsOcaofbU5Nb+HWRAIuWt4b8OBg1O2ufwfmbVSLBItkhGj 8kr1d9RR7s/e5sxvTKV3kkd8EtRtT74U1lN23ABfEpw8hWQptjHZcTzun2IDvcb6pklt p5oV+Mcg/0d9LRGXuvueL3XpKGEY6mW/0BKuH2j07SBI84vtNNAW1vL87RE9uJlbdzb4 Alwg== X-Gm-Message-State: AOJu0YzgSVN7XkzHYz2exCWf76dBemMiHtK5N8/QwAg2cL3SV3RXLBEV epb7PIUCe4iaTXB0e0OsJV0Rk5XmMD8= X-Google-Smtp-Source: AGHT+IHnJxxgoAi/LL3f+YBbpEGTL4PvExpSvvFKgYizrjKWlR4aS3WrwjzZFC/g39Cp49HV9TURjg== X-Received: by 2002:a05:600c:1c1b:b0:403:334:fb0d with SMTP id j27-20020a05600c1c1b00b004030334fb0dmr22443670wms.4.1699225264475; Sun, 05 Nov 2023 15:01:04 -0800 (PST) Received: from localhost.localdomain ([193.48.40.241]) by smtp.gmail.com with ESMTPSA id q6-20020a05600c2e4600b003feae747ff2sm9977759wmf.35.2023.11.05.15.01.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 15:01:03 -0800 (PST) From: Simon Tournier Date: Mon, 6 Nov 2023 00:00:55 +0100 Message-ID: <4be63ddf12bd6143b43e87951e164dc93c585bb8.1699225200.git.zimon.toutoune@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=zimon.toutoune@gmail.com; helo=mail-wm1-x330.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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 Fixes . Reported by Simon Tournier * guix/hash.scm (vcs-file?): Add optional argument for passing VCS kind of the file/repository. (file-hash*): Adjust accordingly. * guix/scripts/hash.scm (guix-hash)[file-hash]: Detect VCS kind of the file/repository and passes it. Change-Id: I8e286c3426ddefd664dc3a471d5a09e309824faa --- guix/hash.scm | 18 ++++++++++++------ guix/scripts/hash.scm | 18 +++++++++++++----- 2 files changed, 25 insertions(+), 11 deletions(-) Hi, I re-resend this patch for more attractions in case I have missed something. :-) It had already been send more than 2 weeks ago as an answer to #65979. It fixes a corner case of "guix hash". --8<---------------cut here---------------start------------->8--- $ git clone https://github.com/s-andrews/FastQC /tmp/FastQC $ git -C /tmp/FastQC/ checkout v0.11.9 $ find /tmp/FastQC/ -type d -name ".git" -print /tmp/FastQC/.git $ find /tmp/FastQC/ -type d -name ".svn" -print /tmp/FastQC/Help/1 Introduction/.svn /tmp/FastQC/Help/3 Analysis Modules/.svn /tmp/FastQC/Help/2 Basic Operations/.svn $ guix hash -rx /tmp/FastQC 0jyk90kg6s62w3dn6qjx9nrawjs12qx172lii0yxbvsfylhnx479 $ grep -A 15 'define-public fastqc' gnu/packages/bioinformatics.scm | grep -C 1 base32 (sha256 (base32 "00y9drm0bkpxw8xfl8ysss18jmnhj8blgqgr6fpa58rkpfcbg8qk")) $ ./pre-inst-env guix hash -rx /tmp/FastQC 00y9drm0bkpxw8xfl8ysss18jmnhj8blgqgr6fpa58rkpfcbg8qk --8<---------------cut here---------------end--------------->8--- And it does not introduce any significant penalty: --8<---------------cut here---------------start------------->8--- $ time guix hash -rx . 093w70scf2v64bdbln5m2xjm63pzfib903w1mcb2smj32g0w8y63 real 0m9.730s user 0m20.468s sys 0m1.487s $ time ./pre-inst-env guix hash -rx . 093w70scf2v64bdbln5m2xjm63pzfib903w1mcb2smj32g0w8y63 real 0m9.632s user 0m20.320s sys 0m1.541s --8<---------------cut here---------------end--------------->8--- WDYT? Cheers, simon base-commit: 08d94fe20eca47b69678b3eced8749dd02c700a4 diff --git a/guix/hash.scm b/guix/hash.scm index 3cb68e5c44..8fff51e8f1 100644 --- a/guix/hash.scm +++ b/guix/hash.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2021 Sarah Morgensen ;;; Copyright © 2022 Maxime Devos +;;; Copyright © 2023 Simon Tournier ;;; ;;; This file is part of GNU Guix. ;;; @@ -25,21 +26,26 @@ (define-module (guix hash) #:export (vcs-file? file-hash*)) -(define (vcs-file? file stat) - "Returns true if FILE is a version control system file." +(define* (vcs-file? file stat + #:optional + (vcses (list ".bzr" ".git" ".hg" ".svn" "CVS"))) + "Returns true if FILE matches a version control system from the list VCSES." (case (stat:type stat) ((directory) - (member (basename file) '(".bzr" ".git" ".hg" ".svn" "CVS"))) + (member (basename file) vcses)) ((regular) - ;; Git sub-modules have a '.git' file that is a regular text file. - (string=? (basename file) ".git")) + (if (member ".git" vcses) + ;; Git sub-modules have a '.git' file that is a regular text file. + (string=? (basename file) ".git") + #f)) (else #f))) (define* (file-hash* file #:key (algorithm (hash-algorithm sha256)) (recursive? 'auto) - (select? (negate vcs-file?))) + (select? (negate (lambda (file stat) + (vcs-file? file stat))))) "Compute the hash of FILE with ALGORITHM. Symbolic links are only dereferenced if RECURSIVE? is false. diff --git a/guix/scripts/hash.scm b/guix/scripts/hash.scm index 7197d3965c..ed96e6a7e1 100644 --- a/guix/scripts/hash.scm +++ b/guix/scripts/hash.scm @@ -3,7 +3,7 @@ ;;; Copyright © 2013 Nikita Karetnikov ;;; Copyright © 2016 Jan Nieuwenhuizen ;;; Copyright © 2018 Tim Gesthuizen -;;; Copyright © 2021 Simon Tournier +;;; Copyright © 2021, 2023 Simon Tournier ;;; Copyright © 2021 Sarah Morgensen ;;; ;;; This file is part of GNU Guix. @@ -181,9 +181,6 @@ (define-command (guix-hash . args) (_ #f)) (reverse opts))) (fmt (assq-ref opts 'format)) - (select? (if (assq-ref opts 'exclude-vcs?) - (negate vcs-file?) - (const #t))) (algorithm (assoc-ref opts 'hash-algorithm)) (serializer (assoc-ref opts 'serializer))) @@ -193,7 +190,18 @@ (define-command (guix-hash . args) (catch 'system-error (lambda _ (with-error-handling - (serializer file algorithm select?))) + (let* ((vcses (fold (lambda (vcs result) + (if (file-exists? (string-append file "/" vcs)) + (cons vcs result) + result)) + '() + (list ".bzr" ".git" ".hg" ".svn" "CVS"))) + (select? (if (assq-ref opts 'exclude-vcs?) + (negate (lambda (file stat) + (vcs-file? file stat + vcses))) + (const #t)))) + (serializer file algorithm select?)))) (lambda args (leave (G_ "~a ~a~%") file