@matheusbsbs / matheus-bagliano / commits / 840cef0c70
Fork 0

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

William Baker committed Oct 21, 2019 at 18:39 UTC 840cef0c70e4c664d814d09f304d4be9a63d11e4
1 file changed +21 -4
midx.c
+21 -4
@@ -448,6 +448,8 @@ struct pack_list {
448 uint32_t nr;
449 uint32_t alloc;
450 struct multi_pack_index *m;
451 + struct progress *progress;
452 + unsigned pack_paths_checked;
453 };
454
455 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,
458 struct pack_list *packs = (struct pack_list *)data;
459
460 if (ends_with(file_name, ".idx")) {
461 + display_progress(packs->progress, ++packs->pack_paths_checked);
462 if (packs->m && midx_contains_pack(packs->m, file_name))
463 return;
464
@@ -785,7 +788,7 @@ static size_t write_midx_large_offsets(struct hashfile *f, uint32_t nr_large_off
788 }
789
790 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)
792 {
793 unsigned char cur_chunk, num_chunks = 0;
794 char *midx_name;
@@ -799,6 +802,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
802 uint64_t chunk_offsets[MIDX_MAX_CHUNKS + 1];
803 uint32_t nr_entries, num_large_offsets = 0;
804 struct pack_midx_entry *entries = NULL;
805 + struct progress *progress = NULL;
806 int large_offsets_needed = 0;
807 int pack_name_concat_len = 0;
808 int dropped_packs = 0;
@@ -833,7 +837,14 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
837 }
838 }
839
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 +
846 for_each_file_in_pack_dir(object_dir, add_pack_to_midx, &packs);
847 + stop_progress(&packs.progress);
848
849 if (packs.m && packs.nr == packs.m->num_packs && !packs_to_drop)
850 goto cleanup;
@@ -958,6 +969,9 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
969 written += MIDX_CHUNKLOOKUP_WIDTH;
970 }
971
972 + if (flags & MIDX_PROGRESS)
973 + progress = start_progress(_("Writing chunks to multi-pack-index"),
974 + num_chunks);
975 for (i = 0; i < num_chunks; i++) {
976 if (written != chunk_offsets[i])
977 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 *
1004 BUG("trying to write unknown chunk id %"PRIx32,
1005 chunk_ids[i]);
1006 }
1007 +
1008 + display_progress(progress, i + 1);
1009 }
1010 + stop_progress(&progress);
1011
1012 if (written != chunk_offsets[num_chunks])
1013 BUG("incorrect final offset %"PRIu64" != %"PRIu64,
@@ -1018,7 +1035,7 @@ cleanup:
1035
1036 int write_midx_file(const char *object_dir, unsigned flags)
1037 {
1021 - return write_midx_internal(object_dir, NULL, NULL);
1038 + return write_midx_internal(object_dir, NULL, NULL, flags);
1039 }
1040
1041 void clear_midx_file(struct repository *r)
@@ -1221,7 +1238,7 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla
1238 free(count);
1239
1240 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);
1242
1243 string_list_clear(&packs_to_drop, 0);
1244 return result;
@@ -1370,7 +1387,7 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
1387 goto cleanup;
1388 }
1389
1373 - result = write_midx_internal(object_dir, m, NULL);
1390 + result = write_midx_internal(object_dir, m, NULL, flags);
1391 m = NULL;
1392
1393 cleanup: