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>
maint
William Baker 2019-10-21 18:40:03 +00:00 committed by Junio C Hamano
parent 64d80e7d52
commit 680cba2c2b
3 changed files with 87 additions and 6 deletions

View File

@ -9,7 +9,7 @@ git-multi-pack-index - Write and verify multi-pack-indexes
SYNOPSIS SYNOPSIS
-------- --------
[verse] [verse]
'git multi-pack-index' [--object-dir=<dir>] <subcommand> 'git multi-pack-index' [--object-dir=<dir>] [--[no-]progress] <subcommand>


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


--[no-]progress::
Turn progress on/off explicitly. If neither is specified, progress is
shown if standard error is connected to a terminal.

The following subcommands are available: The following subcommands are available:


write:: write::

View File

@ -6,21 +6,25 @@
#include "trace2.h" #include "trace2.h"


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


static struct opts_multi_pack_index { static struct opts_multi_pack_index {
const char *object_dir; const char *object_dir;
unsigned long batch_size; unsigned long batch_size;
int progress;
} opts; } opts;


int cmd_multi_pack_index(int argc, const char **argv, int cmd_multi_pack_index(int argc, const char **argv,
const char *prefix) const char *prefix)
{ {
unsigned flags = 0;

static struct option builtin_multi_pack_index_options[] = { static struct option builtin_multi_pack_index_options[] = {
OPT_FILENAME(0, "object-dir", &opts.object_dir, OPT_FILENAME(0, "object-dir", &opts.object_dir,
N_("object directory containing set of packfile and pack-index pairs")), N_("object directory containing set of packfile and pack-index pairs")),
OPT_BOOL(0, "progress", &opts.progress, N_("force progress reporting")),
OPT_MAGNITUDE(0, "batch-size", &opts.batch_size, OPT_MAGNITUDE(0, "batch-size", &opts.batch_size,
N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")), N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")),
OPT_END(), OPT_END(),
@ -28,12 +32,15 @@ int cmd_multi_pack_index(int argc, const char **argv,


git_config(git_default_config, NULL); git_config(git_default_config, NULL);


opts.progress = isatty(2);
argc = parse_options(argc, argv, prefix, argc = parse_options(argc, argv, prefix,
builtin_multi_pack_index_options, builtin_multi_pack_index_options,
builtin_multi_pack_index_usage, 0); builtin_multi_pack_index_usage, 0);


if (!opts.object_dir) if (!opts.object_dir)
opts.object_dir = get_object_directory(); opts.object_dir = get_object_directory();
if (opts.progress)
flags |= MIDX_PROGRESS;


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


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


if (!strcmp(argv[0], "write")) if (!strcmp(argv[0], "write"))
return write_midx_file(opts.object_dir, 0); return write_midx_file(opts.object_dir, flags);
if (!strcmp(argv[0], "verify")) if (!strcmp(argv[0], "verify"))
return verify_midx_file(the_repository, opts.object_dir, 0); return verify_midx_file(the_repository, opts.object_dir, flags);
if (!strcmp(argv[0], "expire")) if (!strcmp(argv[0], "expire"))
return expire_midx_packs(the_repository, opts.object_dir, 0); return expire_midx_packs(the_repository, opts.object_dir, flags);


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

View File

@ -147,6 +147,21 @@ test_expect_success 'write midx with two packs' '


compare_results_with_midx "two packs" compare_results_with_midx "two packs"


test_expect_success 'write progress off for redirected stderr' '
git multi-pack-index --object-dir=$objdir write 2>err &&
test_line_count = 0 err
'

test_expect_success 'write force progress on for stderr' '
git multi-pack-index --object-dir=$objdir --progress write 2>err &&
test_file_not_empty err
'

test_expect_success 'write with the --no-progress option' '
git multi-pack-index --object-dir=$objdir --no-progress write 2>err &&
test_line_count = 0 err
'

test_expect_success 'add more packs' ' test_expect_success 'add more packs' '
for j in $(test_seq 11 20) for j in $(test_seq 11 20)
do do
@ -169,6 +184,21 @@ test_expect_success 'verify multi-pack-index success' '
git multi-pack-index verify --object-dir=$objdir git multi-pack-index verify --object-dir=$objdir
' '


test_expect_success 'verify progress off for redirected stderr' '
git multi-pack-index verify --object-dir=$objdir 2>err &&
test_line_count = 0 err
'

test_expect_success 'verify force progress on for stderr' '
git multi-pack-index verify --object-dir=$objdir --progress 2>err &&
test_file_not_empty err
'

test_expect_success 'verify with the --no-progress option' '
git multi-pack-index verify --object-dir=$objdir --no-progress 2>err &&
test_line_count = 0 err
'

# usage: corrupt_midx_and_verify <pos> <data> <objdir> <string> # usage: corrupt_midx_and_verify <pos> <data> <objdir> <string>
corrupt_midx_and_verify() { corrupt_midx_and_verify() {
POS=$1 && POS=$1 &&
@ -284,6 +314,21 @@ test_expect_success 'git-fsck incorrect offset' '
"git -c core.multipackindex=true fsck" "git -c core.multipackindex=true fsck"
' '


test_expect_success 'repack progress off for redirected stderr' '
git multi-pack-index --object-dir=$objdir repack 2>err &&
test_line_count = 0 err
'

test_expect_success 'repack force progress on for stderr' '
git multi-pack-index --object-dir=$objdir --progress repack 2>err &&
test_file_not_empty err
'

test_expect_success 'repack with the --no-progress option' '
git multi-pack-index --object-dir=$objdir --no-progress repack 2>err &&
test_line_count = 0 err
'

test_expect_success 'repack removes multi-pack-index' ' test_expect_success 'repack removes multi-pack-index' '
test_path_is_file $objdir/pack/multi-pack-index && test_path_is_file $objdir/pack/multi-pack-index &&
GIT_TEST_MULTI_PACK_INDEX=0 git repack -adf && GIT_TEST_MULTI_PACK_INDEX=0 git repack -adf &&
@ -413,6 +458,30 @@ test_expect_success 'expire does not remove any packs' '
) )
' '


test_expect_success 'expire progress off for redirected stderr' '
(
cd dup &&
git multi-pack-index expire 2>err &&
test_line_count = 0 err
)
'

test_expect_success 'expire force progress on for stderr' '
(
cd dup &&
git multi-pack-index --progress expire 2>err &&
test_file_not_empty err
)
'

test_expect_success 'expire with the --no-progress option' '
(
cd dup &&
git multi-pack-index --no-progress expire 2>err &&
test_line_count = 0 err
)
'

test_expect_success 'expire removes unreferenced packs' ' test_expect_success 'expire removes unreferenced packs' '
( (
cd dup && cd dup &&