diff mbox

scripts: hash: Add --exclude-.git option.

Message ID 87zinmybwv.fsf@gnu.org
State New
Headers show

Commit Message

Jan Nieuwenhuizen Sept. 5, 2016, 8:43 a.m. UTC
Hi!

Added an -g/--exclude-.git option for guix hash.  It is very specific:
it skips toplevel .git directory.  WDYT?

Greetings,
Jan

Comments

Hartmut Goebel Sept. 5, 2016, 9:20 a.m. UTC | #1
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?
Vincent Legoll Sept. 5, 2016, 10:56 a.m. UTC | #2
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
Jan Nieuwenhuizen Sept. 5, 2016, 11:36 a.m. UTC | #3
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
Efraim Flashner Sept. 5, 2016, 8:20 p.m. UTC | #4
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.
Danny Milosavljevic Sept. 5, 2016, 8:49 p.m. UTC | #5
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?
Leo Famulari Sept. 5, 2016, 8:50 p.m. UTC | #6
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.
Leo Famulari Sept. 5, 2016, 8:52 p.m. UTC | #7
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.
Ludovic Courtès Sept. 5, 2016, 9:33 p.m. UTC | #8
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’.
Vincent Legoll Sept. 6, 2016, 6:48 a.m. UTC | #9
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)
Ludovic Courtès Sept. 6, 2016, 12:24 p.m. UTC | #10
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’.
diff mbox

Patch

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