Skip to content

Commit ea4f869

Browse files
committed
multi-pack-index: add [--[no-]progress] option.
Add the --[no-]progress option to git multi-pack-index. Pass the MIDX_PROGRESS flag to the subcommand functions when progress should be displayed by multi-pack-index. The progress feature was added to 'verify' in 144d703 ("multi-pack-index: report progress during 'verify'", 2018-09-13) but some subcommands were not updated to display progress, and the ability to opt-out was overlooked. Signed-off-by: William Baker <[email protected]>
1 parent d6ae4e1 commit ea4f869

File tree

3 files changed

+87
-6
lines changed

3 files changed

+87
-6
lines changed

Documentation/git-multi-pack-index.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git-multi-pack-index - Write and verify multi-pack-indexes
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git multi-pack-index' [--object-dir=<dir>] <subcommand>
12+
'git multi-pack-index' [--object-dir=<dir>] [--[no-]progress] <subcommand>
1313

1414
DESCRIPTION
1515
-----------
@@ -23,6 +23,10 @@ OPTIONS
2323
`<dir>/packs/multi-pack-index` for the current MIDX file, and
2424
`<dir>/packs` for the pack-files to index.
2525

26+
--[no-]progress::
27+
Turn progress on/off explicitly. If neither is specified, progress is
28+
shown if standard error is connected to a terminal.
29+
2630
The following subcommands are available:
2731

2832
write::

builtin/multi-pack-index.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,41 @@
66
#include "trace2.h"
77

88
static char const * const builtin_multi_pack_index_usage[] = {
9-
N_("git multi-pack-index [--object-dir=<dir>] (write|verify|expire|repack --batch-size=<size>)"),
9+
N_("git multi-pack-index [<options>] (write|verify|expire|repack --batch-size=<size>)"),
1010
NULL
1111
};
1212

1313
static struct opts_multi_pack_index {
1414
const char *object_dir;
1515
unsigned long batch_size;
16+
int progress;
1617
} opts;
1718

1819
int cmd_multi_pack_index(int argc, const char **argv,
1920
const char *prefix)
2021
{
22+
unsigned flags = 0;
23+
2124
static struct option builtin_multi_pack_index_options[] = {
2225
OPT_FILENAME(0, "object-dir", &opts.object_dir,
2326
N_("object directory containing set of packfile and pack-index pairs")),
27+
OPT_BOOL(0, "progress", &opts.progress, N_("force progress reporting")),
2428
OPT_MAGNITUDE(0, "batch-size", &opts.batch_size,
2529
N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")),
2630
OPT_END(),
2731
};
2832

2933
git_config(git_default_config, NULL);
3034

35+
opts.progress = isatty(2);
3136
argc = parse_options(argc, argv, prefix,
3237
builtin_multi_pack_index_options,
3338
builtin_multi_pack_index_usage, 0);
3439

3540
if (!opts.object_dir)
3641
opts.object_dir = get_object_directory();
42+
if (opts.progress)
43+
flags |= MIDX_PROGRESS;
3744

3845
if (argc == 0)
3946
usage_with_options(builtin_multi_pack_index_usage,
@@ -47,16 +54,17 @@ int cmd_multi_pack_index(int argc, const char **argv,
4754
trace2_cmd_mode(argv[0]);
4855

4956
if (!strcmp(argv[0], "repack"))
50-
return midx_repack(the_repository, opts.object_dir, (size_t)opts.batch_size, 0);
57+
return midx_repack(the_repository, opts.object_dir,
58+
(size_t)opts.batch_size, flags);
5159
if (opts.batch_size)
5260
die(_("--batch-size option is only for 'repack' subcommand"));
5361

5462
if (!strcmp(argv[0], "write"))
55-
return write_midx_file(opts.object_dir, 0);
63+
return write_midx_file(opts.object_dir, flags);
5664
if (!strcmp(argv[0], "verify"))
57-
return verify_midx_file(the_repository, opts.object_dir, 0);
65+
return verify_midx_file(the_repository, opts.object_dir, flags);
5866
if (!strcmp(argv[0], "expire"))
59-
return expire_midx_packs(the_repository, opts.object_dir, 0);
67+
return expire_midx_packs(the_repository, opts.object_dir, flags);
6068

6169
die(_("unrecognized subcommand: %s"), argv[0]);
6270
}

t/t5319-multi-pack-index.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,21 @@ test_expect_success 'write midx with two packs' '
147147

148148
compare_results_with_midx "two packs"
149149

150+
test_expect_success 'write progress off for redirected stderr' '
151+
git multi-pack-index --object-dir=$objdir write 2>err &&
152+
test_line_count = 0 err
153+
'
154+
155+
test_expect_success 'write force progress on for stderr' '
156+
git multi-pack-index --object-dir=$objdir --progress write 2>err &&
157+
test_file_not_empty err
158+
'
159+
160+
test_expect_success 'write with the --no-progress option' '
161+
git multi-pack-index --object-dir=$objdir --no-progress write 2>err &&
162+
test_line_count = 0 err
163+
'
164+
150165
test_expect_success 'add more packs' '
151166
for j in $(test_seq 11 20)
152167
do
@@ -169,6 +184,21 @@ test_expect_success 'verify multi-pack-index success' '
169184
git multi-pack-index verify --object-dir=$objdir
170185
'
171186

187+
test_expect_success 'verify progress off for redirected stderr' '
188+
git multi-pack-index verify --object-dir=$objdir 2>err &&
189+
test_line_count = 0 err
190+
'
191+
192+
test_expect_success 'verify force progress on for stderr' '
193+
git multi-pack-index verify --object-dir=$objdir --progress 2>err &&
194+
test_file_not_empty err
195+
'
196+
197+
test_expect_success 'verify with the --no-progress option' '
198+
git multi-pack-index verify --object-dir=$objdir --no-progress 2>err &&
199+
test_line_count = 0 err
200+
'
201+
172202
# usage: corrupt_midx_and_verify <pos> <data> <objdir> <string>
173203
corrupt_midx_and_verify() {
174204
POS=$1 &&
@@ -284,6 +314,21 @@ test_expect_success 'git-fsck incorrect offset' '
284314
"git -c core.multipackindex=true fsck"
285315
'
286316

317+
test_expect_success 'repack progress off for redirected stderr' '
318+
git multi-pack-index --object-dir=$objdir repack 2>err &&
319+
test_line_count = 0 err
320+
'
321+
322+
test_expect_success 'repack force progress on for stderr' '
323+
git multi-pack-index --object-dir=$objdir --progress repack 2>err &&
324+
test_file_not_empty err
325+
'
326+
327+
test_expect_success 'repack with the --no-progress option' '
328+
git multi-pack-index --object-dir=$objdir --no-progress repack 2>err &&
329+
test_line_count = 0 err
330+
'
331+
287332
test_expect_success 'repack removes multi-pack-index' '
288333
test_path_is_file $objdir/pack/multi-pack-index &&
289334
GIT_TEST_MULTI_PACK_INDEX=0 git repack -adf &&
@@ -413,6 +458,30 @@ test_expect_success 'expire does not remove any packs' '
413458
)
414459
'
415460

461+
test_expect_success 'expire progress off for redirected stderr' '
462+
(
463+
cd dup &&
464+
git multi-pack-index expire 2>err &&
465+
test_line_count = 0 err
466+
)
467+
'
468+
469+
test_expect_success 'expire force progress on for stderr' '
470+
(
471+
cd dup &&
472+
git multi-pack-index --progress expire 2>err &&
473+
test_file_not_empty err
474+
)
475+
'
476+
477+
test_expect_success 'expire with the --no-progress option' '
478+
(
479+
cd dup &&
480+
git multi-pack-index --no-progress expire 2>err &&
481+
test_line_count = 0 err
482+
)
483+
'
484+
416485
test_expect_success 'expire removes unreferenced packs' '
417486
(
418487
cd dup &&

0 commit comments

Comments
 (0)