From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: [PATCH] scripts: hash: Add --git option. WIP Date: Fri, 24 Nov 2017 14:34:54 +0100 Message-ID: <87y3mvby0x.fsf@gnu.org> References: <87k1yhhcon.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46401) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eIE8C-0004y2-Oj for guix-devel@gnu.org; Fri, 24 Nov 2017 08:35:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eIE89-00055Z-H0 for guix-devel@gnu.org; Fri, 24 Nov 2017 08:35:00 -0500 In-Reply-To: <87k1yhhcon.fsf@gnu.org> (Jan Nieuwenhuizen's message of "Thu, 23 Nov 2017 04:54:48 +0100") 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: Jan Nieuwenhuizen Cc: guix-devel@gnu.org Hello, Jan Nieuwenhuizen skribis: > Attached is a patch to get the hash of a git archive without having to > clean the tree or do a clean checkout. > > Using > > guix hash -gr . > > procudes the same hash as doing something like > > git clone . tmp && guix hash -rx tmp && rm -r tmp Very useful! > I marked it as WIP because while it is already "handy" as it is, I > consider adding a commit argument and imply --recursive, like so > > guix hash --git HEAD > guix hash --git v0.13 > > WDYT? This can always be added in a later patch. > From cfc9e557db6fe6c9aece68cfc5153ec9481a45a4 Mon Sep 17 00:00:00 2001 > From: Jan Nieuwenhuizen > Date: Thu, 23 Nov 2017 04:30:13 +0100 > Subject: [PATCH] scripts: hash: Add --git option. WIP > > Using > > guix hash -gr . > > procudes the same hash as doing something like > > git clone . tmp && guix hash -rx tmp && rm -r tmp > > * guix/git.scm (git-ls-files): New function. > * guix/scripts/hash.scm (%options, show-help): Add `--git'. > (guix-hash)[git-file?]: New function. [...] > +(define (git-ls-files directory) What about =E2=80=98git-file-list=E2=80=99 or =E2=80=98git-controlled-files= =E2=80=99 rather? With a docstring too. :-) > + (define (git-file? directory) > + (let* ((files (git-ls-files directory)) > + (directories (delete-duplicates (map dirname files))) > + (prefix (if (string-suffix? "/" directory) directory > + (string-append directory "/"))) > + (prefix-length (string-length prefix))) > + (lambda (file stat) > + (case (stat:type stat) > + ((directory) > + (member (string-drop file prefix-length) directories)) > + ((regular) > + (member (string-drop file prefix-length) files)) > + (else > + #f))))) This appears to duplicate =E2=80=98git-predicate=E2=80=99 from (guix git-do= wnload), which was carefully optimized for large trees by Chris. What about: 1. Rewrite =E2=80=98git-predicate=E2=80=99 to use the new =E2=80=98git-fi= le-list=E2=80=99 (currently is shells out =E2=80=98git=E2=80=99); 2. Moving =E2=80=98git-predicate=E2=80=99 to (guix git). ? I understand this is probably more than you were willing to do ;-), but it should be beneficial. > + (select? (cond > + ((assq-ref opts 'exclude-vcs?) > + (negate vcs-file?)) > + ((assq-ref opts 'git?) > + (git-file? (car args))) > + (else > + (const #t))))) I think we should use =E2=80=98match=E2=80=99 to gracefully handle any erro= rs: ((assq-ref opts 'git?) (match args ((file) (git-predicate file)) (_ (const #f)))) Thanks, Ludo=E2=80=99.