all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [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

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.