🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #4217

[PATCH v2 1/5] builtin/multi-pack-index: resolve default object directory lazily

#4217
From: Justin Tobler
Date: Tue, 01 Dec 2026 18:16
111 lines
14451 bytes
The object directory used by git-multi-pack-index(1) defaults to the
path of the primary object database source. This default is set eagerly
in `cmd_multi_pack_index()` before any options are parsed, and again
when "--no-object-dir" is given. Both cases access `the_repository` to
do so, and the eager initialization additionally has to guard against
the repository not being set up.

In a subsequent commit, the remaining references to `the_repository` in
"builtin/multi-pack-index.c" are removed. In preparation for this
change, leave the object directory unset in both cases and lazily fall
back to the path of the primary source in `handle_object_dir_option()`,
where the repository is passed in explicitly. This also removes the
need for the defensive `NULL` checks guarding the eager initialization.

With the default handled lazily, the callback for "--object-dir=" is
only left to resolve the given path via `real_pathdup()`. This is
unnecessary though, as `odb_source_files_find_dir()` already resolves
the path itself when looking up the matching object directory. Replace
the callback with a plain `OPT_STRING()`, which also means that the
option value no longer has to be allocated and freed.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
 builtin/multi-pack-index.c | 38 +++++++++++---------------------------
 1 file changed, 11 insertions(+), 27 deletions(-)

diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index c48212290cf8..ba5f326dd6ef 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -1,6 +1,5 @@
 #define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
-#include "abspath.h"
 #include "config.h"
 #include "environment.h"
 #include "gettext.h"
@@ -64,7 +63,7 @@ static char const * const builtin_multi_pack_index_usage[] = {
 };
 
 static struct opts_multi_pack_index {
-	char *object_dir;
+	const char *object_dir;
 	const char *preferred_pack;
 	const char *incremental_base;
 	char *refs_snapshot;
@@ -73,33 +72,24 @@ static struct opts_multi_pack_index {
 	int stdin_packs;
 } opts;
 
-
-static int parse_object_dir(const struct option *opt, const char *arg,
-			    int unset)
-{
-	char **value = opt->value;
-	free(*value);
-	if (unset)
-		*value = xstrdup(the_repository->objects->source->path);
-	else
-		*value = real_pathdup(arg, 1);
-	return 0;
-}
-
 static struct odb_source_packed *handle_object_dir_option(struct repository *repo)
 {
-	struct odb_files_dir *dir = odb_source_files_find_dir(repo->objects, opts.object_dir);
+	const char *object_dir = opts.object_dir;
+	struct odb_files_dir *dir;
+
+	if (!object_dir)
+		object_dir = repo->objects->source->path;
+
+	dir = odb_source_files_find_dir(repo->objects, object_dir);
 	if (!dir)
 		die(_("object directory is not an alternate of the current repository: '%s'"),
-		    opts.object_dir);
+		    object_dir);
 	return dir->packed;
 }
 
 static struct option common_opts[] = {
-	OPT_CALLBACK(0, "object-dir", &opts.object_dir,
-	  N_("directory"),
-	  N_("object directory containing set of packfile and pack-index pairs"),
-	  parse_object_dir),
+	OPT_STRING(0, "object-dir", &opts.object_dir, N_("directory"),
+	  N_("object directory containing set of packfile and pack-index pairs")),
 	OPT_BIT(0, "progress", &opts.flags, N_("force progress reporting"),
 		MIDX_PROGRESS),
 	OPT_END(),
@@ -424,17 +414,11 @@ int cmd_multi_pack_index(int argc,
 
 	repo_config(the_repository, git_default_config, NULL);
 
-	if (the_repository &&
-	    the_repository->objects &&
-	    the_repository->objects->source)
-		opts.object_dir = xstrdup(the_repository->objects->source->path);
-
 	argc = parse_options(argc, argv, prefix, options,
 			     builtin_multi_pack_index_usage, 0);
 	FREE_AND_NULL(options);
 
 	res = fn(argc, argv, prefix, repo);
 
-	free(opts.object_dir);
 	return res;
 }
-- 
2.56.0
Technical Details
Message-ID: <3e6369b99ba39b135fc1b315dc0721d098968e13.1796147221.git.jltobler@gmail.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76814-linux-kernel-git=dewy.ru
References: <cover.1796147221.git.jltobler@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76814-linux-kernel-git=dewy.ru
From: jltobler@gmail.com (Justin Tobler)
Newsgroups: linux.kernel.git
Subject: [PATCH v2 1/5] builtin/multi-pack-index: resolve default object directory lazily
Date: Tue,  1 Dec 2026 12:16:12 -0600
Organization: Usenet Network
Message-ID: <3e6369b99ba39b135fc1b315dc0721d098968e13.1796147221.git.jltobler@gmail.com>
References: <cover.1796147221.git.jltobler@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1786903"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:JstyyFZ2wF/3kvIfYbbYddTO+lU= sha256:iKZDFy/RWoUM2jx6neL9wm6+RLui4VG0fH5YSzRaH9w=
	sha1:rSzI5HfkxrBalhpvLJXYY4557SQ= sha256:VAILM2ku8aoDfMxxD4r9UhXROyQ2y4gkhDJolnGQG9s=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id C3EAE11745B; Tue,  1 Dec 2026 21:20:11 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id ckgOspas_ONm;
	Tue,  1 Dec 2026 21:20:08 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=git+bounces-76814-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 34C0C11744F; Tue,  1 Dec 2026 21:19:57 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id A64352339D; Tue,  1 Dec 2026 18:19:55 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796149194;
	b=PtnCEa3W38tzbgFXSAFZ+QKuWQvh6rdOjHcYLLSoV6+1dJmbaIVB1Djt9iDD0ENuOuja
	 thfY+95Cn+C427doIWbz8TC6ajnno30NkDBduQNmRUTmqoTF8+G9EZAsrHq4IVfhN1h4r
	 dAD0VGYmPXLKRnwb5X7Bsxj0ZcCUGWKKq6QF9DCLs0BB0pQvTAzR6oSSpgzTEel7pznK9
	 Cncc/AS/rAtbFlNvBxCdi3qec+zXTFmEQDRrThH4vZ4EEw/1p69M85cICgcyS9P8lQjB/
	 Ry1oett4Htc37mRSbBpCDq3dEy+32k8Wuo1BKEPFwgup9x+iimyt6IUrWJABRXbPyBQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796149194;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
	 Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
	 References:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=ClhIpoL7K8bJ+wot87ip8XRGhm8L7CZ9GC6A7d8sZnc=;
	b=Hi8TwnWamofiwlRdl8FIFd/5kkBiSbZM/bh5G6eyRsqgT4kxdhS8uzyOGZN1fu0A8qFf
	 SEx2TcnWFtGZb7nmtLxNNOTxwbZNz2oB370h3lPKFHrx8X6hUbmLOdw26VdvsQ+Ys4gOG
	 WTJtg9/EFi0qMlmZOvjcrgxQla0YGQJiD5Ojidss9ASR33rFnyzK3SMbyBLTMlDWB5jS1
	 OF4g0crD/WC6peIiZNBH3BZ/iNlI/EtR5FY/XDCQgvHO1yaMpv2MlermOBPlbL6/aRv8i
	 nxATFMP1cmhjlicnFeqQzgKLcEMnuVFo0cHBDzFIDTaWXsPnw+32gZEHYaNZ0dafkpA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Mgu4vO+y;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 4F56B606A332;
	Tue,  1 Dec 2026 18:19:54 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Mgu4vO+y
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.52
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796149193;
	b=HwRjHk5+/xHc+adRRtuxiqPFkGX9ZiX9hAgyyTOul3fYHKqLJQCblQ8ZPGCpMctQJvpW
	 NU30HjjOKUrtynkgupc2pNo3Ez4mQ7pyQ5KwTrr5Lst1UJOej5M0CGvfpa+qftleTb/kH
	 2gM2rEkgq+76pKW+fJT1xHQKqtarldOREpom9uJxWpEJsRu5siFbgSLi3zCuN+WiP9lj8
	 z8ywu88AfKd8sbArKmAvdmRAmgmN/Apt7uaIOujn6SGhQ8Bavv6sZUQlq2PDqFVSLr0kk
	 N5OAW3SRl4rH15dmJu1R6hghf+KJbpeiOGWbcPmaUTMqdWq/ZonzQc6/YP7a4bREHTw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796149193;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=ClhIpoL7K8bJ+wot87ip8XRGhm8L7CZ9GC6A7d8sZnc=;
	b=Koq2bm9BdBnPNth0lQeesHYOOcDr6V1pnnG19xRqVByiSd507F+7UeupGJ7XfPCum3XQ
	 T+WEiSHfcz3P4+jt1oszBCyBLupwPV3HAjx7gsKyCgxHKkv4aYd6Z4vCzFAG0gTYQqnOs
	 7ZbVqkGUKKd3qGs4Byn2CRjS+z3XdNbZJIrQk1pybwW1NJl2bG3tQ0FcfanHftUqzcVKp
	 CLFbZvQf6p+PiWNJCDaHTLkWTECwV/1PPQRIuzaLqbMHrT1KCBGawAmDSFQL41XIjKQsD
	 SKtQjwXpE246xNJ+8b8ZnDkNNvDJUia2JYT1woQel6eEi+w3BfQ2meyGhfm4cNPFTmQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Mgu4vO+y;
	arc=none smtp.remote-ip=209.85.210.52
X-Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2736A606A333
	for <git@vger.kernel.org>; Tue,  1 Dec 2026 18:19:53 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2736A606A333
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-ot1-f52.google.com with SMTP id 46e09a7af769-86103aaac12so6891206a34.0
        for <git@vger.kernel.org>; Tue, 01 Dec 2026 10:19:52 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1796149192; x=1796753992; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=ClhIpoL7K8bJ+wot87ip8XRGhm8L7CZ9GC6A7d8sZnc=;
        b=Mgu4vO+yHjvA2jdDimFGIGJCEhktrsfowNXH18cEEW0yQZTeQxPSkdQQzkG5bZ4vcX
         5BFumscVcUh7txBuYAlK6H5LwF/9tJ4Ax66+JlNfWVwmDfURpW3DwcYeVxmPmiS0x0+o
         kSpCvd23kHzT3msTTnIgiBceXWjFJ0/v7lXEL619ZsBLgDkyPlVo4q1/D6nw+3fgNwlL
         +gg28XowBSns59Fk+/bnKc7Ae0IcoMX2ZZu3TpLJdeBhxCrVs3WsLSSUVD0LzRcE8iKw
         FhPrLaXqdE0dLpxcBnB1nTE1pdiwh4xIhQa4ENXaYVlyA6UAR6s8zI452Dvq++Wy4aqZ
         lHhA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1796149192; x=1796753992;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
         :to:cc:subject:date:message-id:reply-to:content-type;
        bh=ClhIpoL7K8bJ+wot87ip8XRGhm8L7CZ9GC6A7d8sZnc=;
        b=EGJ8KP/ghnXYnSjAB2W1G3bMfFpEJ60BenOQFzwrbaV8vzi2zzsVh0cLhmEDFrNHvr
         udlaXbVReWOUawGXja8Glvce/YYinz3EQ5ZrbDD9Otjjf5OKsZSpx1NqwxNpluElT0tj
         7wgoc3wyYAEoWFDJii/h/x3XXzl0SjeiC1mGVklkEIpFTF2YhDmEk4XIo2ZauqLfH35f
         9gbMSGG2ohlOujBPXJSdNTztTT51N7YNwLDbLD6C9ZXWFwOQML0klC7HbkExDN9USktY
         dJcH7D48XSK9x+z/c7Wkwx9aDFEPT464NBIjDvPG/kVxJZ9gmYVRxUxzmxqWBEl5Uv4A
         RilQ==
X-Gm-Message-State: APuU4Z/WrxX5XG31RBNUfPaECFudYKhTvr6u9kDz72854WBlebpH9ZFI
	IdEG5QamP5ArAcBxTUjM/x9ckHyY4mt4C1Rg3eQiI9n42tjn1M0LdoZ4Fog8Dw==
X-Gm-Gg: AZFdTZfUMN6hwUyyY7UiV+CDaCFVU0vYR/+zk0SiUY/lmFll2D3d3Y+flkIhW00+DZ6
	IokSYY9yq+k3Fb+6zy+nwrVYYwIM/nb14vt1khgj/jhgscbtvvl9ZbY9oo6gNEfgHxK4/tx7h9t
	kXcgI4NkXI8eJHX80bi7+ZLtUqucz+g+Pdom/XgVVLqg7N3zAz4e41BMujewVj44EYx70VHiFp3
	qxusQmfJFBNa1Io8XRL/W8oIbGqHdg0vJDNTgqP5kEu6fPfqU8MZl2BoTBfPMT6KVx0va6eE8sF
	v5lzEbnL0LTNPnFr2PJg5PkfRWhUrPVEs/Sm2v1UccsCDOULqE0khdvarOPSrAKDMCUHnfq3x0O
	onpRsHm/jPDGfqh9/HunHYzpKHXYEL9m+o/zIVM5sCJqOuBOi6tDZqOPTmaIJtUe0NzHSk+wIBI
	ObxSzZgUO2GiBxY8J8pyX+b+z1YInAlAla6PoHkydY1rVn1T/Uz5bH4h3hlNosLdVuqcWtFFI/K
	l02JYM+TF1AFea2MfNRRNnjY++0McPrXSakd8D3krE/OcWsHL0wQgNB/4kspvtMHSlWGY4//nHE
	YzOD2RygPV2C9rAZpeetp0F/sHcazYb+HL8Uf5uvjq3S7GXMj5ZfKLr9MrLIs4AoS0WBfuXj/oo
	N0mbbCxuwTaU2
X-Received: by 2002:a05:6830:4c0b:b0:839:c62a:1661 with SMTP id 46e09a7af769-863091a9a86mr28586595a34.7.1796149192078;
        Tue, 01 Dec 2026 10:19:52 -0800 (PST)
X-Received: from jtobler--20250820-SHC54.localdomain ([136.51.44.64])
        by smtp.gmail.com with ESMTPSA id 46e09a7af769-863607d0f48sm16701271a34.7.2026.12.01.10.19.51
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Tue, 01 Dec 2026 10:19:51 -0800 (PST)
X-Cc: ps@pks.im,
	Justin Tobler <jltobler@gmail.com>
X-Mailer: git-send-email 2.56.0
X-In-Reply-To: <cover.1796147221.git.jltobler@gmail.com>
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list