]> git.ipfire.org Git - thirdparty/git.git/commitdiff
midx: add progress to write_midx_file
authorWilliam Baker <William.Baker@microsoft.com>
Mon, 21 Oct 2019 18:39:59 +0000 (18:39 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Oct 2019 03:05:05 +0000 (12:05 +0900)
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>
midx.c

diff --git a/midx.c b/midx.c
index f169a681dd34e9a638f2134df02f707edc4de94c..716aeecefb1f68696f73102308742213a39df982 100644 (file)
--- a/midx.c
+++ b/midx.c
@@ -448,6 +448,8 @@ struct pack_list {
        uint32_t nr;
        uint32_t alloc;
        struct multi_pack_index *m;
+       struct progress *progress;
+       unsigned pack_paths_checked;
 };
 
 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,
        struct pack_list *packs = (struct pack_list *)data;
 
        if (ends_with(file_name, ".idx")) {
+               display_progress(packs->progress, ++packs->pack_paths_checked);
                if (packs->m && midx_contains_pack(packs->m, file_name))
                        return;
 
@@ -785,7 +788,7 @@ static size_t write_midx_large_offsets(struct hashfile *f, uint32_t nr_large_off
 }
 
 static int write_midx_internal(const char *object_dir, struct multi_pack_index *m,
-                              struct string_list *packs_to_drop)
+                              struct string_list *packs_to_drop, unsigned flags)
 {
        unsigned char cur_chunk, num_chunks = 0;
        char *midx_name;
@@ -799,6 +802,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
        uint64_t chunk_offsets[MIDX_MAX_CHUNKS + 1];
        uint32_t nr_entries, num_large_offsets = 0;
        struct pack_midx_entry *entries = NULL;
+       struct progress *progress = NULL;
        int large_offsets_needed = 0;
        int pack_name_concat_len = 0;
        int dropped_packs = 0;
@@ -833,7 +837,14 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
                }
        }
 
+       packs.pack_paths_checked = 0;
+       if (flags & MIDX_PROGRESS)
+               packs.progress = start_progress(_("Adding packfiles to multi-pack-index"), 0);
+       else
+               packs.progress = NULL;
+
        for_each_file_in_pack_dir(object_dir, add_pack_to_midx, &packs);
+       stop_progress(&packs.progress);
 
        if (packs.m && packs.nr == packs.m->num_packs && !packs_to_drop)
                goto cleanup;
@@ -958,6 +969,9 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
                written += MIDX_CHUNKLOOKUP_WIDTH;
        }
 
+       if (flags & MIDX_PROGRESS)
+               progress = start_progress(_("Writing chunks to multi-pack-index"),
+                                         num_chunks);
        for (i = 0; i < num_chunks; i++) {
                if (written != chunk_offsets[i])
                        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 *
                                BUG("trying to write unknown chunk id %"PRIx32,
                                    chunk_ids[i]);
                }
+
+               display_progress(progress, i + 1);
        }
+       stop_progress(&progress);
 
        if (written != chunk_offsets[num_chunks])
                BUG("incorrect final offset %"PRIu64" != %"PRIu64,
@@ -1018,7 +1035,7 @@ cleanup:
 
 int write_midx_file(const char *object_dir, unsigned flags)
 {
-       return write_midx_internal(object_dir, NULL, NULL);
+       return write_midx_internal(object_dir, NULL, NULL, flags);
 }
 
 void clear_midx_file(struct repository *r)
@@ -1221,7 +1238,7 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla
        free(count);
 
        if (packs_to_drop.nr)
-               result = write_midx_internal(object_dir, m, &packs_to_drop);
+               result = write_midx_internal(object_dir, m, &packs_to_drop, flags);
 
        string_list_clear(&packs_to_drop, 0);
        return result;
@@ -1370,7 +1387,7 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
                goto cleanup;
        }
 
-       result = write_midx_internal(object_dir, m, NULL);
+       result = write_midx_internal(object_dir, m, NULL, flags);
        m = NULL;
 
 cleanup: