From patchwork Mon May 25 19:59:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 11569357 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2C9DC912 for ; Mon, 25 May 2020 20:00:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 15D8E2075F for ; Mon, 25 May 2020 20:00:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (3072-bit key) header.d=crustytoothpaste.net header.i=@crustytoothpaste.net header.b="DObXe0jb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390479AbgEYUAF (ORCPT ); Mon, 25 May 2020 16:00:05 -0400 Received: from injection.crustytoothpaste.net ([192.241.140.119]:38728 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390446AbgEYT77 (ORCPT ); Mon, 25 May 2020 15:59:59 -0400 Received: from camp.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:b610:a2f0:36c1:12e3]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id DF99960D17; Mon, 25 May 2020 19:59:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1590436798; bh=wSBvyjey21gbVX/7xAGCthcffF4q4jyfM63IKoHZXnw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=DObXe0jbWyKrbFQkyydgII4x9GcinnMkjw/eQ5UeXiTiwohHQgdDdmLAVlPkzNiNB fUKdvP2uw6/7glVWHcpt2mF0ulCvPd7YQjbEkosjD+op7gigA0Cac20pWgeWvZtkRR DgTn/8zXPDBISfv1diq3Lm1a27NYnSIFusGk6pTr7hSjisbtCugy909lftqXiLWo/8 7IWqhsIV877/WbWguXgTQlzcKfzV9gz6DjMY5f5LjNcuxCiWTlXXwneSbIWrgjVGNg H7QUBq0Mu2xqPi78A+hgmgp0rEaFSvTyMSGGEHZ+ctFOFyRYS3zpm0TIcVhzxPTHyk w+cIuKX+tTcnWiPzybf0qYw9/KJsAx1Nrc7Ti0js0EsPSPtxzeV2H2TI5oM8Cxp7Sa VbOY1U4qheuGHNVh09rnYb9LplF71kHh0oVRVVquDHp8IkB1vY3pT+wsjGV9INbHM4 g8a6HFe/mZlqrQv9Dsmov3VNUvrYb5+65XPaw6JGXfat50fntx4 From: "brian m. carlson" To: Cc: =?utf-8?q?Martin_=C3=85gren?= Subject: [PATCH v2 35/44] builtin/index-pack: add option to specify hash algorithm Date: Mon, 25 May 2020 19:59:21 +0000 Message-Id: <20200525195930.309665-36-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.27.0.rc0.183.gde8f92d652 In-Reply-To: <20200525195930.309665-1-sandals@crustytoothpaste.net> References: <20200513005424.81369-1-sandals@crustytoothpaste.net> <20200525195930.309665-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org git index-pack is usually run in a repository, but need not be. Since packs don't contains information on the algorithm in use, instead relying on context, add an option to index-pack to tell it which one we're using in case someone runs it outside of a repository. Since using --stdin necessarily implies a repository, don't allow specifying an object format if it's provided to prevent users from passing an option that won't work. Add documentation for this option. Signed-off-by: brian m. carlson --- Documentation/git-index-pack.txt | 8 ++++++++ builtin/index-pack.c | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/Documentation/git-index-pack.txt b/Documentation/git-index-pack.txt index d5b7560bfe..9316d9a80b 100644 --- a/Documentation/git-index-pack.txt +++ b/Documentation/git-index-pack.txt @@ -93,6 +93,14 @@ OPTIONS --max-input-size=:: Die, if the pack is larger than . +--object-format=:: + Specify the given object format (hash algorithm) for the pack. The valid + values are 'sha1' and (if enabled) 'sha256'. The default is the algorithm for + the current repository (set by `extensions.objectFormat`), or 'sha1' if no + value is set or outside a repository. ++ +This option cannot be used with --stdin. + NOTES ----- diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 7bea1fba52..f865666db9 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1667,6 +1667,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) unsigned char pack_hash[GIT_MAX_RAWSZ]; unsigned foreign_nr = 1; /* zero is a "good" value, assume bad */ int report_end_of_input = 0; + int hash_algo = 0; /* * index-pack never needs to fetch missing objects except when @@ -1760,6 +1761,11 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) die(_("bad %s"), arg); } else if (skip_prefix(arg, "--max-input-size=", &arg)) { max_input_size = strtoumax(arg, NULL, 10); + } else if (skip_prefix(arg, "--object-format=", &arg)) { + hash_algo = hash_algo_by_name(arg); + if (hash_algo == GIT_HASH_UNKNOWN) + die(_("unknown hash algorithm '%s'"), arg); + repo_set_hash_algo(the_repository, hash_algo); } else usage(index_pack_usage); continue; @@ -1776,6 +1782,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) die(_("--fix-thin cannot be used without --stdin")); if (from_stdin && !startup_info->have_repository) die(_("--stdin requires a git repository")); + if (from_stdin && hash_algo) + die(_("--object-format cannot be used with --stdin")); if (!index_name && pack_name) index_name = derive_filename(pack_name, "idx", &index_name_buf);