From patchwork Fri Dec 29 07:27:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13506352 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 830F0C8CE for ; Fri, 29 Dec 2023 07:27:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="p9odUuDu"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="gU1aEkHZ" Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id D2F475C0184; Fri, 29 Dec 2023 02:27:07 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Fri, 29 Dec 2023 02:27:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1703834827; x=1703921227; bh=/JPSnppaKi ZO3nXm9DEN+3Gc4HZEN8toGs9DO/HBAR4=; b=p9odUuDuUdLEsrDoyjuP1TC9xo 366G/D9QMapd3mP6ToTU15j9J7b32mNMQWe0K/L3pHNw/Fvrl+RYISgzKqcFbMZy IgemGF6ZZ9siHDI/ddt8DDxn0y3vH+TbKforiz6WbvPL886l36dHANhaaxUYTi/u W9mmDBGbLqohMFVpGg+AK4y/QhVgGPfxLA/Kqe9xrvYGQXxZ1nCcceNQrNW7K/Xi PfcSxcShOx2Fdq4+X8cKKSwIwalYkAf8V1NOtmFBu84OYON/Q283olKbNq4U0zgM oksaN4Tg+cAVG1fIy+pPa6XfI43jSUl1fkjuNhxyV86SNC/GLZbTl64+Vb+w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1703834827; x=1703921227; bh=/JPSnppaKiZO3nXm9DEN+3Gc4HZE N8toGs9DO/HBAR4=; b=gU1aEkHZMkQNnehU6TGE3HgKmFTVgcTh9FQbADm+If62 JrkCeMy/xMmmC4zlfftJsWHVmUDkHuac0Myd3hGfhcKrrTthSR9zgvgLfth0HXRa P1nGD9OHfjs4fpeBJTsV+1npndW0IGlvDnn3e8/I1665RKFV6TVtu/tS0mBmwLFo 8KB1uGVixrVen4Bo2HWjPAMhj4xf4Unq+zrWiB22KUE6Q+fza01FPZ9dfrqDkrok M/GjKOmQzT/xXG+7d5mlGKkF62Xb4IvzEk0JGOXPqTBlMU1lEf5wN+Yo2JwZtkf+ CONMG553Ok1WZvOIMk9+fIZ4wYhMTyBrSzaPOxGwKw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdefvddguddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 29 Dec 2023 02:27:06 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 02b14237 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 29 Dec 2023 07:24:50 +0000 (UTC) Date: Fri, 29 Dec 2023 08:27:04 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Karthik Nayak , Junio C Hamano , Eric Sunshine Subject: [PATCH v3 10/12] builtin/init: introduce `--ref-format=` value flag Message-ID: <25773e356063e5c109c238105c148b1112cc9672.1703833819.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Introduce a new `--ref-format` value flag for git-init(1) that allows the user to specify the ref format that is to be used for a newly initialized repository. Signed-off-by: Patrick Steinhardt --- Documentation/git-init.txt | 7 +++++++ builtin/init-db.c | 13 ++++++++++++- t/t0001-init.sh | 26 ++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Documentation/git-init.txt b/Documentation/git-init.txt index 6f0d2973bf..e8dc645bb5 100644 --- a/Documentation/git-init.txt +++ b/Documentation/git-init.txt @@ -11,6 +11,7 @@ SYNOPSIS [verse] 'git init' [-q | --quiet] [--bare] [--template=] [--separate-git-dir ] [--object-format=] + [--ref-format=] [-b | --initial-branch=] [--shared[=]] [] @@ -57,6 +58,12 @@ values are 'sha1' and (if enabled) 'sha256'. 'sha1' is the default. + include::object-format-disclaimer.txt[] +--ref-format=:: + +Specify the given ref storage format for the repository. The valid values are: ++ +include::ref-storage-format.txt[] + --template=:: Specify the directory from which templates will be used. (See the "TEMPLATE diff --git a/builtin/init-db.c b/builtin/init-db.c index b6e80feab6..a4f81e2af5 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -58,6 +58,7 @@ static int shared_callback(const struct option *opt, const char *arg, int unset) static const char *const init_db_usage[] = { N_("git init [-q | --quiet] [--bare] [--template=]\n" " [--separate-git-dir ] [--object-format=]\n" + " [--ref-format=]\n" " [-b | --initial-branch=]\n" " [--shared[=]] []"), NULL @@ -77,8 +78,10 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) const char *template_dir = NULL; unsigned int flags = 0; const char *object_format = NULL; + const char *ref_format = NULL; const char *initial_branch = NULL; int hash_algo = GIT_HASH_UNKNOWN; + unsigned int ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN; int init_shared_repository = -1; const struct option init_db_options[] = { OPT_STRING(0, "template", &template_dir, N_("template-directory"), @@ -96,6 +99,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) N_("override the name of the initial branch")), OPT_STRING(0, "object-format", &object_format, N_("hash"), N_("specify the hash algorithm to use")), + OPT_STRING(0, "ref-format", &ref_format, N_("format"), + N_("specify the reference format to use")), OPT_END() }; @@ -159,6 +164,12 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) die(_("unknown hash algorithm '%s'"), object_format); } + if (ref_format) { + ref_storage_format = ref_storage_format_by_name(ref_format); + if (ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN) + die(_("unknown ref storage format '%s'"), ref_format); + } + if (init_shared_repository != -1) set_shared_repository(init_shared_repository); @@ -237,6 +248,6 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) flags |= INIT_DB_EXIST_OK; return init_db(git_dir, real_git_dir, template_dir, hash_algo, - REF_STORAGE_FORMAT_UNKNOWN, initial_branch, + ref_storage_format, initial_branch, init_shared_repository, flags); } diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 30ce752cc1..b131d665db 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -576,6 +576,32 @@ test_expect_success 'init with GIT_DEFAULT_REF_FORMAT=garbage' ' test_cmp expect err ' +test_expect_success 'init with --ref-format=files' ' + test_when_finished "rm -rf refformat" && + git init --ref-format=files refformat && + echo files >expect && + git -C refformat rev-parse --show-ref-format >actual && + test_cmp expect actual +' + +test_expect_success 're-init with same format' ' + test_when_finished "rm -rf refformat" && + git init --ref-format=files refformat && + git init --ref-format=files refformat && + echo files >expect && + git -C refformat rev-parse --show-ref-format >actual && + test_cmp expect actual +' + +test_expect_success 'init with --ref-format=garbage' ' + test_when_finished "rm -rf refformat" && + cat >expect <<-EOF && + fatal: unknown ref storage format ${SQ}garbage${SQ} + EOF + test_must_fail git init --ref-format=garbage refformat 2>err && + test_cmp expect err +' + test_expect_success MINGW 'core.hidedotfiles = false' ' git config --global core.hidedotfiles false && rm -rf newdir &&