* [PATCH] scripts: hash: Add --exclude-.git option. @ 2016-09-05 8:43 Jan Nieuwenhuizen 2016-09-05 9:20 ` Hartmut Goebel ` (2 more replies) 0 siblings, 3 replies; 16+ messages in thread From: Jan Nieuwenhuizen @ 2016-09-05 8:43 UTC (permalink / raw) To: guix-devel [-- Attachment #1: Type: text/plain, Size: 134 bytes --] Hi! Added an -g/--exclude-.git option for guix hash. It is very specific: it skips toplevel .git directory. WDYT? Greetings, Jan [-- Attachment #2: 0001-scripts-hash-Add-exclude-.git-option.patch --] [-- Type: text/x-patch, Size: 3623 bytes --] From 86a580840f21f858b757cb7f421b0ba1c169e09d Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen <janneke@gnu.org> Date: Mon, 5 Sep 2016 10:27:19 +0200 Subject: [PATCH] scripts: hash: Add --exclude-.git option. * guix/scripts/hash.scm (show-help): Add help text for --exclude-.git option. (%options): Add --exclude-.git option. (guix-hash): Handle exclude-.git option. * doc/guix.texi ("invoking guix hash"): Update doc. * tests/guix-hash.sh: Add test. --- doc/guix.texi | 11 ++++++++++- guix/scripts/hash.scm | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 5330238..3393a1f 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -4616,10 +4616,14 @@ The general syntax is: guix hash @var{option} @var{file} @end example -@command{guix hash} has the following option: +@command{guix hash} has the following options: @table @code +@item --exclude-.git +@itemx -g +Exclude the @var{.git} directory when computing a recursive hash. + @item --format=@var{fmt} @itemx -f @var{fmt} Write the hash in the format specified by @var{fmt}. @@ -4655,6 +4659,11 @@ $ cd foo $ rm -rf .git $ guix hash -r . @end example +@noindent +or simply use the -g (--exclude-.git) option +@example +$ guix hash -r -g . +@end example @end table @node Invoking guix import diff --git a/guix/scripts/hash.scm b/guix/scripts/hash.scm index d440953..2933011 100644 --- a/guix/scripts/hash.scm +++ b/guix/scripts/hash.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2012, 2013, 2014 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org> +;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org> ;;; ;;; This file is part of GNU Guix. ;;; @@ -51,6 +52,8 @@ and 'hexadecimal' can be used as well).\n")) (format #t (_ " -f, --format=FMT write the hash in the given format")) (format #t (_ " + -g, --exclude-.git exclude .git directory")) + (format #t (_ " -r, --recursive compute the hash on FILE recursively")) (newline) (display (_ " @@ -78,6 +81,10 @@ and 'hexadecimal' can be used as well).\n")) (alist-cons 'format fmt-proc (alist-delete 'format result)))) + (option '(#\g "exclude-.git") #f #f + (lambda (opt name arg result) + (alist-cons 'exclude-.git #t result))) + (option '(#\r "recursive") #f #f (lambda (opt name arg result) (alist-cons 'recursive? #t result))) @@ -113,7 +120,10 @@ and 'hexadecimal' can be used as well).\n")) value) (_ #f)) (reverse opts))) - (fmt (assq-ref opts 'format))) + (fmt (assq-ref opts 'format)) + (select? (if (assq-ref opts 'exclude-.git) + (lambda (f s) (not (string= f "./.git"))) + (const #t)))) (define (file-hash file) ;; Compute the hash of FILE. @@ -121,7 +131,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)))) -- 2.9.3 [-- Attachment #3: Type: text/plain, Size: 154 bytes --] -- Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.nl ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH] scripts: hash: Add --exclude-.git option. 2016-09-05 8:43 [PATCH] scripts: hash: Add --exclude-.git option Jan Nieuwenhuizen @ 2016-09-05 9:20 ` Hartmut Goebel 2016-09-05 10:56 ` Vincent Legoll 2016-09-05 20:49 ` Danny Milosavljevic 2016-09-05 21:33 ` Ludovic Courtès 2 siblings, 1 reply; 16+ messages in thread From: Hartmut Goebel @ 2016-09-05 9:20 UTC (permalink / raw) To: guix-devel [-- Attachment #1.1: Type: text/plain, Size: 631 bytes --] Am 05.09.2016 um 10:43 schrieb Jan Nieuwenhuizen: > Added an -g/--exclude-.git option for guix hash. It is very specific: > it skips toplevel .git directory. WDYT? +1. What about make i the default? -- Schönen Gruß Hartmut Goebel Dipl.-Informatiker (univ), CISSP, CSSLP, ISO 27001 Lead Implementer Information Security Management, Security Governance, Secure Software Development Goebel Consult, Landshut http://www.goebel-consult.de Blog: http://www.goebel-consult.de/blog/filmgesprach-zu-201ecitizenfour201c-in-herrsching Kolumne: http://www.cissp-gefluester.de/2010-01-hinterturen-allen-ortes [-- Attachment #1.2: Type: text/html, Size: 1766 bytes --] [-- Attachment #2: S/MIME Cryptographic Signature --] [-- Type: application/pkcs7-signature, Size: 2430 bytes --] ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] scripts: hash: Add --exclude-.git option. 2016-09-05 9:20 ` Hartmut Goebel @ 2016-09-05 10:56 ` Vincent Legoll 2016-09-05 11:36 ` Jan Nieuwenhuizen 0 siblings, 1 reply; 16+ messages in thread From: Vincent Legoll @ 2016-09-05 10:56 UTC (permalink / raw) To: Hartmut Goebel; +Cc: guix-devel Hello, here are my 2 cts On Mon, Sep 5, 2016 at 11:20 AM, Hartmut Goebel <h.goebel@goebel-consult.de> wrote: > Am 05.09.2016 um 10:43 schrieb Jan Nieuwenhuizen: > > Added an -g/--exclude-.git option for guix hash. It is very specific: > it skips toplevel .git directory. WDYT? I'd rather name it "--exclude-git" or something less strange than --exclude-.git, even --exclude-dot-git... > +1. > > What about make i the default? OK with defaulting -- Vincent Legoll ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] scripts: hash: Add --exclude-.git option. 2016-09-05 10:56 ` Vincent Legoll @ 2016-09-05 11:36 ` Jan Nieuwenhuizen 2016-09-05 20:20 ` Efraim Flashner 2016-09-05 20:50 ` Leo Famulari 0 siblings, 2 replies; 16+ messages in thread From: Jan Nieuwenhuizen @ 2016-09-05 11:36 UTC (permalink / raw) To: Vincent Legoll; +Cc: guix-devel, Hartmut Goebel Vincent Legoll writes: >> Added an -g/--exclude-.git option for guix hash. It is very specific: >> it skips toplevel .git directory. WDYT? > > I'd rather name it "--exclude-git" or something less strange than > --exclude-.git, > even --exclude-dot-git... >> What about make i the default? > > OK with defaulting Drop the option altogether, or make it --include-git? Greetings, Jan -- Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.nl ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] scripts: hash: Add --exclude-.git option. 2016-09-05 11:36 ` Jan Nieuwenhuizen @ 2016-09-05 20:20 ` Efraim Flashner 2016-09-05 21:04 ` Jan Nieuwenhuizen 2016-09-05 20:50 ` Leo Famulari 1 sibling, 1 reply; 16+ messages in thread From: Efraim Flashner @ 2016-09-05 20:20 UTC (permalink / raw) To: Jan Nieuwenhuizen; +Cc: guix-devel, Hartmut Goebel [-- Attachment #1: Type: text/plain, Size: 853 bytes --] On Mon, Sep 05, 2016 at 01:36:43PM +0200, Jan Nieuwenhuizen wrote: > Vincent Legoll writes: > > >> Added an -g/--exclude-.git option for guix hash. It is very specific: > >> it skips toplevel .git directory. WDYT? > > > > I'd rather name it "--exclude-git" or something less strange than > > --exclude-.git, > > even --exclude-dot-git... > > >> What about make i the default? > > > > OK with defaulting > > Drop the option altogether, or make it --include-git? > > Greetings, > Jan > Can this be generalized? `grep \\-download\) gnu/packages/*scm' shows also svn-download, cvs-download and a lone hg-download. -- Efraim Flashner <efraim@flashner.co.il> אפרים פלשנר GPG key = A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351 Confidentiality cannot be guaranteed on emails sent or received unencrypted [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 819 bytes --] ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] scripts: hash: Add --exclude-.git option. 2016-09-05 20:20 ` Efraim Flashner @ 2016-09-05 21:04 ` Jan Nieuwenhuizen 2016-09-05 21:14 ` Leo Famulari 0 siblings, 1 reply; 16+ messages in thread From: Jan Nieuwenhuizen @ 2016-09-05 21:04 UTC (permalink / raw) To: Efraim Flashner; +Cc: guix-devel, Hartmut Goebel [-- Attachment #1: Type: text/plain, Size: 287 bytes --] Efraim Flashner writes: > Can this be generalized? `grep \\-download\) gnu/packages/*scm' shows also > svn-download, cvs-download and a lone hg-download. Okay. What about simply having non-default --exclude=FILE See attached. (Missing test included this time). Greetings, Jan [-- Attachment #2: 0001-scripts-hash-Add-exclude-option.patch --] [-- Type: text/x-patch, Size: 5294 bytes --] From ae738ad845f6d9e7576c42c53db6f7036b006e6c Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen <janneke@gnu.org> Date: Mon, 5 Sep 2016 10:27:19 +0200 Subject: [PATCH] scripts: hash: Add --exclude option. * guix/scripts/hash.scm (show-help): Add help text for --exclude option. (%options): Add --exclude option. (guix-hash): Handle exclude option. * doc/guix.texi ("invoking guix hash"): Update doc. * tests/guix-hash.sh: Add test. --- doc/guix.texi | 14 +++++++++++++- guix/scripts/hash.scm | 18 +++++++++++++++--- tests/guix-hash.sh | 17 +++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 5330238..b5c0a7d 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -4616,10 +4616,17 @@ The general syntax is: guix hash @var{option} @var{file} @end example -@command{guix hash} has the following option: +@command{guix hash} has the following options: @table @code +@item --exclude=@var{file} +@itemx -e @var{file} +Exclude @var{file} when computing a recursive hash, e.g.: +@example +$ guix hash -r -e .git . +@end example + @item --format=@var{fmt} @itemx -f @var{fmt} Write the hash in the format specified by @var{fmt}. @@ -4655,6 +4662,11 @@ $ cd foo $ rm -rf .git $ guix hash -r . @end example +@noindent +or simply use the -e (--exclude) option +@example +$ guix hash -r -e .git . +@end example @end table @node Invoking guix import diff --git a/guix/scripts/hash.scm b/guix/scripts/hash.scm index d440953..642e1c0 100644 --- a/guix/scripts/hash.scm +++ b/guix/scripts/hash.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2012, 2013, 2014 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org> +;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org> ;;; ;;; 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 (_ " + -e, --exclude=FILE exclude FILE when computing hash")) + (format #t (_ " -f, --format=FMT 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")) (define %options ;; Specification of the command-line options. - (list (option '(#\f "format") #t #f + (list (option '(#\e "exclude") #t #f + (lambda (opt name arg result) + (alist-cons 'exclude arg result))) + (option '(#\f "format") #t #f (lambda (opt name arg result) (define fmt-proc (match arg @@ -78,6 +84,7 @@ and 'hexadecimal' can be used as well).\n")) (alist-cons 'format fmt-proc (alist-delete 'format result)))) + (option '(#\r "recursive") #f #f (lambda (opt name arg result) (alist-cons 'recursive? #t result))) @@ -113,7 +120,12 @@ and 'hexadecimal' can be used as well).\n")) value) (_ #f)) (reverse opts))) - (fmt (assq-ref opts 'format))) + (fmt (assq-ref opts 'format)) + (exclude (assq-ref opts 'exclude)) + (select? (if exclude + (lambda (f s) + (not (string= f (string-append (car args) "/" exclude)))) + (const #t)))) (define (file-hash file) ;; Compute the hash of FILE. @@ -121,7 +133,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..b59939e 100644 --- a/tests/guix-hash.sh +++ b/tests/guix-hash.sh @@ -1,5 +1,6 @@ # GNU Guix --- Functional package management for GNU # Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org> +# Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org> # # This file is part of GNU Guix. # @@ -20,6 +21,7 @@ # Test the `guix hash' command-line utility. # +set -x guix hash --version tmpdir="guix-hash-$$" @@ -46,4 +48,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` = 0a50z04zyzf7pidwxv0nwbj82pgzbrhdy9562kncnvkcfvb48m59 + +# ...but remains the same when using `-e .git' +test `guix hash -r $tmpdir -e .git` = 10k1lw41wyrjf9mxydi0is5nkpynlsvgslinics4ppir13g7d74p + +# Without '-r', this should fail. +if guix hash "$tmpdir" +then false; else true; fi + -- 2.9.3 [-- Attachment #3: Type: text/plain, Size: 154 bytes --] -- Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.nl ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH] scripts: hash: Add --exclude-.git option. 2016-09-05 21:04 ` Jan Nieuwenhuizen @ 2016-09-05 21:14 ` Leo Famulari 0 siblings, 0 replies; 16+ messages in thread From: Leo Famulari @ 2016-09-05 21:14 UTC (permalink / raw) To: Jan Nieuwenhuizen; +Cc: guix-devel, Hartmut Goebel On Mon, Sep 05, 2016 at 11:04:11PM +0200, Jan Nieuwenhuizen wrote: > Efraim Flashner writes: > > > Can this be generalized? `grep \\-download\) gnu/packages/*scm' shows also > > svn-download, cvs-download and a lone hg-download. > > Okay. What about simply having non-default > > --exclude=FILE I like this way the best. Hashing source code checkouts is still rare enough in my experience that it makes sense to take a generalized approach like this, in my opinion. > > See attached. (Missing test included this time). > > Greetings, > Jan > > From ae738ad845f6d9e7576c42c53db6f7036b006e6c Mon Sep 17 00:00:00 2001 > From: Jan Nieuwenhuizen <janneke@gnu.org> > Date: Mon, 5 Sep 2016 10:27:19 +0200 > Subject: [PATCH] scripts: hash: Add --exclude option. > > * guix/scripts/hash.scm (show-help): Add help text for --exclude option. > (%options): Add --exclude option. > (guix-hash): Handle exclude option. > * doc/guix.texi ("invoking guix hash"): Update doc. > * tests/guix-hash.sh: Add test. > --- > doc/guix.texi | 14 +++++++++++++- > guix/scripts/hash.scm | 18 +++++++++++++++--- > tests/guix-hash.sh | 17 +++++++++++++++++ > 3 files changed, 45 insertions(+), 4 deletions(-) > > diff --git a/doc/guix.texi b/doc/guix.texi > index 5330238..b5c0a7d 100644 > --- a/doc/guix.texi > +++ b/doc/guix.texi > @@ -4616,10 +4616,17 @@ The general syntax is: > guix hash @var{option} @var{file} > @end example > > -@command{guix hash} has the following option: > +@command{guix hash} has the following options: > > @table @code > > +@item --exclude=@var{file} > +@itemx -e @var{file} > +Exclude @var{file} when computing a recursive hash, e.g.: > +@example > +$ guix hash -r -e .git . > +@end example > + > @item --format=@var{fmt} > @itemx -f @var{fmt} > Write the hash in the format specified by @var{fmt}. > @@ -4655,6 +4662,11 @@ $ cd foo > $ rm -rf .git > $ guix hash -r . > @end example > +@noindent > +or simply use the -e (--exclude) option > +@example > +$ guix hash -r -e .git . > +@end example > @end table > > @node Invoking guix import > diff --git a/guix/scripts/hash.scm b/guix/scripts/hash.scm > index d440953..642e1c0 100644 > --- a/guix/scripts/hash.scm > +++ b/guix/scripts/hash.scm > @@ -1,6 +1,7 @@ > ;;; GNU Guix --- Functional package management for GNU > ;;; Copyright © 2012, 2013, 2014 Ludovic Courtès <ludo@gnu.org> > ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org> > +;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org> > ;;; > ;;; 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 (_ " > + -e, --exclude=FILE exclude FILE when computing hash")) > + (format #t (_ " > -f, --format=FMT 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")) > > (define %options > ;; Specification of the command-line options. > - (list (option '(#\f "format") #t #f > + (list (option '(#\e "exclude") #t #f > + (lambda (opt name arg result) > + (alist-cons 'exclude arg result))) > + (option '(#\f "format") #t #f > (lambda (opt name arg result) > (define fmt-proc > (match arg > @@ -78,6 +84,7 @@ and 'hexadecimal' can be used as well).\n")) > > (alist-cons 'format fmt-proc > (alist-delete 'format result)))) > + > (option '(#\r "recursive") #f #f > (lambda (opt name arg result) > (alist-cons 'recursive? #t result))) > @@ -113,7 +120,12 @@ and 'hexadecimal' can be used as well).\n")) > value) > (_ #f)) > (reverse opts))) > - (fmt (assq-ref opts 'format))) > + (fmt (assq-ref opts 'format)) > + (exclude (assq-ref opts 'exclude)) > + (select? (if exclude > + (lambda (f s) > + (not (string= f (string-append (car args) "/" exclude)))) > + (const #t)))) > > (define (file-hash file) > ;; Compute the hash of FILE. > @@ -121,7 +133,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..b59939e 100644 > --- a/tests/guix-hash.sh > +++ b/tests/guix-hash.sh > @@ -1,5 +1,6 @@ > # GNU Guix --- Functional package management for GNU > # Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org> > +# Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org> > # > # This file is part of GNU Guix. > # > @@ -20,6 +21,7 @@ > # Test the `guix hash' command-line utility. > # > > +set -x > guix hash --version > > tmpdir="guix-hash-$$" > @@ -46,4 +48,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` = 0a50z04zyzf7pidwxv0nwbj82pgzbrhdy9562kncnvkcfvb48m59 > + > +# ...but remains the same when using `-e .git' > +test `guix hash -r $tmpdir -e .git` = 10k1lw41wyrjf9mxydi0is5nkpynlsvgslinics4ppir13g7d74p > + > +# Without '-r', this should fail. > +if guix hash "$tmpdir" > +then false; else true; fi > + > -- > 2.9.3 > > > -- > Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org > Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.nl ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] scripts: hash: Add --exclude-.git option. 2016-09-05 11:36 ` Jan Nieuwenhuizen 2016-09-05 20:20 ` Efraim Flashner @ 2016-09-05 20:50 ` Leo Famulari 1 sibling, 0 replies; 16+ messages in thread From: Leo Famulari @ 2016-09-05 20:50 UTC (permalink / raw) To: Jan Nieuwenhuizen; +Cc: guix-devel, Hartmut Goebel On Mon, Sep 05, 2016 at 01:36:43PM +0200, Jan Nieuwenhuizen wrote: > Vincent Legoll writes: > > >> Added an -g/--exclude-.git option for guix hash. It is very specific: > >> it skips toplevel .git directory. WDYT? > > > > I'd rather name it "--exclude-git" or something less strange than > > --exclude-.git, > > even --exclude-dot-git... > > >> What about make i the default? > > > > OK with defaulting > > Drop the option altogether, or make it --include-git? One way or another, we should have a way to `guix hash -r` .git directories if we really want to. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] scripts: hash: Add --exclude-.git option. 2016-09-05 8:43 [PATCH] scripts: hash: Add --exclude-.git option Jan Nieuwenhuizen 2016-09-05 9:20 ` Hartmut Goebel @ 2016-09-05 20:49 ` Danny Milosavljevic 2016-09-05 20:52 ` Leo Famulari 2016-09-05 21:33 ` Ludovic Courtès 2 siblings, 1 reply; 16+ messages in thread From: Danny Milosavljevic @ 2016-09-05 20:49 UTC (permalink / raw) To: Jan Nieuwenhuizen; +Cc: guix-devel Hi Jan, On Mon, 05 Sep 2016 10:43:28 +0200 Jan Nieuwenhuizen <janneke@gnu.org> wrote: > Added an -g/--exclude-.git option for guix hash. It is very specific: > it skips toplevel .git directory. Why? ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] scripts: hash: Add --exclude-.git option. 2016-09-05 20:49 ` Danny Milosavljevic @ 2016-09-05 20:52 ` Leo Famulari 0 siblings, 0 replies; 16+ messages in thread From: Leo Famulari @ 2016-09-05 20:52 UTC (permalink / raw) To: Danny Milosavljevic; +Cc: guix-devel On Mon, Sep 05, 2016 at 10:49:23PM +0200, Danny Milosavljevic wrote: > Hi Jan, > > On Mon, 05 Sep 2016 10:43:28 +0200 > Jan Nieuwenhuizen <janneke@gnu.org> wrote: > > Added an -g/--exclude-.git option for guix hash. It is very specific: > > it skips toplevel .git directory. > > Why? To calculate the hash of a source that is a Git repository, one clones the Git repository, checks out the desired commit, removes the '.git' metadata directory, and then runs `guix hash -r` on the remaining Git tree. If the Git repository is very large, it's tedious to make a copy or re-clone it in order to experiment with different commits. It would be easier if `guix hash` could skip the '.git' metadata in that case. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] scripts: hash: Add --exclude-.git option. 2016-09-05 8:43 [PATCH] scripts: hash: Add --exclude-.git option Jan Nieuwenhuizen 2016-09-05 9:20 ` Hartmut Goebel 2016-09-05 20:49 ` Danny Milosavljevic @ 2016-09-05 21:33 ` Ludovic Courtès 2016-09-06 6:36 ` Jan Nieuwenhuizen 2016-09-06 6:48 ` Vincent Legoll 2 siblings, 2 replies; 16+ messages in thread From: Ludovic Courtès @ 2016-09-05 21:33 UTC (permalink / raw) To: Jan Nieuwenhuizen; +Cc: guix-devel Hello! Jan Nieuwenhuizen <janneke@gnu.org> skribis: > Added an -g/--exclude-.git option for guix hash. It is very specific: > it skips toplevel .git directory. WDYT? Good idea! > From 86a580840f21f858b757cb7f421b0ba1c169e09d Mon Sep 17 00:00:00 2001 > From: Jan Nieuwenhuizen <janneke@gnu.org> > Date: Mon, 5 Sep 2016 10:27:19 +0200 > Subject: [PATCH] scripts: hash: Add --exclude-.git option. > > * guix/scripts/hash.scm (show-help): Add help text for --exclude-.git option. > (%options): Add --exclude-.git option. > (guix-hash): Handle exclude-.git option. > * doc/guix.texi ("invoking guix hash"): Update doc. ^ Capital I. :-) > * tests/guix-hash.sh: Add test. > @table @code > > +@item --exclude-.git > +@itemx -g What about --exclude-vcs/-x? Tar uses that name, although with slightly different semantics (info "(tar) exclude"). > + (select? (if (assq-ref opts 'exclude-.git) > + (lambda (f s) (not (string= f "./.git"))) 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" …))) (else #f))) … and then: (if (assq-ref opts 'exclude-vcs?) (negate vcs-file?) (const #t)) Could you send an updated patch? Thank you for making our lives easier! :-) Ludo’. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] scripts: hash: Add --exclude-.git option. 2016-09-05 21:33 ` Ludovic Courtès @ 2016-09-06 6:36 ` Jan Nieuwenhuizen 2016-09-06 12:26 ` Ludovic Courtès 2016-09-07 10:02 ` Ludovic Courtès 2016-09-06 6:48 ` Vincent Legoll 1 sibling, 2 replies; 16+ messages in thread From: Jan Nieuwenhuizen @ 2016-09-06 6:36 UTC (permalink / raw) To: Ludovic Courtès; +Cc: guix-devel, Hartmut Goebel [-- Attachment #1: Type: text/plain, Size: 823 bytes --] Ludovic Courtès 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=FILE 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" …))) > (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 [-- Attachment #2: 0001-scripts-hash-Add-exclude-vcs-option.patch --] [-- Type: text/x-patch, Size: 5584 bytes --] From 060f9123acd4c6771e976c5442361285f8c8bc89 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen <janneke@gnu.org> 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 -@command{guix hash} has the following option: +@command{guix hash} has the following options: @table @code +@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=@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 @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 © 2012, 2013, 2014 Ludovic Courtès <ludo@gnu.org> +;;; Copyright © 2012, 2013, 2014, 2016 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org> +;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org> ;;; ;;; 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=FMT 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")) (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)) + (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)))) (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 © 2013, 2014 Ludovic Courtès <ludo@gnu.org> +# Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org> # # 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` = 0a50z04zyzf7pidwxv0nwbj82pgzbrhdy9562kncnvkcfvb48m59 + +# ...but remains the same when using `-x' +test `guix hash -r $tmpdir -x` = 10k1lw41wyrjf9mxydi0is5nkpynlsvgslinics4ppir13g7d74p + +# Without '-r', this should fail. +if guix hash "$tmpdir" +then false; else true; fi + -- 2.9.3 [-- Attachment #3: Type: text/plain, Size: 154 bytes --] -- Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.nl ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH] scripts: hash: Add --exclude-.git option. 2016-09-06 6:36 ` Jan Nieuwenhuizen @ 2016-09-06 12:26 ` Ludovic Courtès 2016-09-07 10:02 ` Ludovic Courtès 1 sibling, 0 replies; 16+ messages in thread From: Ludovic Courtès @ 2016-09-06 12:26 UTC (permalink / raw) To: Jan Nieuwenhuizen; +Cc: guix-devel, Hartmut Goebel Jan Nieuwenhuizen <janneke@gnu.org> skribis: >> 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=FILE patch. I prefer --exclude-vcs too because that’s the main use case, so it’s best to have a shortcut. > From 060f9123acd4c6771e976c5442361285f8c8bc89 Mon Sep 17 00:00:00 2001 > From: Jan Nieuwenhuizen <janneke@gnu.org> > 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. OK for me! If there are no objections, I’ll commit this one. Ludo’. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] scripts: hash: Add --exclude-.git option. 2016-09-06 6:36 ` Jan Nieuwenhuizen 2016-09-06 12:26 ` Ludovic Courtès @ 2016-09-07 10:02 ` Ludovic Courtès 1 sibling, 0 replies; 16+ messages in thread From: Ludovic Courtès @ 2016-09-07 10:02 UTC (permalink / raw) To: Jan Nieuwenhuizen; +Cc: guix-devel, Hartmut Goebel Jan Nieuwenhuizen <janneke@gnu.org> skribis: > From 060f9123acd4c6771e976c5442361285f8c8bc89 Mon Sep 17 00:00:00 2001 > From: Jan Nieuwenhuizen <janneke@gnu.org> > 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. Pushed as 392a4e122350367c4b4ac331db5ec28360c7f38c with minor edits to guix.texi, thanks! Ludo’. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] scripts: hash: Add --exclude-.git option. 2016-09-05 21:33 ` Ludovic Courtès 2016-09-06 6:36 ` Jan Nieuwenhuizen @ 2016-09-06 6:48 ` Vincent Legoll 2016-09-06 12:24 ` Ludovic Courtès 1 sibling, 1 reply; 16+ messages in thread From: Vincent Legoll @ 2016-09-06 6:48 UTC (permalink / raw) To: Ludovic Courtès; +Cc: guix-devel On Mon, Sep 5, 2016 at 11:33 PM, Ludovic Courtès <ludo@gnu.org> wrote: > Hello! > > Jan Nieuwenhuizen <janneke@gnu.org> skribis: > >> Added an -g/--exclude-.git option for guix hash. It is very specific: >> it skips toplevel .git directory. WDYT? > > Good idea! > >> From 86a580840f21f858b757cb7f421b0ba1c169e09d Mon Sep 17 00:00:00 2001 >> From: Jan Nieuwenhuizen <janneke@gnu.org> >> Date: Mon, 5 Sep 2016 10:27:19 +0200 >> Subject: [PATCH] scripts: hash: Add --exclude-.git option. >> >> * guix/scripts/hash.scm (show-help): Add help text for --exclude-.git option. >> (%options): Add --exclude-.git option. >> (guix-hash): Handle exclude-.git option. >> * doc/guix.texi ("invoking guix hash"): Update doc. > ^ > Capital I. :-) > >> * tests/guix-hash.sh: Add test. >> @table @code >> >> +@item --exclude-.git >> +@itemx -g > > What about --exclude-vcs/-x? Tar uses that name, although with slightly > different semantics (info "(tar) exclude"). > >> + (select? (if (assq-ref opts 'exclude-.git) >> + (lambda (f s) (not (string= f "./.git"))) > > 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" …))) Could this not come from each vcs package ? i.e. each vcs package defines a vcs-dir which get put together in a global %vcs-dirs variable that is used here ? I ask because that's how I did it in meld (which I'll try to package for guix) in a distant past... WDYT, overdesigned ? I also like the generic proposal from Efraim (--exclude/-x) -- Vincent Legoll ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] scripts: hash: Add --exclude-.git option. 2016-09-06 6:48 ` Vincent Legoll @ 2016-09-06 12:24 ` Ludovic Courtès 0 siblings, 0 replies; 16+ messages in thread From: Ludovic Courtès @ 2016-09-06 12:24 UTC (permalink / raw) To: Vincent Legoll; +Cc: guix-devel Vincent Legoll <vincent.legoll@gmail.com> skribis: > On Mon, Sep 5, 2016 at 11:33 PM, Ludovic Courtès <ludo@gnu.org> wrote: >> Hello! >> >> Jan Nieuwenhuizen <janneke@gnu.org> skribis: >> >>> Added an -g/--exclude-.git option for guix hash. It is very specific: >>> it skips toplevel .git directory. WDYT? >> >> Good idea! >> >>> From 86a580840f21f858b757cb7f421b0ba1c169e09d Mon Sep 17 00:00:00 2001 >>> From: Jan Nieuwenhuizen <janneke@gnu.org> >>> Date: Mon, 5 Sep 2016 10:27:19 +0200 >>> Subject: [PATCH] scripts: hash: Add --exclude-.git option. >>> >>> * guix/scripts/hash.scm (show-help): Add help text for --exclude-.git option. >>> (%options): Add --exclude-.git option. >>> (guix-hash): Handle exclude-.git option. >>> * doc/guix.texi ("invoking guix hash"): Update doc. >> ^ >> Capital I. :-) >> >>> * tests/guix-hash.sh: Add test. >>> @table @code >>> >>> +@item --exclude-.git >>> +@itemx -g >> >> What about --exclude-vcs/-x? Tar uses that name, although with slightly >> different semantics (info "(tar) exclude"). >> >>> + (select? (if (assq-ref opts 'exclude-.git) >>> + (lambda (f s) (not (string= f "./.git"))) >> >> 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" …))) > > Could this not come from each vcs package ? > > i.e. each vcs package defines a vcs-dir which get put together in a global > %vcs-dirs variable that is used here ? > > I ask because that's how I did it in meld (which I'll try to package for guix) > in a distant past... > > WDYT, overdesigned ? Respectfully, I think so. :-) Ludo’. ^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2016-09-07 10:02 UTC | newest] Thread overview: 16+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-09-05 8:43 [PATCH] scripts: hash: Add --exclude-.git option Jan Nieuwenhuizen 2016-09-05 9:20 ` Hartmut Goebel 2016-09-05 10:56 ` Vincent Legoll 2016-09-05 11:36 ` Jan Nieuwenhuizen 2016-09-05 20:20 ` Efraim Flashner 2016-09-05 21:04 ` Jan Nieuwenhuizen 2016-09-05 21:14 ` Leo Famulari 2016-09-05 20:50 ` Leo Famulari 2016-09-05 20:49 ` Danny Milosavljevic 2016-09-05 20:52 ` Leo Famulari 2016-09-05 21:33 ` Ludovic Courtès 2016-09-06 6:36 ` Jan Nieuwenhuizen 2016-09-06 12:26 ` Ludovic Courtès 2016-09-07 10:02 ` Ludovic Courtès 2016-09-06 6:48 ` Vincent Legoll 2016-09-06 12:24 ` Ludovic Courtès
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/guix.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.