From: Simon Tournier <zimon.toutoune@gmail.com>
To: 66961@debbugs.gnu.org
Cc: "Simon Tournier" <zimon.toutoune@gmail.com>,
"Christopher Baines" <guix@cbaines.net>,
"Josselin Poiret" <dev@jpoiret.xyz>,
"Ludovic Courtès" <ludo@gnu.org>,
"Mathieu Othacehe" <othacehe@gnu.org>,
"Ricardo Wurmus" <rekado@elephly.net>,
"Simon Tournier" <zimon.toutoune@gmail.com>,
"Tobias Geerinckx-Rice" <me@tobias.gr>
Subject: [bug#66961] [PATCH v2] scripts: hash: Handle repository with different VCS folders.
Date: Wed, 29 Nov 2023 21:31:00 +0100 [thread overview]
Message-ID: <adfd8ba3e41841d280b873ed4199607b0bcfae52.1701289675.git.zimon.toutoune@gmail.com> (raw)
In-Reply-To: <4be63ddf12bd6143b43e87951e164dc93c585bb8.1699225200.git.zimon.toutoune@gmail.com>
Fixes <https://issues.guix.gnu.org/issue/65979>.
Reported by Simon Tournier <zimon.toutoune@gmail.com>
* 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): Use it.
Change-Id: I8e286c3426ddefd664dc3a471d5a09e309824faa
---
guix/hash.scm | 34 ++++++++++++++++++++++++++++------
guix/scripts/hash.scm | 2 +-
2 files changed, 29 insertions(+), 7 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 <iskarian@mgsn.dev>
;;; Copyright © 2022 Maxime Devos <maximedevos@telenet.be>
+;;; Copyright © 2023 Simon Tournier <zimon.toutoune@gmail.com>
;;;
;;; 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..b6af9d5649 100644
--- a/guix/scripts/hash.scm
+++ b/guix/scripts/hash.scm
@@ -182,7 +182,7 @@ (define-command (guix-hash . args)
(reverse opts)))
(fmt (assq-ref opts 'format))
(select? (if (assq-ref opts 'exclude-vcs?)
- (negate vcs-file?)
+ (vcs-exclude? file)
(const #t)))
(algorithm (assoc-ref opts 'hash-algorithm))
(serializer (assoc-ref opts 'serializer)))
base-commit: cd46757c1a0f886848fbb6828c028dd2a2532767
--
2.41.0
next prev parent reply other threads:[~2023-11-29 20:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-05 23:00 [bug#66961] [PATCH] scripts: hash: Handle repository with different VCS folders Simon Tournier
2023-11-14 13:44 ` Ludovic Courtès
2023-11-29 20:36 ` Simon Tournier
2023-11-29 20:52 ` Simon Tournier
2023-11-29 20:31 ` Simon Tournier [this message]
2023-11-29 20:54 ` [bug#66961] [PATCH v3] " Simon Tournier
2023-12-02 10:39 ` Ludovic Courtès
2023-12-02 13:10 ` Simon Tournier
2023-12-02 13:11 ` [bug#66961] [PATCH v4] " Simon Tournier
2023-12-22 16:19 ` Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=adfd8ba3e41841d280b873ed4199607b0bcfae52.1701289675.git.zimon.toutoune@gmail.com \
--to=zimon.toutoune@gmail.com \
--cc=66961@debbugs.gnu.org \
--cc=dev@jpoiret.xyz \
--cc=guix@cbaines.net \
--cc=ludo@gnu.org \
--cc=me@tobias.gr \
--cc=othacehe@gnu.org \
--cc=rekado@elephly.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).