Skip to content

Commit

Permalink
multi-pack-index: add --no-progress to verify
Browse files Browse the repository at this point in the history
Add --no-progress option to git multi-pack-index.
The progress feature was added in 144d703
("multi-pack-index: report progress during 'verify'", 2018-09-13)
but the ability to opt-out was overlooked.

Signed-off-by: William Baker <William.Baker@microsoft.com>
  • Loading branch information
wilbaker authored and derrickstolee committed Nov 4, 2019
1 parent 6a3fa2a commit 665d520
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 16 deletions.
6 changes: 5 additions & 1 deletion Documentation/git-multi-pack-index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ git-multi-pack-index - Write and verify multi-pack-indexes
SYNOPSIS
--------
[verse]
'git multi-pack-index' [--object-dir=<dir>] <subcommand>
'git multi-pack-index' [--object-dir=<dir>] <subcommand> [--[no-]progress]

DESCRIPTION
-----------
Expand All @@ -23,6 +23,10 @@ OPTIONS
`<dir>/packs/multi-pack-index` for the current MIDX file, and
`<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:

write::
Expand Down
14 changes: 11 additions & 3 deletions builtin/multi-pack-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,41 @@
#include "trace2.h"

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 [--object-dir=<dir>] (write|verify|expire|repack --batch-size=<size>) [--[no-]progress]"),
NULL
};

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

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

static struct option builtin_multi_pack_index_options[] = {
OPT_FILENAME(0, "object-dir", &opts.object_dir,
N_("object directory containing set of packfile and pack-index pairs")),
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")),
OPT_BOOL(0, "progress", &opts.progress, N_("force progress reporting")),
OPT_END(),
};

git_config(git_default_config, NULL);

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

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

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

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

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

Expand Down
30 changes: 20 additions & 10 deletions midx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1076,19 +1076,20 @@ static int compare_pair_pos_vs_id(const void *_a, const void *_b)
display_progress(progress, _n); \
} while (0)

int verify_midx_file(struct repository *r, const char *object_dir)
int verify_midx_file(struct repository *r, const char *object_dir, unsigned flags)
{
struct pair_pos_vs_id *pairs = NULL;
uint32_t i;
struct progress *progress;
struct progress *progress = NULL;
struct multi_pack_index *m = load_multi_pack_index(object_dir, 1);
verify_midx_error = 0;

if (!m)
return 0;

progress = start_progress(_("Looking for referenced packfiles"),
m->num_packs);
if (flags & MIDX_PROGRESS)
progress = start_progress(_("Looking for referenced packfiles"),
m->num_packs);
for (i = 0; i < m->num_packs; i++) {
if (prepare_midx_pack(r, m, i))
midx_report("failed to load pack in position %d", i);
Expand All @@ -1106,8 +1107,9 @@ int verify_midx_file(struct repository *r, const char *object_dir)
i, oid_fanout1, oid_fanout2, i + 1);
}

progress = start_sparse_progress(_("Verifying OID order in MIDX"),
m->num_objects - 1);
if (flags & MIDX_PROGRESS)
progress = start_sparse_progress(_("Verifying OID order in MIDX"),
m->num_objects - 1);
for (i = 0; i < m->num_objects - 1; i++) {
struct object_id oid1, oid2;

Expand All @@ -1134,13 +1136,15 @@ int verify_midx_file(struct repository *r, const char *object_dir)
pairs[i].pack_int_id = nth_midxed_pack_int_id(m, i);
}

progress = start_sparse_progress(_("Sorting objects by packfile"),
m->num_objects);
if (flags & MIDX_PROGRESS)
progress = start_sparse_progress(_("Sorting objects by packfile"),
m->num_objects);
display_progress(progress, 0); /* TODO: Measure QSORT() progress */
QSORT(pairs, m->num_objects, compare_pair_pos_vs_id);
stop_progress(&progress);

progress = start_sparse_progress(_("Verifying object offsets"), m->num_objects);
if (flags & MIDX_PROGRESS)
progress = start_sparse_progress(_("Verifying object offsets"), m->num_objects);
for (i = 0; i < m->num_objects; i++) {
struct object_id oid;
struct pack_entry e;
Expand Down Expand Up @@ -1315,7 +1319,7 @@ static int fill_included_packs_batch(struct repository *r,
return 0;
}

int midx_repack(struct repository *r, const char *object_dir, size_t batch_size)
int midx_repack(struct repository *r, const char *object_dir, size_t batch_size, unsigned flags)
{
int result = 0;
uint32_t i;
Expand All @@ -1340,6 +1344,12 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size)
strbuf_addstr(&base_name, object_dir);
strbuf_addstr(&base_name, "/pack/pack");
argv_array_push(&cmd.args, base_name.buf);

if (flags & MIDX_PROGRESS)
argv_array_push(&cmd.args, "--progress");
else
argv_array_push(&cmd.args, "-q");

strbuf_release(&base_name);

cmd.git_cmd = 1;
Expand Down
6 changes: 4 additions & 2 deletions midx.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ struct multi_pack_index {
char object_dir[FLEX_ARRAY];
};

#define MIDX_PROGRESS (1 << 0)

struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local);
int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id);
int bsearch_midx(const struct object_id *oid, struct multi_pack_index *m, uint32_t *result);
Expand All @@ -49,9 +51,9 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, i

int write_midx_file(const char *object_dir);
void clear_midx_file(struct repository *r);
int verify_midx_file(struct repository *r, const char *object_dir);
int verify_midx_file(struct repository *r, const char *object_dir, unsigned flags);
int expire_midx_packs(struct repository *r, const char *object_dir);
int midx_repack(struct repository *r, const char *object_dir, size_t batch_size);
int midx_repack(struct repository *r, const char *object_dir, size_t batch_size, unsigned flags);

void close_midx(struct multi_pack_index *m);

Expand Down
30 changes: 30 additions & 0 deletions t/t5319-multi-pack-index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,21 @@ test_expect_success 'verify multi-pack-index success' '
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>
corrupt_midx_and_verify() {
POS=$1 &&
Expand Down Expand Up @@ -284,6 +299,21 @@ test_expect_success 'git-fsck incorrect offset' '
"git -c core.multipackindex=true fsck"
'

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

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

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

test_expect_success 'repack removes multi-pack-index' '
test_path_is_file $objdir/pack/multi-pack-index &&
GIT_TEST_MULTI_PACK_INDEX=0 git repack -adf &&
Expand Down

0 comments on commit 665d520

Please sign in to comment.