commit-graph write: show progress for object search

Show the percentage progress for the "Finding commits for commit graph" phase for the common case where we're operating on all packs in the repository, as "commit-graph write" or "gc" will do. Before we'd emit on e.g. linux.git with "commit-graph write": Finding commits for commit graph: 6529159, done. [...] And now: Finding commits for commit graph: 100% (6529159/6529159), done. [...] Since the commit graph only includes those commits that are packed (via for_each_packed_object(...)) the approximate_object_count() returns the actual number of objects we're going to process. Still, it is possible due to a race with "gc" or another process maintaining packs that the number of objects we're going to process is lower than what approximate_object_count() reported. In that case we don't want to stop the progress bar short of 100%. So let's make sure it snaps to 100% at the end. The inverse case is also possible and more likely. I.e. that a new pack has been added between approximate_object_count() and for_each_packed_object(). In that case the percentage will go beyond 100%, and we'll do nothing to snap it back to 100% at the end. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jan 19, 2019 at 21:21 UTC d9b1b309cfc0ebbe5ac689e1131f8c85b025c8c7
1 file changed +7 -2
commit-graph.c
+7 -2
@@ -785,12 +785,14 @@ void write_commit_graph(const char *obj_dir,
785 struct progress *progress = NULL;
786 uint64_t progress_cnt = 0;
787 struct strbuf progress_title = STRBUF_INIT;
788 + unsigned long approx_nr_objects;
789
790 if (!commit_graph_compatible(the_repository))
791 return;
792
793 oids.nr = 0;
793 - oids.alloc = approximate_object_count() / 32;
794 + approx_nr_objects = approximate_object_count();
795 + oids.alloc = approx_nr_objects / 32;
796 oids.progress = NULL;
797 oids.progress_done = 0;
798
@@ -871,9 +873,12 @@ void write_commit_graph(const char *obj_dir,
873 if (!pack_indexes && !commit_hex) {
874 if (report_progress)
875 oids.progress = start_delayed_progress(
874 - _("Finding commits for commit graph"), 0);
876 + _("Finding commits for commit graph"),
877 + approx_nr_objects);
878 for_each_packed_object(add_packed_commits, &oids,
879 FOR_EACH_OBJECT_PACK_ORDER);
880 + if (oids.progress_done < approx_nr_objects)
881 + display_progress(oids.progress, approx_nr_objects);
882 stop_progress(&oids.progress);
883 }
884