From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796149193; b=hNnvJavXL2Xa6VF9zwRBE8mQ1zrWg9wiMOv8bWrsNOVTJhrbdImm3zmWZKSQ98Lk0eE7 mEYRso9uwv+/dv0yUS6DJYYxp9gH/h5R1ejYAEhpSw3tSTD9knvFiWs0/uXhocu5j4HsH kxd1BOXsawMJ8DhzDxRWoFSyeP9gAI3Y4T7tSMvLG1sN/GPqlR4yXc2dsasZcplA36K/K y0xgtK+WeJywm3tQyAhFg6FNxW46HLfK2Ep2ojkGHSb9Iewm2hBzMgNd054HqC7Ac4jNp sQStlQ2iu0s6695aLL8MHn13xa92n84EII1329SZ9CM/N5k6TLf6itDld/WpYjARUHg== 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=zVYI6F1xcbmx2W/MNEffwSYQjteLY9fKdQsk5CAS+Zw=; b=oDffrm8v+gPfHT5j/uMTqnOiPnD6s/tYuclEhK+dS7ajzMwP0HJT4cte4yIIVPQ1cxcQ ja8CUUgXcuYqSs+i5UpSPZmTFdc+Jty/oK7xFO0UHZMihe8QtxRS3YjFDvUw8lqwoHfy0 8iUm4a0SfvxYBuoPK+eDXAQSOm6q0Ftg2/AcN2HBBi2+5kTmt61mnP7zWG1besiDCHNWs +YPHZK1ACZupjemZgqVdxAxZk+yMGBjtjTSxaFPFBZrRDNJU9l7eplc8QY/IyRVLWyXXx INwxqCKs4OOU/68W4eoY9hOMYu9TYcycvT/Dpo0Sk7YehXS7vA9ITdiQFYQSdcc+h/Q== 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=JvZMmuIA; arc=none smtp.remote-ip=209.85.161.42 Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) (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 C6313606A32E for ; Tue, 1 Dec 2026 18:19:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C6313606A32E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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=JvZMmuIA Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-71bb0f27587so1835949eaf.0 for ; Tue, 01 Dec 2026 10:19:52 -0800 (PST) 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=zVYI6F1xcbmx2W/MNEffwSYQjteLY9fKdQsk5CAS+Zw=; b=JvZMmuIAdt1IqxhcderRTLz4hzrm/wQBQQQLAxi2RZUhuM03Nh/bA4Tyc78o+qVjQL auKzZ4KlFI7jfqqdXyVmd67Y30xxGYuXra26LWtB+NIOWNz9Mnn4+gBj1rv4y4TFaYSH Crimi6lGp2te9Bi9QFGauqKS5sEFlZtE6Gj8N/NsyL1SvW5f1WVSE3MvEflpPs4w8FxE 9gf1tYD4weY7CSVCoThm/n4p8twWjzEJjTuds0zV/MpymFGUD1CCAWIVaIBzq833ZRy4 qXBVNH0NaLAltJ12OGqqmocXcDuB9KcYYhkZwTjV329PtLbNfcMzGcXfjjJSozym2GkI HK+Q== 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=zVYI6F1xcbmx2W/MNEffwSYQjteLY9fKdQsk5CAS+Zw=; b=VkdduNYkY/i3sIk1MQ5e3UKlvLe4RbMIe6ZtopIEVWeoR7gO9579UEo0hIOp5bZY3P qZh4J55fjd2THbyrKIGMQn6ZFJsAwe4KUx3HWEcVIBtCOI4exkt3CVpwXN0tKs9Jg/HY 6ReapmGm8sCpzf1wvXpDexLqKYZjV7KgyLaR9akkuebH4cco5uMKaSQra1A9zekwvxIu rbXbJpXseudrBVZsnVHSEfYbVs1/LRjay3jzgcpEupg1kGNZklFV4bPjjEQ3Gc6F6NPk DcLPJcpoOfUGE2NNyWr1F406AFoev8nzS833n9vNUSf26L5d7jdb1WnumLXRD1U5Jp2I naWQ== X-Gm-Message-State: APuU4Z++LQamN7l4WYsldzfPqf+OpuDewz5KJeOJ3AypT6OsfJOtdx7f yF7ux0Uth0wiIsvOGGFq/K2OC1b7rVFncrpcelK63yinZNQzWYOeIwIO/Gll7g== X-Gm-Gg: AZFdTZfDJEh1ZaIefrvHBZ0seV9A5gR7cVJWn/jwpx3VlYUKekTg1VDQfGz5v2r3BcA GDNe/eT13hOxqUi9zgdkSTKvvwQ7Aa/w/IKXfunjgL6/YVpfX+DsYXwF7SJ2xngdeL97qBldSeV PN3yLMqdYQWUDz8+s7K1h51XXVf59Dw6PzJLy6NZPNG8hY9rYmmME0cbxJUGKnt7w6lUHmCmN6Z c255rI8DOgvVvxOiCGLgPtoNsKx//ccZw/VfQXC0HXMrdgXzoCjzNGlzvJc+2Hw2TsScrkJByu0 dMRcdhv9QZRB36VctCLnd5sIwQzfJ37UsdiL+FU4P3HFnDpEzAtmLu772xf35lT03vlnWwSnzja T6uNGOTePWo6Xa7AKDCh8z5g5nvLM7Ht3S+U2MgBJZi8vIiWhsuQ2nIO301ldQygCsyjlTverVU +Uq87CY+TwQieAGGCmn3eqn2oeN2qTLb5jWStgtNbVX/qQjPTueJYVwLKp7NAkNboo0jy3ePGL2 ZdWRnOKwvPhyc8hTlVF1eIq+2ktRZCfFZt5I1sto5RUKKeqOshGYPxX2eA35IMQLoNreLfCsWYs Va9nFSQ5vWPUIY6vjJvusrh8t9F2eRMkpAp2cDAB5nPCePM5r3kxmjY5WqpFnSXoX5SAXtjJllz 1ExXXhDlKJ+fh X-Received: by 2002:a05:6820:1ca1:b0:71b:87ac:6ec8 with SMTP id 006d021491bc7-71b87ac7f4amr17544601eaf.6.1796149191390; Tue, 01 Dec 2026 10:19:51 -0800 (PST) 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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 10:19:50 -0800 (PST) From: Justin Tobler To: git@vger.kernel.org Cc: ps@pks.im, Justin Tobler Subject: [PATCH v2 0/5] builtin/multi-pack-index: remove global state Date: Tue, 1 Dec 2026 12:16:11 -0600 Message-ID: X-Mailer: git-send-email 2.56.0 In-Reply-To: References: X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Greetings, This series cleans up git-multi-pack-index(1) by getting rid of `the_repository` and the global state used to track its options. Each subcommand now parses its options into a local structure, and the common options are wired up via a macro instead of allocating a combined options array for every subcommand. The main reason the options are global is that "--object-dir=" and "--[no-]progress" are also accepted before the subcommand, where the top-level builtin parses them into the same global state used by the subcommands. Patch 3 drops support for giving these options before the subcommand, as every subcommand already accepts both of them. The "--[no-]progress" option was previously removed as a top-level option in 0394f8d002 (builtin/multi-pack-index.c: disable top-level --[no-]progress, 2021-09-20) and appears to have been inadvertently reintroduced via 6b8fb17490 (builtin/multi-pack-index.c: make '--progress' a common option, 2026-02-24). So I think it should be fine to drop. While "--object-dir=" has never previously been dropped, it appears to exist as a top-level option for the same historical reason, from when all options were parsed by the top-level builtin. Since the subcommands already parse the common options themselves, it should ideally be dropped as well. If we want to keep this top-level option though, an alternative could be to propagate the option argument to each subcommand. In this case, I don't think it's worth it, but happy to change if others feel differently. This series is built on top of 86e79b2795 (The 26th batch, 2026-11-29). Changes since V1: - "--object-dir=" is now parsed via `OPT_STRING()`, so the option value no longer needs to be allocated or freed. - Clarified in the message of patch 2 that the repository may still be `NULL` until `parse_options()` has been called. - The synopsis and usage strings now explicitly list the common options instead of using the `[]` placeholder. - The common options are now added at the front of each options array, so the order of the "-h" output stays the same. Thanks for the review, -Justin Justin Tobler (5): builtin/multi-pack-index: resolve default object directory lazily builtin/multi-pack-index: get rid of `the_repository` builtin/multi-pack-index: drop top-level options builtin/multi-pack-index: simplify how common options are wired up builtin/multi-pack-index: de-globalize options handling Documentation/git-multi-pack-index.adoc | 23 ++-- builtin/multi-pack-index.c | 165 +++++++++--------------- t/lib-midx.sh | 2 +- t/t5319-multi-pack-index.sh | 32 ++--- 4 files changed, 91 insertions(+), 131 deletions(-) Range-diff against v1: 1: c381afb0da59 ! 1: 3e6369b99ba3 builtin/multi-pack-index: resolve default object directory lazily @@ Commit message 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 ## builtin/multi-pack-index.c ## -@@ builtin/multi-pack-index.c: static int parse_object_dir(const struct option *opt, const char *arg, - char **value = opt->value; - free(*value); - if (unset) -- *value = xstrdup(the_repository->objects->source->path); -+ *value = NULL; - else - *value = real_pathdup(arg, 1); - return 0; -@@ builtin/multi-pack-index.c: static int parse_object_dir(const struct option *opt, const char *arg, +@@ + #define USE_THE_REPOSITORY_VARIABLE + #include "builtin.h" +-#include "abspath.h" + #include "config.h" + #include "environment.h" + #include "gettext.h" +@@ builtin/multi-pack-index.c: 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; +@@ builtin/multi-pack-index.c: 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); @@ builtin/multi-pack-index.c: static int parse_object_dir(const struct option *opt 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(), @@ builtin/multi-pack-index.c: int cmd_multi_pack_index(int argc, repo_config(the_repository, git_default_config, NULL); @@ builtin/multi-pack-index.c: int cmd_multi_pack_index(int argc, 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: 673945d65de3 ! 2: 28d7916f0a24 builtin/multi-pack-index: get rid of `the_repository` @@ Commit message builtin/multi-pack-index: get rid of `the_repository` There are a couple of remaining references to `the_repository` in - git-multi-pack-index(1). The command cannot run outside of a repository, - so these references can be trivially replaced with the repository - passed to the subcommands. + git-multi-pack-index(1). Replace them with the repository that is passed + to the builtin and its subcommands. + + Note that the repository may still be `NULL` until `parse_options()` has + been called. The only use of the repository before that point is + `repo_config()`, which handles a `NULL` repository. Signed-off-by: Justin Tobler @@ builtin/multi-pack-index.c @@ -#define USE_THE_REPOSITORY_VARIABLE #include "builtin.h" - #include "abspath.h" #include "config.h" + #include "environment.h" @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, const char **argv, opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE; 3: cc2876d6803f ! 3: 5fe18c5564c3 builtin/multi-pack-index: drop top-level options @@ Documentation/git-multi-pack-index.adoc: git-multi-pack-index - Write and verify -------- [verse] -'git multi-pack-index' [] write [--preferred-pack=] -+'git multi-pack-index' write [] [--preferred-pack=] - [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs] - [--refs-snapshot=] [--[no-]write-chain-file] - [--base=] +- [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs] +- [--refs-snapshot=] [--[no-]write-chain-file] +- [--base=] -'git multi-pack-index' [] compact [--[no-]incremental] -+'git multi-pack-index' compact [] [--[no-]incremental] - [--[no-]bitmap] [--base=] [--[no-]write-chain-file] - +- [--[no-]bitmap] [--base=] [--[no-]write-chain-file] +- -'git multi-pack-index' [] verify -'git multi-pack-index' [] expire -'git multi-pack-index' [] repack [--batch-size=] -+'git multi-pack-index' verify [] -+'git multi-pack-index' expire [] -+'git multi-pack-index' repack [] [--batch-size=] ++'git multi-pack-index' write [--object-dir=] [--[no-]progress] ++ [--preferred-pack=] [--[no-]bitmap] [--[no-]incremental] ++ [--[no-]stdin-packs] [--refs-snapshot=] ++ [--[no-]write-chain-file] [--base=] ++'git multi-pack-index' compact [--object-dir=] [--[no-]progress] ++ [--[no-]incremental] [--[no-]bitmap] [--base=] ++ [--[no-]write-chain-file] ++'git multi-pack-index' verify [--object-dir=] [--[no-]progress] ++'git multi-pack-index' expire [--object-dir=] [--[no-]progress] ++'git multi-pack-index' repack [--object-dir=] [--[no-]progress] ++ [--batch-size=] DESCRIPTION ----------- @@ builtin/multi-pack-index.c #define BUILTIN_MIDX_WRITE_USAGE \ - N_("git multi-pack-index [] write [--preferred-pack=]\n" \ -+ N_("git multi-pack-index write [] [--preferred-pack=]\n" \ - " [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs]\n" \ - " [--refs-snapshot=] [--[no-]write-chain-file]\n" \ - " [--base=]") +- " [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs]\n" \ +- " [--refs-snapshot=] [--[no-]write-chain-file]\n" \ +- " [--base=]") ++ N_("git multi-pack-index write [--object-dir=] [--[no-]progress]\n" \ ++ " [--preferred-pack=] [--[no-]bitmap] [--[no-]incremental]\n" \ ++ " [--[no-]stdin-packs] [--refs-snapshot=]\n" \ ++ " [--[no-]write-chain-file] [--base=]") #define BUILTIN_MIDX_COMPACT_USAGE \ - N_("git multi-pack-index [] compact [--[no-]incremental]\n" \ -+ N_("git multi-pack-index compact [] [--[no-]incremental]\n" \ - " [--[no-]bitmap] [--base=] [--[no-]write-chain-file]\n" \ - " ") +- " [--[no-]bitmap] [--base=] [--[no-]write-chain-file]\n" \ +- " ") ++ N_("git multi-pack-index compact [--object-dir=] [--[no-]progress]\n" \ ++ " [--[no-]incremental] [--[no-]bitmap] [--base=]\n" \ ++ " [--[no-]write-chain-file] ") #define BUILTIN_MIDX_VERIFY_USAGE \ - N_("git multi-pack-index [] verify") -+ N_("git multi-pack-index verify []") ++ N_("git multi-pack-index verify [--object-dir=] [--[no-]progress]") #define BUILTIN_MIDX_EXPIRE_USAGE \ - N_("git multi-pack-index [] expire") -+ N_("git multi-pack-index expire []") ++ N_("git multi-pack-index expire [--object-dir=] [--[no-]progress]") #define BUILTIN_MIDX_REPACK_USAGE \ - N_("git multi-pack-index [] repack [--batch-size=]") -+ N_("git multi-pack-index repack [] [--batch-size=]") ++ N_("git multi-pack-index repack [--object-dir=] [--[no-]progress]\n" \ ++ " [--batch-size=]") static char const * const builtin_multi_pack_index_write_usage[] = { BUILTIN_MIDX_WRITE_USAGE, 4: 1c16a0988239 ! 4: 3bb2b9a69f1c builtin/multi-pack-index: simplify how common options are wired up @@ builtin/multi-pack-index.c: static struct odb_source_packed *handle_object_dir_o } -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(), @@ builtin/multi-pack-index.c: static struct odb_source_packed *handle_object_dir_o - return parse_options_concat(common_opts, prev); -} +#define MULTI_PACK_INDEX_COMMON_OPTIONS(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) @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, cons - struct option *options; - static struct option builtin_multi_pack_index_write_options[] = { + static struct option options[] = { ++ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts), OPT_STRING(0, "preferred-pack", &opts.preferred_pack, N_("preferred-pack"), N_("pack for reuse when computing a multi-pack bitmap")), @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, const char **argv, - N_("write multi-pack index containing only given indexes")), - OPT_FILENAME(0, "refs-snapshot", &opts.refs_snapshot, - N_("refs snapshot for selecting bitmap commits")), -+ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts), - OPT_END(), - }; - struct odb_source_packed *packed_source; -@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, const char **argv, repo_config(repo, git_multi_pack_index_write_config, NULL); @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_compact(int argc, co - struct option *options; - static struct option builtin_multi_pack_index_compact_options[] = { + static struct option options[] = { ++ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts), OPT_STRING(0, "base", &opts.incremental_base, N_("checksum"), N_("base MIDX for incremental writes")), OPT_BIT(0, "bitmap", &opts.flags, N_("write multi-pack bitmap"), @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_compact(int argc, const char **argv, - OPT_NEGBIT(0, "write-chain-file", &opts.flags, - N_("write the multi-pack-index chain file"), - MIDX_WRITE_NO_CHAIN), -+ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts), - OPT_END(), - }; repo_config(repo, git_multi_pack_index_write_config, NULL); @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_repack(int argc, con - struct option *options; - static struct option builtin_multi_pack_index_repack_options[] = { + static struct option options[] = { ++ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts), OPT_UNSIGNED(0, "batch-size", &opts.batch_size, N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")), -+ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts), OPT_END(), }; struct odb_source_packed *packed_source; 5: d8ac43810193 ! 5: 46a59a5daf52 builtin/multi-pack-index: de-globalize options handling @@ builtin/multi-pack-index.c: static char const * const builtin_multi_pack_index_u -static struct opts_multi_pack_index { +struct opts_multi_pack_index { - char *object_dir; + const char *object_dir; const char *preferred_pack; const char *incremental_base; @@ builtin/multi-pack-index.c: static struct opts_multi_pack_index { @@ builtin/multi-pack-index.c: static struct opts_multi_pack_index { unsigned flags; int stdin_packs; -} opts; -- +}; - static int parse_object_dir(const struct option *opt, const char *arg, - int unset) -@@ builtin/multi-pack-index.c: static int parse_object_dir(const struct option *opt, const char *arg, - return 0; - } - -static struct odb_source_packed *handle_object_dir_option(struct repository *repo) +static struct odb_source_packed *handle_object_dir_option(struct repository *repo, + const char *object_dir) @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, cons - static struct option options[] = { + struct opts_multi_pack_index opts = { 0 }; + struct option options[] = { + MULTI_PACK_INDEX_COMMON_OPTIONS(&opts), OPT_STRING(0, "preferred-pack", &opts.preferred_pack, N_("preferred-pack"), - N_("pack for reuse when computing a multi-pack bitmap")), @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, const char **argv, opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE; @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, cons if (opts.stdin_packs) { struct string_list packs = STRING_LIST_INIT_DUP; -@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, const char **argv, - - string_list_clear(&packs, 0); - free(opts.refs_snapshot); -+ free(opts.object_dir); - - return ret; - -@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, const char **argv, - opts.refs_snapshot, opts.flags); - - free(opts.refs_snapshot); -+ free(opts.object_dir); - return ret; - } - @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_compact(int argc, const char **argv, const char *prefix, struct repository *repo) @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_compact(int argc, co - static struct option options[] = { + struct option options[] = { + MULTI_PACK_INDEX_COMMON_OPTIONS(&opts), OPT_STRING(0, "base", &opts.incremental_base, N_("checksum"), N_("base MIDX for incremental writes")), - OPT_BIT(0, "bitmap", &opts.flags, N_("write multi-pack bitmap"), @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_compact(int argc, const char **argv, OPT_END(), }; @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_compact(int argc, co m = get_multi_pack_index(packed_source); -@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_compact(int argc, const char **argv, - ret = write_midx_file_compact(packed_source, from_midx, to_midx, - opts.incremental_base, opts.flags); - -+ free(opts.object_dir); - return ret; - } - @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_verify(int argc, const char **argv, const char *prefix, struct repository *repo) @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_verify(int argc, con MULTI_PACK_INDEX_COMMON_OPTIONS(&opts), OPT_END(), }; - struct odb_source_packed *packed_source; -+ int ret; - - trace2_cmd_mode(argv[0]); - @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_verify(int argc, const char **argv, if (argc) usage_with_options(builtin_multi_pack_index_verify_usage, @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_verify(int argc, con - packed_source = handle_object_dir_option(repo); + packed_source = handle_object_dir_option(repo, opts.object_dir); -- return verify_midx_file(packed_source, opts.flags); -+ ret = verify_midx_file(packed_source, opts.flags); -+ -+ free(opts.object_dir); -+ return ret; + return verify_midx_file(packed_source, opts.flags); } - - static int cmd_multi_pack_index_expire(int argc, const char **argv, +@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_expire(int argc, const char **argv, const char *prefix, struct repository *repo) { @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_verify(int argc, con MULTI_PACK_INDEX_COMMON_OPTIONS(&opts), OPT_END(), }; - struct odb_source_packed *packed_source; -+ int ret; - - trace2_cmd_mode(argv[0]); - @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_expire(int argc, const char **argv, if (argc) usage_with_options(builtin_multi_pack_index_expire_usage, options); - packed_source = handle_object_dir_option(repo); + packed_source = handle_object_dir_option(repo, opts.object_dir); -+ -+ ret = expire_midx_packs(packed_source, opts.flags); -- return expire_midx_packs(packed_source, opts.flags); -+ free(opts.object_dir); -+ return ret; + return expire_midx_packs(packed_source, opts.flags); } - - static int cmd_multi_pack_index_repack(int argc, const char **argv, +@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_repack(int argc, const char **argv, const char *prefix, struct repository *repo) { - static struct option options[] = { + struct opts_multi_pack_index opts = { 0 }; + struct option options[] = { + MULTI_PACK_INDEX_COMMON_OPTIONS(&opts), OPT_UNSIGNED(0, "batch-size", &opts.batch_size, N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")), - MULTI_PACK_INDEX_COMMON_OPTIONS(&opts), - OPT_END(), - }; - struct odb_source_packed *packed_source; -+ int ret; - - trace2_cmd_mode(argv[0]); - @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_repack(int argc, const char **argv, if (argc) usage_with_options(builtin_multi_pack_index_repack_usage, options); - packed_source = handle_object_dir_option(repo); + packed_source = handle_object_dir_option(repo, opts.object_dir); -+ -+ ret = midx_repack(packed_source, (size_t)opts.batch_size, opts.flags); -- return midx_repack(packed_source, (size_t)opts.batch_size, opts.flags); -+ free(opts.object_dir); -+ return ret; + return midx_repack(packed_source, (size_t)opts.batch_size, opts.flags); } - - int cmd_multi_pack_index(int argc, @@ builtin/multi-pack-index.c: int cmd_multi_pack_index(int argc, const char *prefix, struct repository *repo) @@ builtin/multi-pack-index.c: int cmd_multi_pack_index(int argc, - res = fn(argc, argv, prefix, repo); - -- free(opts.object_dir); - return res; + return fn(argc, argv, prefix, repo); } base-commit: 86e79b2795e3ce3b0ad7685edd368574b0c8b9f2 -- 2.56.0