From patchwork Wed Nov 29 20:54:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Tournier X-Patchwork-Id: 57122 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 9375A27BBEA; Wed, 29 Nov 2023 20:55:24 +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 981F427BBE9 for ; Wed, 29 Nov 2023 20:55:23 +0000 (GMT) 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 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-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(-) base-commit: cd46757c1a0f886848fbb6828c028dd2a2532767 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