index-pack: add --progress-title option

Add a --progress-title option to index-pack, when data is piped into index-pack its progress is a proxy for whatever's feeding it data. This option will allow us to set a more relevant progress bar title in "git bundle unbundle", and is also used in my "bundle-uri" RFC patches[1] by a new caller in fetch-pack.c. The code change in cmd_index_pack() won't handle "--progress-title=xyz", only "--progress-title xyz", and the "(i+1)" style (as opposed to "i + 1") is a bit odd. Not using the "--long-option=value" style is inconsistent with existing long options handled by cmd_index_pack(), but makes the code that needs to call it better (two strvec_push(), instead of needing a strvec_pushf()). Since the option is internal-only the inconsistency shouldn't matter. I'm copying the pattern to handle it as-is from the handling of the existing "-o" option in the same function, see 9cf6d3357aa (Add git-index-pack utility, 2005-10-12) for its addition. That's a short option, but the code to implement the two is the same in functionality and style. Eventually we'd like to migrate all of this this to parse_options(), which would make these differences in behavior go away. 1. https://lore.kernel.org/git/RFC-cover-00.13-0000000000-20210805T150534Z-avarab@gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Sep 5, 2021 at 09:34 UTC f46c46e4f22506a01aa0033b37ef027d9e87585f
2 files changed +12
Documentation/git-index-pack.txt
+6
@@ -82,6 +82,12 @@ OPTIONS
82 --strict::
83 Die, if the pack contains broken objects or links.
84
85 +--progress-title::
86 + For internal use only.
87 ++
88 +Set the title of the progress bar. The title is "Receiving objects" by
89 +default and "Indexing objects" when `--stdin` is specified.
90 +
91 --check-self-contained-and-connected::
92 Die if the pack contains broken links. For internal use only.
93
builtin/index-pack.c
+6
@@ -122,6 +122,7 @@ static int strict;
122 static int do_fsck_object;
123 static struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES;
124 static int verbose;
125 +static const char *progress_title;
126 static int show_resolving_progress;
127 static int show_stat;
128 static int check_self_contained_and_connected;
@@ -1157,6 +1158,7 @@ static void parse_pack_objects(unsigned char *hash)
1158
1159 if (verbose)
1160 progress = start_progress(
1161 + progress_title ? progress_title :
1162 from_stdin ? _("Receiving objects") : _("Indexing objects"),
1163 nr_objects);
1164 for (i = 0; i < nr_objects; i++) {
@@ -1806,6 +1808,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1808 input_len = sizeof(*hdr);
1809 } else if (!strcmp(arg, "-v")) {
1810 verbose = 1;
1811 + } else if (!strcmp(arg, "--progress-title")) {
1812 + if (progress_title || (i+1) >= argc)
1813 + usage(index_pack_usage);
1814 + progress_title = argv[++i];
1815 } else if (!strcmp(arg, "--show-resolving-progress")) {
1816 show_resolving_progress = 1;
1817 } else if (!strcmp(arg, "--report-end-of-input")) {