From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id wFAhKIqclWGMQAAAgWs5BA (envelope-from ) for ; Thu, 18 Nov 2021 01:21:30 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id eNjRI4qclWE1KQAAB5/wlQ (envelope-from ) for ; Thu, 18 Nov 2021 00:21:30 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 21D6DDF1C for ; Thu, 18 Nov 2021 01:21:30 +0100 (CET) Received: from localhost ([::1]:51720 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mnVBB-0004Ct-AW for larch@yhetil.org; Wed, 17 Nov 2021 19:21:29 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45196) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnVAm-0003gs-5b for guix-patches@gnu.org; Wed, 17 Nov 2021 19:21:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:50831) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mnVAl-00088d-0R for guix-patches@gnu.org; Wed, 17 Nov 2021 19:21:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mnVAk-00070a-8V for guix-patches@gnu.org; Wed, 17 Nov 2021 19:21:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51307] [PATCH v2 3/3] scripts: hash: Add git serializer. Resent-From: zimoun Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 18 Nov 2021 00:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51307 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 51307@debbugs.gnu.org Cc: ludo@gnu.org, zimoun Received: via spool by 51307-submit@debbugs.gnu.org id=B51307.163719484926878 (code B ref 51307); Thu, 18 Nov 2021 00:21:02 +0000 Received: (at 51307) by debbugs.gnu.org; 18 Nov 2021 00:20:49 +0000 Received: from localhost ([127.0.0.1]:34139 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mnVAX-0006zN-8Q for submit@debbugs.gnu.org; Wed, 17 Nov 2021 19:20:49 -0500 Received: from mail-wm1-f49.google.com ([209.85.128.49]:51171) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mnVAT-0006yl-0y for 51307@debbugs.gnu.org; Wed, 17 Nov 2021 19:20:46 -0500 Received: by mail-wm1-f49.google.com with SMTP id 133so3777508wme.0 for <51307@debbugs.gnu.org>; Wed, 17 Nov 2021 16:20:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SL/gIdANgdxZAgXsJxq4XvVCS8NHj/f/oZy9QdFOxNw=; b=PQjCP73Ed1W9i9OmbdPttpddetuhr3hpImdm2A7o8MzN/LvL9Kx0wFj2ZN4H2BlV8n QnWOvC8moio0UjXT9Uh/mEyLMHAkc1eiolb/nnEDEXuqstHoMcjrJwirWP7mfa+UCMx5 3f5LoyY57OTuBwd4k18Ja6YuUGe92BbXxsquZglXr+ZCN3AFYuG+aM3DJrztc8tN9VtL 6d8i+Er4jjki/HNgFJkPPeVFNmocy3YRvB9aCklUq2jOLMM8Rwa8HxJilV16lE0gCKOz KQF78MPcyNslR365vzeuEmqZgq0kDs8/TfgwPFJQwURJBzgjFVJ4+Y2zl17dTBGTGckQ YPKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SL/gIdANgdxZAgXsJxq4XvVCS8NHj/f/oZy9QdFOxNw=; b=TAVCI8fTSuMl7WPRsXysanLAUt40V9HcjxyZC4CFo1n2dj2Oph2aDrkQ9TqMuiH91g 4YYe1oH8QLdYowRt6Anc3Xvbegyh3CT8smZRsXLzum1xGTxO+p+qPnPXKaISuO0Tv/IS ir/jS3gHoN/9b3K1CSNWCam31Hd4hdk8dkyzqpQv1/ZYdcN8Egf/jMe4825I9NdrggIR TfZjCU2lQi+es3kVjTuJmW1/EF83DJZqL531oA4aZCVN1uxne92DJqDn1ttDj7lmwng/ 0hjRDqs4pisq/cOrpsa0hGq/fmouGDrr+k6OFRQ0gRxkQMv3V1351LAKLm12EPEoUbZd 9kcQ== X-Gm-Message-State: AOAM530g5dtHEbVFCCxr+p3jUdeaYzmmnEr7Cs7CL380lzyLmutlGwXz xk7EjSLkbdqhIAZaXDdXBkfsC98n0AU= X-Google-Smtp-Source: ABdhPJyiaxVZkZ386v+PAb71IJ0p3QaQNYqRIi+N+0flJxemc6NEVjRWT4CaSFp6TIq67JmYHR6UPQ== X-Received: by 2002:a1c:9a89:: with SMTP id c131mr4615594wme.80.1637194839356; Wed, 17 Nov 2021 16:20:39 -0800 (PST) Received: from localhost.localdomain ([193.48.40.117]) by smtp.gmail.com with ESMTPSA id y7sm1255927wrw.55.2021.11.17.16.20.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 16:20:39 -0800 (PST) From: zimoun Date: Thu, 18 Nov 2021 01:20:23 +0100 Message-Id: <20211118002023.3323307-4-zimon.toutoune@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211118002023.3323307-1-zimon.toutoune@gmail.com> References: <20211118002023.3323307-1-zimon.toutoune@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1637194890; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=6kNR1hC5EWmLt322nYH+wjebZvUFjB3jiO+5gc0WQoI=; b=mmLjKQu5ZOD6CZ8YSpp9arMBBV/i6PnY2k6o80OfgX/kvw8ZEmII2NWBqgmBqJArcxYawc M8VD7ybCbEdrKqAVv7l0tHR3LAaPjcC5EV6Hu8eBZUx24wNH3kf+0sO2wNIYQ8Fj8ipVWx oX7AdTKJxJ/jp90hFeRe8GRVjZp/gkSzDTsDHEuIGsbr70QG0a2E033fhVMQ0rvYSK0vIC ogS1/kZv7cvY0qc7gsvdVUYsH13c+NHFHDsFkx10OCbVNth+zgfkMjWr8zlEgyp2YHAUkE GXcPw5XkeJF+KqCKm9/URmiAtIv3HuxQkgLYaQz/0xdUbJXogvwXKMLgHLd3KA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1637194890; a=rsa-sha256; cv=none; b=Foo23ipGwdZ09WG+uGiqeRzrvL+Jqba7wIKU49z+1oKxzdi+l8kB3dnQcHCBQmzVkI6YnU O9eSjUyhwWsiASddYrhm1oOl7rJPijIsK+TmITUVCU7aD4igvrnWT26COo+hbGqAkOKfWX yyOEmr/0vm7hFnhpPRq6hmWnZTgptkmEPxLN7m0GZd6dLG79FMOKJjk8Nt9vJMIz7x3FTF eowbuY5ZZ7JpH/vU2Q/nG2SZqfrvfR2Vpt9VuNWAbfnkM4D3SLAZ+QAeKL+Mu05ulqMU3h ZdN/MSbYMYvkp2hkO43GOTXNJK6+vpEItdqFa5xcA9yBOb3QNElIRbokyy8rIA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=PQjCP73E; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -1.36 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=PQjCP73E; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 21D6DDF1C X-Spam-Score: -1.36 X-Migadu-Scanner: scn0.migadu.com X-TUID: zs2jEI4TT+0t * guix/scripts/hash.scm (git-hash): New procedure. (%options): Use it. * tests/guix-hash.sh: Test it. * doc/guix.texi: Update. --- doc/guix.texi | 4 +++- guix/scripts/hash.scm | 15 +++++++++++++++ tests/guix-hash.sh | 6 ++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/doc/guix.texi b/doc/guix.texi index 20041c20b7..af2e99903b 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -11638,7 +11638,7 @@ legacy alias for @var{type} sets to @code{nar}. @itemx -S Compute the hash on @var{file} using @var{type} serialization. -Supported types: @code{none} and @code{nar}. +Supported types: @code{none}, @code{nar} and @code{git}. When using @code{nar}, the hash is computed on an archive containing @var{file}, including its children if it is a directory. Some of the @@ -11649,6 +11649,8 @@ impact on the hash (@pxref{Invoking guix archive}). @c FIXME: Replace xref above with xref to an ``Archive'' section when @c it exists. +Using @code{git} serializes the file or directory as a Git tree. + @item --exclude-vcs @itemx -x When combined with @option{--recursive}, exclude version control system diff --git a/guix/scripts/hash.scm b/guix/scripts/hash.scm index d05ecb80ba..80581f2340 100644 --- a/guix/scripts/hash.scm +++ b/guix/scripts/hash.scm @@ -35,6 +35,8 @@ (define-module (guix scripts hash) #:use-module (srfi srfi-11) #:use-module (srfi srfi-26) #:use-module (srfi srfi-37) + #:use-module ((disarchive git-hash) #:select (git-hash-file + git-hash-directory)) #:export (guix-hash)) @@ -60,6 +62,17 @@ (define* (default-hash file #:optional (call-with-input-file file (cute port-hash algorithm <>))))) +(define* (git-hash file #:optional + (algorithm (assoc-ref %default-options 'hash-algorithm)) + select?) + (define directory? + (case (stat:type (stat file)) + ((directory) #t) + (else #f))) + (if directory? + (git-hash-directory file algorithm) + (git-hash-file file algorithm))) + ;;; ;;; Command-line options. @@ -138,6 +151,8 @@ (define serializer-proc default-hash) ("nar" nar-hash) + ("git" + git-hash) (x (leave (G_ "unsupported serializer type: ~a~%") arg)))) diff --git a/tests/guix-hash.sh b/tests/guix-hash.sh index cdcfac19bc..bb3973771f 100644 --- a/tests/guix-hash.sh +++ b/tests/guix-hash.sh @@ -34,6 +34,9 @@ test `guix hash -f base32 /dev/null` = 4oymiquy7qobjgx36tejs35zeqt24qpemsnzgtfes test `guix hash -H sha512 -f hex /dev/null` = cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e test `guix hash -H sha1 -f base64 /dev/null` = "2jmj7l5rSw0yVb/vlWAYkK/YBwk=" +# idem as `cat /dev/null | git hash-object --stdin` +test `guix hash -S git -H sha1 -f hex /dev/null` = e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 + ! guix hash -H abcd1234 /dev/null mkdir "$tmpdir" @@ -44,6 +47,7 @@ mkdir "$tmpdir/subdir" test `guix hash -S nar "$tmpdir"` = 10k1lw41wyrjf9mxydi0is5nkpynlsvgslinics4ppir13g7d74p test `guix hash -S nar "$tmpdir" -H sha512` = 301ra58c2vahczzxiyfin41mpyb0ljh4dh9zn3ijvwviaw1j40sfzw5skh9x945da88n3785ggifzig7acd6k72h0mpsc20m1f66m9n +test `guix hash -S git "$tmpdir" -H sha512` = 158b10d1bsdk4pm8ym9cg9ckfak1b0cgpw7365cl6s341ir380mh2f4ylicyh8khyrfnwq5cn9766d7m8fbfwwl94ndkv456v6a8knr # Deprecated --recursive option test `guix hash -r "$tmpdir" 2>/dev/null` = 10k1lw41wyrjf9mxydi0is5nkpynlsvgslinics4ppir13g7d74p @@ -62,9 +66,11 @@ touch "$tmpdir/.git/foo" # ...changes the hash test `guix hash -S nar $tmpdir` = 0a50z04zyzf7pidwxv0nwbj82pgzbrhdy9562kncnvkcfvb48m59 +test `guix hash -S git $tmpdir` = 0ghlpca9xaswa1ay1g55dknwd9q899mi3ahfr43pq083v8wisjc7 # ...but remains the same when using `-x' test `guix hash -S nar $tmpdir -x` = 10k1lw41wyrjf9mxydi0is5nkpynlsvgslinics4ppir13g7d74p +test `guix hash -S git $tmpdir -x` = 0ghlpca9xaswa1ay1g55dknwd9q899mi3ahfr43pq083v8wisjc7 # Without '-r', this should fail. ! guix hash "$tmpdir" -- 2.33.1