From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id EBU3ITulZ2UtQgAA9RJhRA:P1 (envelope-from ) for ; Wed, 29 Nov 2023 21:55:23 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id EBU3ITulZ2UtQgAA9RJhRA (envelope-from ) for ; Wed, 29 Nov 2023 21:55:23 +0100 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 1D07854C77 for ; Wed, 29 Nov 2023 21:55:23 +0100 (CET) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20230601 header.b=UbaTJFvB; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1701291323; 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=+g9zgFox1WA0+ttxLLokz6eTRxjtsQ7tf8MQus1QiKo=; b=VbvDKpPMvnlp35/vGb+EsYVHYOBBI/B8HZNqi/2g4HbMh7cn4i4hrqLF39f8wSBGuxqmYg GxNDQYLxlL/9dZmkhBxfFJZGpSFOFhYpWlrBB6K68dyeOcZoWWA8bCleoiAlTmEwHUEzCk 6Yy3TCLJ8+g5WptyxyW5WQ1g4X5fGupXdWFmHp84ePHcldAXXfi/rTu/zOvggpM4b+/y4a 2pA/X6LVuy4gTBwiEL7vA3UiZ20UmSrO8Tie2vRuhty5Xq1/v8a5qpNnAtsWDNxtAoorV5 iZ+x7jGiIM7PooxmhXSTeTFDXn9CfYWYFWHBL1d5eXFOBj2g/YuKMRsUgZOeKQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1701291323; a=rsa-sha256; cv=none; b=gVf2EZTbWYpFKL7ypcZ1oy9eW3iiiT/NiWjt/2IugA+ZxrCFUFrEmiwqcJNEj6zY3NLG5U 9V3pDgG5KU4sSm+RbI8EO0pFzLwnwVOP0t/qxtroTFDT1s+Xp5Hll5qJrUzaAkjaphzSko SkrompOLMgHqNKvV6opYkpIeaWwcemel8TjRGVkp1OQT3FnjLpKJM7+w+jfMeRCuf27b2r 9iigwnY44uDB8sdHTlRQ4HXDBr5GEjRYgUtZfi6EhWBFdsrUOUyFpMjXrftsUJk24Ye9wY eqXqho0uVN+ZFEV+Oj3um4YpiSmpOiqBvsS6RnaUuMqG/hjmqK5P+Iw4Ypr86A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20230601 header.b=UbaTJFvB; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); 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" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8RaI-0003ka-5l; Wed, 29 Nov 2023 15:55:02 -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 1r8RaG-0003jv-Ie for guix-patches@gnu.org; Wed, 29 Nov 2023 15:55:00 -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 1r8RaF-00077e-H9; Wed, 29 Nov 2023 15:54:59 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r8RaH-0008JO-RQ; Wed, 29 Nov 2023 15:55:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#66961] [PATCH v3] scripts: hash: Handle repository with different VCS folders. References: <4be63ddf12bd6143b43e87951e164dc93c585bb8.1699225200.git.zimon.toutoune@gmail.com> In-Reply-To: <4be63ddf12bd6143b43e87951e164dc93c585bb8.1699225200.git.zimon.toutoune@gmail.com> 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: Wed, 29 Nov 2023 20:55:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 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-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 66961-submit@debbugs.gnu.org id=B66961.170129126631906 (code B ref 66961); Wed, 29 Nov 2023 20:55:01 +0000 Received: (at 66961) by debbugs.gnu.org; 29 Nov 2023 20:54:26 +0000 Received: from localhost ([127.0.0.1]:51590 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r8RZi-0008IX-5T for submit@debbugs.gnu.org; Wed, 29 Nov 2023 15:54:26 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:40060) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r8RZf-0008IJ-Kr for 66961@debbugs.gnu.org; Wed, 29 Nov 2023 15:54:24 -0500 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3316d855828so43217f8f.0 for <66961@debbugs.gnu.org>; Wed, 29 Nov 2023 12:54:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701291250; x=1701896050; darn=debbugs.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=+g9zgFox1WA0+ttxLLokz6eTRxjtsQ7tf8MQus1QiKo=; b=UbaTJFvBoySv/Y373+uu7YBfj3dPQLlDaTqZ70OfQaBTLUA/U4kLVGHynk91mm2pV2 gdsfdAN0O99bg4O7G1i9BTmPzI1a6NILpxTW32CRdTYqPwikknTHjkHNt+M04+28KP20 /SUHF5tgaGTZ8PZ4reCr+uH2hEPbdFUSBVG4Ofl1e9vDXjwBMs1L7OJ9pA3mrwqbtDdk JTMAn4nC2rErfvlDJAXBNuX9lAzJhtagzed7KqUVGjKUydOn2HJzVSO8LqRIO48o1MCt 8tXjQ4R4ojOm2VM+ZSZlPPrSt3c+Wb4VpabwdU1eaoYRGSnkExqF41Y2ndXgms4lGv+x THeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701291250; x=1701896050; 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=+g9zgFox1WA0+ttxLLokz6eTRxjtsQ7tf8MQus1QiKo=; b=qnCgi1gR8df3GtSrLzWbOLhu92R3vAeu5oB/FOsPpAP2tLb5/62tDtouQoe2B89Kfh 6ODpLF+rwi3eBO1UTI4qvT9k0YXvPUJDZ8tt/uCu++4pf72PGPg4rPCDnY6YUE11Rfbg z3uSy4CBMlKwFUTq276ZBHW20ut7gPJsK29C28IhCWtfLy8vUqzEsBVXY7CaZ/LUrBGb cbYvQlsuqfg0iWXsJHefT1IUltXFbjeQjcY5eYkdhNhym5AUGW7mPHS2UlY9iQLXVXeo cKOCnL/MVzBCHHMZ07SUHE0HrvBak5NhPqhcjViVulDEBbncJkEcK0IiUZPJIWSX30ID rwEQ== X-Gm-Message-State: AOJu0YxeVXcBKj5Sk8nQXQa9afNjUgGOuMnclz7vmWiECfLCc2F+bUEC h1Wj7/cC422xwdIiCUbWEdkiD/ZQPVI= X-Google-Smtp-Source: AGHT+IE0kNUuI816YF0wiLwONGwYDH6MFNOE4nRBe82ue64sIgGLCijnbmxSyAG3KZTg1vSWwkdR9w== X-Received: by 2002:a05:6000:4011:b0:332:e749:adaa with SMTP id cp17-20020a056000401100b00332e749adaamr13264355wrb.3.1701291249890; Wed, 29 Nov 2023 12:54:09 -0800 (PST) Received: from lili.home (2a01cb04060a11004b3b81ecb857e340.ipv6.abo.wanadoo.fr. [2a01:cb04:60a:1100:4b3b:81ec:b857:e340]) by smtp.gmail.com with ESMTPSA id w27-20020adf8bdb000000b00332e5624a31sm18234719wra.84.2023.11.29.12.54.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 12:54:09 -0800 (PST) From: Simon Tournier Date: Wed, 29 Nov 2023 21:54:03 +0100 Message-ID: <6a560e37ba23e43d35c0b62c1ee860b4341c263c.1701290895.git.zimon.toutoune@gmail.com> X-Mailer: git-send-email 2.41.0 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-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx11.migadu.com X-Migadu-Spam-Score: -3.54 X-Spam-Score: -3.54 X-Migadu-Queue-Id: 1D07854C77 X-TUID: 7fh6ckgqQdkB Fixes . Reported by Simon Tournier * guix/hash.scm (%vcs-directories): New variable. (vcs-file?): Add optional argument for passing VCS kind of the file/repository. (file-hash*): Adjust accordingly. (vcs-exclude?): New procedure and export it. * guix/scripts/hash.scm (guix-hash)[file-hash]: Use it. Change-Id: I8e286c3426ddefd664dc3a471d5a09e309824faa --- guix/hash.scm | 34 ++++++++++++++++++++++++++++------ guix/scripts/hash.scm | 10 +++++----- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/guix/hash.scm b/guix/hash.scm index 3cb68e5c44..650def0696 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. ;;; @@ -23,23 +24,44 @@ (define-module (guix hash) #:use-module (srfi srfi-1) #:use-module (srfi srfi-11) #:export (vcs-file? + vcs-exclude? file-hash*)) -(define (vcs-file? file stat) - "Returns true if FILE is a version control system file." +(define %vcs-directories + ;; Directory used for determining the kind of VCS. + (list ".bzr" ".git" ".hg" ".svn" "CVS")) + +(define* (vcs-file? file stat + #:optional + (vcs-directories %vcs-directories)) + "Return true if FILE matches a version control system from the list +VCSES-DIRECTORIES." (case (stat:type stat) ((directory) - (member (basename file) '(".bzr" ".git" ".hg" ".svn" "CVS"))) + (member (basename file) vcs-directories)) ((regular) - ;; Git sub-modules have a '.git' file that is a regular text file. - (string=? (basename file) ".git")) + (if (member ".git" vcs-directories) + ;; Git sub-modules have a '.git' file that is a regular text file. + (string=? (basename file) ".git") + #f)) (else #f))) +(define (vcs-exclude? directory) + "Return a procedure excluding content if DIRECTORY contains supported VCS." + (define vcs-directories + (filter (lambda (vcs) + (file-exists? (in-vicinity directory vcs))) + %vcs-directories)) + + (lambda (file stat) + (not (vcs-file? file stat vcs-directories)))) + (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..8982bb37b9 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,10 @@ (define-command (guix-hash . args) (catch 'system-error (lambda _ (with-error-handling - (serializer file algorithm select?))) + (let ((select? (if (assq-ref opts 'exclude-vcs?) + (vcs-exclude? file) + (const #t)))) + (serializer file algorithm select?)))) (lambda args (leave (G_ "~a ~a~%") file base-commit: cd46757c1a0f886848fbb6828c028dd2a2532767 -- 2.41.0