@matheusbsbs / matheus-bagliano / commits / 680cba2c2b
Fork 0

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 <William.Baker@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

William Baker committed Oct 21, 2019 at 18:40 UTC 680cba2c2b1c8120c960faf80cf80a7636519be2
3 files changed +87 -6
Documentation/git-multi-pack-index.txt
+5 -1
@@ -9,7 +9,7 @@ git-multi-pack-index - Write and verify multi-pack-indexes
9 SYNOPSIS
10 --------
11 [verse]
12 -'git multi-pack-index' [--object-dir=<dir>] <subcommand>
12 +'git multi-pack-index' [--object-dir=<dir>] [--[no-]progress] <subcommand>
13
14 DESCRIPTION
15 -----------
@@ -23,6 +23,10 @@ OPTIONS
23 `<dir>/packs/multi-pack-index` for the current MIDX file, and
24 `<dir>/packs` for the pack-files to index.
25
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 +
30 The following subcommands are available:
31
32 write::
builtin/multi-pack-index.c
+13 -5
@@ -6,21 +6,25 @@
6 #include "trace2.h"
7
8 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>)"),
10 NULL
11 };
12
13 static struct opts_multi_pack_index {
14 const char *object_dir;
15 unsigned long batch_size;
16 + int progress;
17 } opts;
18
19 int cmd_multi_pack_index(int argc, const char **argv,
20 const char *prefix)
21 {
22 + unsigned flags = 0;
23 +
24 static struct option builtin_multi_pack_index_options[] = {
25 OPT_FILENAME(0, "object-dir", &opts.object_dir,
26 N_("object directory containing set of packfile and pack-index pairs")),
27 + OPT_BOOL(0, "progress", &opts.progress, N_("force progress reporting")),
28 OPT_MAGNITUDE(0, "batch-size", &opts.batch_size,
29 N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")),
30 OPT_END(),
@@ -28,12 +32,15 @@ int cmd_multi_pack_index(int argc, const char **argv,
32
33 git_config(git_default_config, NULL);
34
35 + opts.progress = isatty(2);
36 argc = parse_options(argc, argv, prefix,
37 builtin_multi_pack_index_options,
38 builtin_multi_pack_index_usage, 0);
39
40 if (!opts.object_dir)
41 opts.object_dir = get_object_directory();
42 + if (opts.progress)
43 + flags |= MIDX_PROGRESS;
44
45 if (argc == 0)
46 usage_with_options(builtin_multi_pack_index_usage,
@@ -47,16 +54,17 @@ int cmd_multi_pack_index(int argc, const char **argv,
54 trace2_cmd_mode(argv[0]);
55
56 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);
59 if (opts.batch_size)
60 die(_("--batch-size option is only for 'repack' subcommand"));
61
62 if (!strcmp(argv[0], "write"))
55 - return write_midx_file(opts.object_dir, 0);
63 + return write_midx_file(opts.object_dir, flags);
64 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);
66 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);
68
69 die(_("unrecognized subcommand: %s"), argv[0]);
70 }
t/t5319-multi-pack-index.sh
+69
@@ -147,6 +147,21 @@ test_expect_success 'write midx with two packs' '
147
148 compare_results_with_midx "two packs"
149
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 +
165 test_expect_success 'add more packs' '
166 for j in $(test_seq 11 20)
167 do
@@ -169,6 +184,21 @@ test_expect_success 'verify multi-pack-index success' '
184 git multi-pack-index verify --object-dir=$objdir
185 '
186
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 +
202 # usage: corrupt_midx_and_verify <pos> <data> <objdir> <string>
203 corrupt_midx_and_verify() {
204 POS=$1 &&
@@ -284,6 +314,21 @@ test_expect_success 'git-fsck incorrect offset' '
314 "git -c core.multipackindex=true fsck"
315 '
316
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 +
332 test_expect_success 'repack removes multi-pack-index' '
333 test_path_is_file $objdir/pack/multi-pack-index &&
334 GIT_TEST_MULTI_PACK_INDEX=0 git repack -adf &&
@@ -413,6 +458,30 @@ test_expect_success 'expire does not remove any packs' '
458 )
459 '
460
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 +
485 test_expect_success 'expire removes unreferenced packs' '
486 (
487 cd dup &&