From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Nieuwenhuizen Subject: Re: [PATCH] scripts: hash: Add --exclude-.git option. Date: Tue, 06 Sep 2016 08:36:07 +0200 Message-ID: <87bn01y1pk.fsf@gnu.org> References: <87zinmybwv.fsf@gnu.org> <87pooit4jz.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50394) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bh9zp-0003ko-Qm for guix-devel@gnu.org; Tue, 06 Sep 2016 02:36:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bh9zl-0004on-KS for guix-devel@gnu.org; Tue, 06 Sep 2016 02:36:36 -0400 In-Reply-To: <87pooit4jz.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Mon, 05 Sep 2016 23:33:36 +0200") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Ludovic =?utf-8?Q?Court=C3=A8s?= Cc: guix-devel@gnu.org, Hartmut Goebel --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ludovic Court=C3=A8s writes: Hi! >> Added an -g/--exclude-.git option for guix hash. It is very specific: >> it skips toplevel .git directory. WDYT? > > Good idea! Thanks... > What about --exclude-vcs/-x? Tar uses that name, although with slightly > different semantics (info "(tar) exclude"). Yes, I like this even better than my 2nd --exclude=3DFILE patch. > Rather make the lambda a top-level procedure, like: > > (define (vcs-file? file stat) > (case (stat:type stat) > ((directory) > (member (basename file) '(".git" ".svn" "CVS" =E2=80=A6))) > (else > #f))) Nice! > Could you send an updated patch? Sure, attached. > Thank you for making our lives easier! :-) :-) Exactly, the mv .git ../dot-git ... drill was getting boring. Greetings, Jan --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0001-scripts-hash-Add-exclude-vcs-option.patch Content-Transfer-Encoding: quoted-printable >From 060f9123acd4c6771e976c5442361285f8c8bc89 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Tue, 6 Sep 2016 08:28:33 +0200 Subject: [PATCH] scripts: hash: Add --exclude-vcs option. * guix/scripts/hash.scm (show-help): Add help text for --exclude-vcs option. (%options): Add --exclude-vcs option. (guix-hash): Handle exclude-vcs option. * doc/guix.texi ("Invoking guix hash"): Update doc. * tests/guix-hash.sh: Add test. --- doc/guix.texi | 15 ++++++++++++++- guix/scripts/hash.scm | 25 ++++++++++++++++++++----- tests/guix-hash.sh | 16 ++++++++++++++++ 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 5330238..68a0707 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -4616,10 +4616,18 @@ The general syntax is: guix hash @var{option} @var{file} @end example =20 -@command{guix hash} has the following option: +@command{guix hash} has the following options: =20 @table @code =20 +@item --exclude-vcs +@itemx -x +Exclude version control system-directories (.bzr, .git, .hg, .svn, CVS) +when computing a recursive hash, e.g.: +@example +$ guix hash -r -x . +@end example + @item --format=3D@var{fmt} @itemx -f @var{fmt} Write the hash in the format specified by @var{fmt}. @@ -4655,6 +4663,11 @@ $ cd foo $ rm -rf .git $ guix hash -r . @end example +@noindent +or simply use the -x (--exclude-vcs) option +@example +$ guix hash -r -x . +@end example @end table =20 @node Invoking guix import diff --git a/guix/scripts/hash.scm b/guix/scripts/hash.scm index d440953..a57602a 100644 --- a/guix/scripts/hash.scm +++ b/guix/scripts/hash.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright =C2=A9 2012, 2013, 2014 Ludovic Court=C3=A8s +;;; Copyright =C2=A9 2012, 2013, 2014, 2016 Ludovic Court=C3=A8s ;;; Copyright =C2=A9 2013 Nikita Karetnikov +;;; Copyright =C2=A9 2016 Jan Nieuwenhuizen ;;; ;;; This file is part of GNU Guix. ;;; @@ -49,6 +50,8 @@ Return the cryptographic hash of FILE. Supported formats: 'nix-base32' (default), 'base32', and 'base16' ('hex' and 'hexadecimal' can be used as well).\n")) (format #t (_ " + -x, --exclude-vcs exclude version control directories")) + (format #t (_ " -f, --format=3DFMT write the hash in the given format")) (format #t (_ " -r, --recursive compute the hash on FILE recursively")) @@ -62,7 +65,10 @@ and 'hexadecimal' can be used as well).\n")) =20 (define %options ;; Specification of the command-line options. - (list (option '(#\f "format") #t #f + (list (option '(#\x "exclude-vcs") #f #f + (lambda (opt name arg result) + (alist-cons 'exclude-vcs? #t result))) + (option '(#\f "format") #t #f (lambda (opt name arg result) (define fmt-proc (match arg @@ -81,7 +87,6 @@ and 'hexadecimal' can be used as well).\n")) (option '(#\r "recursive") #f #f (lambda (opt name arg result) (alist-cons 'recursive? #t result))) - (option '(#\h "help") #f #f (lambda args (show-help) @@ -107,13 +112,23 @@ and 'hexadecimal' can be used as well).\n")) (alist-cons 'argument arg result)) %default-options)) =20 + (define (vcs-file? file stat) + (case (stat:type stat) + ((directory) + (member (basename file) '(".bzr" ".git" ".hg" ".svn" "CVS"))) + (else + #f))) + (let* ((opts (parse-options)) (args (filter-map (match-lambda (('argument . value) value) (_ #f)) (reverse opts))) - (fmt (assq-ref opts 'format))) + (fmt (assq-ref opts 'format)) + (select? (if (assq-ref opts 'exclude-vcs?) + (negate vcs-file?) + (const #t)))) =20 (define (file-hash file) ;; Compute the hash of FILE. @@ -121,7 +136,7 @@ and 'hexadecimal' can be used as well).\n")) (with-error-handling (if (assoc-ref opts 'recursive?) (let-values (((port get-hash) (open-sha256-port))) - (write-file file port) + (write-file file port #:select? select?) (flush-output-port port) (get-hash)) (call-with-input-file file port-sha256)))) diff --git a/tests/guix-hash.sh b/tests/guix-hash.sh index 23df01d..44213d5 100644 --- a/tests/guix-hash.sh +++ b/tests/guix-hash.sh @@ -1,5 +1,6 @@ # GNU Guix --- Functional package management for GNU # Copyright =C2=A9 2013, 2014 Ludovic Court=C3=A8s +# Copyright =C2=A9 2016 Jan Nieuwenhuizen # # This file is part of GNU Guix. # @@ -46,3 +47,18 @@ then false; else true; fi # the archive format doesn't support. if guix hash -r /dev/null then false; else true; fi + +# Adding a .git directory +mkdir "$tmpdir/.git" +touch "$tmpdir/.git/foo" + +# ...changes the hash +test `guix hash -r $tmpdir` =3D 0a50z04zyzf7pidwxv0nwbj82pgzbrhdy9562kncnv= kcfvb48m59 + +# ...but remains the same when using `-x' +test `guix hash -r $tmpdir -x` =3D 10k1lw41wyrjf9mxydi0is5nkpynlsvgslinics= 4ppir13g7d74p + +# Without '-r', this should fail. +if guix hash "$tmpdir" +then false; else true; fi + --=20 2.9.3 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable --=20 Jan Nieuwenhuizen | GNU LilyPond http://lilypond.org Freelance IT http://JoyofSource.com | Avatar=C2=AE http://AvatarAcademy.nl= =20=20 --=-=-=--