Skip to content

Commit fc16cfe

Browse files
committed
Merge branch 'wb/midx-progress' into jch
The code to generate multi-pack index learned to show (or not to show) progress indicators. * wb/midx-progress: multi-pack-index: add [--[no-]progress] option. midx: honor the MIDX_PROGRESS flag in midx_repack midx: honor the MIDX_PROGRESS flag in verify_midx_file midx: add progress to expire_midx_packs midx: add progress to write_midx_file midx: add MIDX_PROGRESS flag
2 parents e189c25 + 680cba2 commit fc16cfe

File tree

6 files changed

+149
-27
lines changed

6 files changed

+149
-27
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);
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);
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);
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);
67+
return expire_midx_packs(the_repository, opts.object_dir, flags);
6068

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

builtin/repack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
569569
remove_temporary_files();
570570

571571
if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0))
572-
write_midx_file(get_object_directory());
572+
write_midx_file(get_object_directory(), 0);
573573

574574
string_list_clear(&names, 0);
575575
string_list_clear(&rollback, 0);

midx.c

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ struct pack_list {
448448
uint32_t nr;
449449
uint32_t alloc;
450450
struct multi_pack_index *m;
451+
struct progress *progress;
452+
unsigned pack_paths_checked;
451453
};
452454

453455
static void add_pack_to_midx(const char *full_path, size_t full_path_len,
@@ -456,6 +458,7 @@ static void add_pack_to_midx(const char *full_path, size_t full_path_len,
456458
struct pack_list *packs = (struct pack_list *)data;
457459

458460
if (ends_with(file_name, ".idx")) {
461+
display_progress(packs->progress, ++packs->pack_paths_checked);
459462
if (packs->m && midx_contains_pack(packs->m, file_name))
460463
return;
461464

@@ -785,7 +788,7 @@ static size_t write_midx_large_offsets(struct hashfile *f, uint32_t nr_large_off
785788
}
786789

787790
static int write_midx_internal(const char *object_dir, struct multi_pack_index *m,
788-
struct string_list *packs_to_drop)
791+
struct string_list *packs_to_drop, unsigned flags)
789792
{
790793
unsigned char cur_chunk, num_chunks = 0;
791794
char *midx_name;
@@ -799,6 +802,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
799802
uint64_t chunk_offsets[MIDX_MAX_CHUNKS + 1];
800803
uint32_t nr_entries, num_large_offsets = 0;
801804
struct pack_midx_entry *entries = NULL;
805+
struct progress *progress = NULL;
802806
int large_offsets_needed = 0;
803807
int pack_name_concat_len = 0;
804808
int dropped_packs = 0;
@@ -833,7 +837,14 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
833837
}
834838
}
835839

840+
packs.pack_paths_checked = 0;
841+
if (flags & MIDX_PROGRESS)
842+
packs.progress = start_progress(_("Adding packfiles to multi-pack-index"), 0);
843+
else
844+
packs.progress = NULL;
845+
836846
for_each_file_in_pack_dir(object_dir, add_pack_to_midx, &packs);
847+
stop_progress(&packs.progress);
837848

838849
if (packs.m && packs.nr == packs.m->num_packs && !packs_to_drop)
839850
goto cleanup;
@@ -958,6 +969,9 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
958969
written += MIDX_CHUNKLOOKUP_WIDTH;
959970
}
960971

972+
if (flags & MIDX_PROGRESS)
973+
progress = start_progress(_("Writing chunks to multi-pack-index"),
974+
num_chunks);
961975
for (i = 0; i < num_chunks; i++) {
962976
if (written != chunk_offsets[i])
963977
BUG("incorrect chunk offset (%"PRIu64" != %"PRIu64") for chunk id %"PRIx32,
@@ -990,7 +1004,10 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
9901004
BUG("trying to write unknown chunk id %"PRIx32,
9911005
chunk_ids[i]);
9921006
}
1007+
1008+
display_progress(progress, i + 1);
9931009
}
1010+
stop_progress(&progress);
9941011

9951012
if (written != chunk_offsets[num_chunks])
9961013
BUG("incorrect final offset %"PRIu64" != %"PRIu64,
@@ -1016,9 +1033,9 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
10161033
return result;
10171034
}
10181035

1019-
int write_midx_file(const char *object_dir)
1036+
int write_midx_file(const char *object_dir, unsigned flags)
10201037
{
1021-
return write_midx_internal(object_dir, NULL, NULL);
1038+
return write_midx_internal(object_dir, NULL, NULL, flags);
10221039
}
10231040

10241041
void clear_midx_file(struct repository *r)
@@ -1076,19 +1093,20 @@ static int compare_pair_pos_vs_id(const void *_a, const void *_b)
10761093
display_progress(progress, _n); \
10771094
} while (0)
10781095

1079-
int verify_midx_file(struct repository *r, const char *object_dir)
1096+
int verify_midx_file(struct repository *r, const char *object_dir, unsigned flags)
10801097
{
10811098
struct pair_pos_vs_id *pairs = NULL;
10821099
uint32_t i;
1083-
struct progress *progress;
1100+
struct progress *progress = NULL;
10841101
struct multi_pack_index *m = load_multi_pack_index(object_dir, 1);
10851102
verify_midx_error = 0;
10861103

10871104
if (!m)
10881105
return 0;
10891106

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

1109-
progress = start_sparse_progress(_("Verifying OID order in MIDX"),
1110-
m->num_objects - 1);
1127+
if (flags & MIDX_PROGRESS)
1128+
progress = start_sparse_progress(_("Verifying OID order in multi-pack-index"),
1129+
m->num_objects - 1);
11111130
for (i = 0; i < m->num_objects - 1; i++) {
11121131
struct object_id oid1, oid2;
11131132

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

1137-
progress = start_sparse_progress(_("Sorting objects by packfile"),
1138-
m->num_objects);
1156+
if (flags & MIDX_PROGRESS)
1157+
progress = start_sparse_progress(_("Sorting objects by packfile"),
1158+
m->num_objects);
11391159
display_progress(progress, 0); /* TODO: Measure QSORT() progress */
11401160
QSORT(pairs, m->num_objects, compare_pair_pos_vs_id);
11411161
stop_progress(&progress);
11421162

1143-
progress = start_sparse_progress(_("Verifying object offsets"), m->num_objects);
1163+
if (flags & MIDX_PROGRESS)
1164+
progress = start_sparse_progress(_("Verifying object offsets"), m->num_objects);
11441165
for (i = 0; i < m->num_objects; i++) {
11451166
struct object_id oid;
11461167
struct pack_entry e;
@@ -1183,23 +1204,34 @@ int verify_midx_file(struct repository *r, const char *object_dir)
11831204
return verify_midx_error;
11841205
}
11851206

1186-
int expire_midx_packs(struct repository *r, const char *object_dir)
1207+
int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags)
11871208
{
11881209
uint32_t i, *count, result = 0;
11891210
struct string_list packs_to_drop = STRING_LIST_INIT_DUP;
11901211
struct multi_pack_index *m = load_multi_pack_index(object_dir, 1);
1212+
struct progress *progress = NULL;
11911213

11921214
if (!m)
11931215
return 0;
11941216

11951217
count = xcalloc(m->num_packs, sizeof(uint32_t));
1218+
1219+
if (flags & MIDX_PROGRESS)
1220+
progress = start_progress(_("Counting referenced objects"),
1221+
m->num_objects);
11961222
for (i = 0; i < m->num_objects; i++) {
11971223
int pack_int_id = nth_midxed_pack_int_id(m, i);
11981224
count[pack_int_id]++;
1225+
display_progress(progress, i + 1);
11991226
}
1227+
stop_progress(&progress);
12001228

1229+
if (flags & MIDX_PROGRESS)
1230+
progress = start_progress(_("Finding and deleting unreferenced packfiles"),
1231+
m->num_packs);
12011232
for (i = 0; i < m->num_packs; i++) {
12021233
char *pack_name;
1234+
display_progress(progress, i + 1);
12031235

12041236
if (count[i])
12051237
continue;
@@ -1217,11 +1249,12 @@ int expire_midx_packs(struct repository *r, const char *object_dir)
12171249
unlink_pack_path(pack_name, 0);
12181250
free(pack_name);
12191251
}
1252+
stop_progress(&progress);
12201253

12211254
free(count);
12221255

12231256
if (packs_to_drop.nr)
1224-
result = write_midx_internal(object_dir, m, &packs_to_drop);
1257+
result = write_midx_internal(object_dir, m, &packs_to_drop, flags);
12251258

12261259
string_list_clear(&packs_to_drop, 0);
12271260
return result;
@@ -1315,7 +1348,7 @@ static int fill_included_packs_batch(struct repository *r,
13151348
return 0;
13161349
}
13171350

1318-
int midx_repack(struct repository *r, const char *object_dir, size_t batch_size)
1351+
int midx_repack(struct repository *r, const char *object_dir, size_t batch_size, unsigned flags)
13191352
{
13201353
int result = 0;
13211354
uint32_t i;
@@ -1340,6 +1373,12 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size)
13401373
strbuf_addstr(&base_name, object_dir);
13411374
strbuf_addstr(&base_name, "/pack/pack");
13421375
argv_array_push(&cmd.args, base_name.buf);
1376+
1377+
if (flags & MIDX_PROGRESS)
1378+
argv_array_push(&cmd.args, "--progress");
1379+
else
1380+
argv_array_push(&cmd.args, "-q");
1381+
13431382
strbuf_release(&base_name);
13441383

13451384
cmd.git_cmd = 1;
@@ -1370,7 +1409,7 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size)
13701409
goto cleanup;
13711410
}
13721411

1373-
result = write_midx_internal(object_dir, m, NULL);
1412+
result = write_midx_internal(object_dir, m, NULL, flags);
13741413
m = NULL;
13751414

13761415
cleanup:

midx.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ struct multi_pack_index {
3737
char object_dir[FLEX_ARRAY];
3838
};
3939

40+
#define MIDX_PROGRESS (1 << 0)
41+
4042
struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local);
4143
int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id);
4244
int bsearch_midx(const struct object_id *oid, struct multi_pack_index *m, uint32_t *result);
@@ -47,11 +49,11 @@ int fill_midx_entry(struct repository *r, const struct object_id *oid, struct pa
4749
int midx_contains_pack(struct multi_pack_index *m, const char *idx_or_pack_name);
4850
int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, int local);
4951

50-
int write_midx_file(const char *object_dir);
52+
int write_midx_file(const char *object_dir, unsigned flags);
5153
void clear_midx_file(struct repository *r);
52-
int verify_midx_file(struct repository *r, const char *object_dir);
53-
int expire_midx_packs(struct repository *r, const char *object_dir);
54-
int midx_repack(struct repository *r, const char *object_dir, size_t batch_size);
54+
int verify_midx_file(struct repository *r, const char *object_dir, unsigned flags);
55+
int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags);
56+
int midx_repack(struct repository *r, const char *object_dir, size_t batch_size, unsigned flags);
5557

5658
void close_midx(struct multi_pack_index *m);
5759

0 commit comments

Comments
 (0)