guix 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. Co-authored-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
parent
afa54a38b7
commit
392a4e1223
|
@ -4678,7 +4678,7 @@ The general syntax is:
|
||||||
guix hash @var{option} @var{file}
|
guix hash @var{option} @var{file}
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
@command{guix hash} has the following option:
|
@command{guix hash} has the following options:
|
||||||
|
|
||||||
@table @code
|
@table @code
|
||||||
|
|
||||||
|
@ -4706,6 +4706,11 @@ hash (@pxref{Invoking guix archive}).
|
||||||
@c FIXME: Replace xref above with xref to an ``Archive'' section when
|
@c FIXME: Replace xref above with xref to an ``Archive'' section when
|
||||||
@c it exists.
|
@c it exists.
|
||||||
|
|
||||||
|
@item --exclude-vcs
|
||||||
|
@itemx -x
|
||||||
|
When combined with @option{--recursive}, exclude version control system
|
||||||
|
directories (@file{.bzr}, @file{.git}, @file{.hg}, etc.)
|
||||||
|
|
||||||
@vindex git-fetch
|
@vindex git-fetch
|
||||||
As an example, here is how you would compute the hash of a Git checkout,
|
As an example, here is how you would compute the hash of a Git checkout,
|
||||||
which is useful when using the @code{git-fetch} method (@pxref{origin
|
which is useful when using the @code{git-fetch} method (@pxref{origin
|
||||||
|
@ -4714,8 +4719,7 @@ Reference}):
|
||||||
@example
|
@example
|
||||||
$ git clone http://example.org/foo.git
|
$ git clone http://example.org/foo.git
|
||||||
$ cd foo
|
$ cd foo
|
||||||
$ rm -rf .git
|
$ guix hash -rx .
|
||||||
$ guix hash -r .
|
|
||||||
@end example
|
@end example
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
;;; GNU Guix --- Functional package management for GNU
|
;;; 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 © 2013 Nikita Karetnikov <nikita@karetnikov.org>
|
||||||
|
;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of GNU Guix.
|
;;; This file is part of GNU Guix.
|
||||||
;;;
|
;;;
|
||||||
|
@ -48,6 +49,8 @@ Return the cryptographic hash of FILE.
|
||||||
|
|
||||||
Supported formats: 'nix-base32' (default), 'base32', and 'base16' ('hex'
|
Supported formats: 'nix-base32' (default), 'base32', and 'base16' ('hex'
|
||||||
and 'hexadecimal' can be used as well).\n"))
|
and 'hexadecimal' can be used as well).\n"))
|
||||||
|
(format #t (_ "
|
||||||
|
-x, --exclude-vcs exclude version control directories"))
|
||||||
(format #t (_ "
|
(format #t (_ "
|
||||||
-f, --format=FMT write the hash in the given format"))
|
-f, --format=FMT write the hash in the given format"))
|
||||||
(format #t (_ "
|
(format #t (_ "
|
||||||
|
@ -62,7 +65,10 @@ and 'hexadecimal' can be used as well).\n"))
|
||||||
|
|
||||||
(define %options
|
(define %options
|
||||||
;; Specification of the command-line 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)
|
(lambda (opt name arg result)
|
||||||
(define fmt-proc
|
(define fmt-proc
|
||||||
(match arg
|
(match arg
|
||||||
|
@ -81,7 +87,6 @@ and 'hexadecimal' can be used as well).\n"))
|
||||||
(option '(#\r "recursive") #f #f
|
(option '(#\r "recursive") #f #f
|
||||||
(lambda (opt name arg result)
|
(lambda (opt name arg result)
|
||||||
(alist-cons 'recursive? #t result)))
|
(alist-cons 'recursive? #t result)))
|
||||||
|
|
||||||
(option '(#\h "help") #f #f
|
(option '(#\h "help") #f #f
|
||||||
(lambda args
|
(lambda args
|
||||||
(show-help)
|
(show-help)
|
||||||
|
@ -107,13 +112,23 @@ and 'hexadecimal' can be used as well).\n"))
|
||||||
(alist-cons 'argument arg result))
|
(alist-cons 'argument arg result))
|
||||||
%default-options))
|
%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))
|
(let* ((opts (parse-options))
|
||||||
(args (filter-map (match-lambda
|
(args (filter-map (match-lambda
|
||||||
(('argument . value)
|
(('argument . value)
|
||||||
value)
|
value)
|
||||||
(_ #f))
|
(_ #f))
|
||||||
(reverse opts)))
|
(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)
|
(define (file-hash file)
|
||||||
;; Compute the hash of FILE.
|
;; Compute the hash of FILE.
|
||||||
|
@ -121,7 +136,7 @@ and 'hexadecimal' can be used as well).\n"))
|
||||||
(with-error-handling
|
(with-error-handling
|
||||||
(if (assoc-ref opts 'recursive?)
|
(if (assoc-ref opts 'recursive?)
|
||||||
(let-values (((port get-hash) (open-sha256-port)))
|
(let-values (((port get-hash) (open-sha256-port)))
|
||||||
(write-file file port)
|
(write-file file port #:select? select?)
|
||||||
(flush-output-port port)
|
(flush-output-port port)
|
||||||
(get-hash))
|
(get-hash))
|
||||||
(call-with-input-file file port-sha256))))
|
(call-with-input-file file port-sha256))))
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# GNU Guix --- Functional package management for GNU
|
# GNU Guix --- Functional package management for GNU
|
||||||
# Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org>
|
# Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org>
|
||||||
|
# Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
#
|
#
|
||||||
# This file is part of GNU Guix.
|
# This file is part of GNU Guix.
|
||||||
#
|
#
|
||||||
|
@ -46,3 +47,18 @@ then false; else true; fi
|
||||||
# the archive format doesn't support.
|
# the archive format doesn't support.
|
||||||
if guix hash -r /dev/null
|
if guix hash -r /dev/null
|
||||||
then false; else true; fi
|
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue