Skip to content

Commit 840cef0

Browse files
wilbakergitster
authored andcommitted
midx: add progress to write_midx_file
Add progress to write_midx_file. Progress is displayed when the MIDX_PROGRESS flag is set. Signed-off-by: William Baker <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent efbc3ae commit 840cef0

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

midx.c

Lines changed: 21 additions & 4 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,
@@ -1018,7 +1035,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
10181035

10191036
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)
@@ -1221,7 +1238,7 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla
12211238
free(count);
12221239

12231240
if (packs_to_drop.nr)
1224-
result = write_midx_internal(object_dir, m, &packs_to_drop);
1241+
result = write_midx_internal(object_dir, m, &packs_to_drop, flags);
12251242

12261243
string_list_clear(&packs_to_drop, 0);
12271244
return result;
@@ -1370,7 +1387,7 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
13701387
goto cleanup;
13711388
}
13721389

1373-
result = write_midx_internal(object_dir, m, NULL);
1390+
result = write_midx_internal(object_dir, m, NULL, flags);
13741391
m = NULL;
13751392

13761393
cleanup:

0 commit comments

Comments
 (0)