git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 2/6] commit-graph write: add more progress output

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Nov 20, 2018, 23:38 UTC
Message-ID
<20181120233840.GC30222@szeder.dev>
In-Reply-To
<20181120195027.3260-3-avarab@gmail.com>
On Tue, Nov 20, 2018 at 07:50:23PM +0000, Ævar Arnfjörð Bjarmason wrote:
Show 21 quoted lines
> Add more progress output to the output already added in
> 7b0f229222 ("commit-graph write: add progress output", 2018-09-17).
> 
> As noted in that commit most of the progress output isn't displayed on
> small repositories, but before this change we'd noticeably hang for
> 2-3 seconds at the end on medium sized repositories such as linux.git.
> 
> Now we'll instead show output like this, and have no human-observable
> point at which we're not producing progress output:
> 
>     $ ~/g/git/git --exec-path=$HOME/g/git commit-graph write
>     Finding commits for commit graph: 6365492, done.
>     Computing commit graph generation numbers: 100% (797222/797222), done.
>     Writing out commit graph: 2399912, done.
> 
> This "writing out" number is not meant to be meaningful to the user,
> but just to show that we're doing work and the command isn't
> hanging.
> 
> In the current implementation it's approximately 4x the number of
> commits.

"approximately" only, because the current implementation is buggy :) If done right it's exactly 4x the number of commits.

> As noted in on-list discussion[1] we could add the loops up
> and show percentage progress here, but I don't think it's worth it. It
> would make the implementation more complex and harder to maintain for
> very little gain.

I think that if we can cheaply and accurately figure out the total, then we should display it, so onlooking users can guesstimate how much work is still left to be done.

Show 36 quoted lines
> On a much larger in-house repository I have we'll show (note how we
> also say "Annotating[...]"):
> 
>     $ ~/g/git/git --exec-path=$HOME/g/git commit-graph write
>     Finding commits for commit graph: 50026015, done.
>     Annotating commit graph: 21567407, done.
>     Computing commit graph generation numbers: 100% (7144680/7144680), done.
>     Writing out commit graph: 21434417, done.
> 
> 1. https://public-inbox.org/git/20181120165800.GB30222@szeder.dev/
> 
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  commit-graph.c | 41 ++++++++++++++++++++++++++++++++---------
>  1 file changed, 32 insertions(+), 9 deletions(-)
> 
> diff --git a/commit-graph.c b/commit-graph.c
> index e6d0d7722b..6f6409b292 100644
> --- a/commit-graph.c
> +++ b/commit-graph.c
> @@ -433,7 +433,9 @@ struct tree *get_commit_tree_in_graph(struct repository *r, const struct commit
>  
>  static void write_graph_chunk_fanout(struct hashfile *f,
>  				     struct commit **commits,
> -				     int nr_commits)
> +				     int nr_commits,
> +				     struct progress *progress,
> +				     uint64_t *progress_cnt)
>  {
>  	int i, count = 0;
>  	struct commit **list = commits;
> @@ -445,6 +447,7 @@ static void write_graph_chunk_fanout(struct hashfile *f,
>  	 */
>  	for (i = 0; i < 256; i++) {
>  		while (count < nr_commits) {
> +			display_progress(progress, ++*progress_cnt);

I think this display_progress() should be places after the condition, so no one has to waste brain cycles on figuring out, why it always counts 255 more than the number of commits.

Show 52 quoted lines
>  			if ((*list)->object.oid.hash[0] != i)
>  				break;
>  			count++;
> @@ -456,12 +459,16 @@ static void write_graph_chunk_fanout(struct hashfile *f,
>  }
>  
>  static void write_graph_chunk_oids(struct hashfile *f, int hash_len,
> -				   struct commit **commits, int nr_commits)
> +				   struct commit **commits, int nr_commits,
> +				   struct progress *progress,
> +				   uint64_t *progress_cnt)
>  {
>  	struct commit **list = commits;
>  	int count;
> -	for (count = 0; count < nr_commits; count++, list++)
> +	for (count = 0; count < nr_commits; count++, list++) {
> +		display_progress(progress, ++*progress_cnt);
>  		hashwrite(f, (*list)->object.oid.hash, (int)hash_len);
> +	}
>  }
>  
>  static const unsigned char *commit_to_sha1(size_t index, void *table)
> @@ -471,7 +478,9 @@ static const unsigned char *commit_to_sha1(size_t index, void *table)
>  }
>  
>  static void write_graph_chunk_data(struct hashfile *f, int hash_len,
> -				   struct commit **commits, int nr_commits)
> +				   struct commit **commits, int nr_commits,
> +				   struct progress *progress,
> +				   uint64_t *progress_cnt)
>  {
>  	struct commit **list = commits;
>  	struct commit **last = commits + nr_commits;
> @@ -481,6 +490,7 @@ static void write_graph_chunk_data(struct hashfile *f, int hash_len,
>  		struct commit_list *parent;
>  		int edge_value;
>  		uint32_t packedDate[2];
> +		display_progress(progress, ++*progress_cnt);
>  
>  		parse_commit(*list);
>  		hashwrite(f, get_commit_tree_oid(*list)->hash, hash_len);
> @@ -542,7 +552,9 @@ static void write_graph_chunk_data(struct hashfile *f, int hash_len,
>  
>  static void write_graph_chunk_large_edges(struct hashfile *f,
>  					  struct commit **commits,
> -					  int nr_commits)
> +					  int nr_commits,
> +					  struct progress *progress,
> +					  uint64_t *progress_cnt)
>  {
>  	struct commit **list = commits;
>  	struct commit **last = commits + nr_commits;
> @@ -565,6 +577,7 @@ static void write_graph_chunk_large_edges(struct hashfile *f,
[Adding more before-context to this hunk here...]
>	while (list < last) {
This loop iterates over all commits ...
>		int num_parents = 0;
>		for (parent = (*list)->parents; num_parents < 3 && parent;
>		     parent = parent->next)
>			num_parents++;
... counts the parents of the current commit ...
>
>		if (num_parents <= 2) {
>			list++;
>			continue;
... and continues iterating unless it's an octopus merge.
Show 9 quoted lines
>		}
>
>		/* Since num_parents > 2, this initializer is safe. */
>		for (parent = (*list)->parents->next; parent; parent = parent->next) {
>			int edge_value = sha1_pos(parent->item->object.oid.hash,
>  						  commits,
>  						  nr_commits,
>  						  commit_to_sha1);
> +			display_progress(progress, ++*progress_cnt);

So this display_progress() call is in the wrong place, because it will only be invoked on octopus merges, which only rarely occur in practice, thus it's entirely possible that it won't show any progress at all while the outer while loop iterates over the whole history.

This display_progress() should be places somewhere before that 'if (num_parents <= 2)' condition. And then this one, too, will count the number of commits.

Show 38 quoted lines
>  
>  			if (edge_value < 0)
>  				edge_value = GRAPH_PARENT_MISSING;
> @@ -764,6 +777,7 @@ void write_commit_graph(const char *obj_dir,
>  	int num_extra_edges;
>  	struct commit_list *parent;
>  	struct progress *progress = NULL;
> +	uint64_t progress_cnt = 0;
>  
>  	if (!commit_graph_compatible(the_repository))
>  		return;
> @@ -937,10 +951,19 @@ void write_commit_graph(const char *obj_dir,
>  		hashwrite(f, chunk_write, 12);
>  	}
>  
> -	write_graph_chunk_fanout(f, commits.list, commits.nr);
> -	write_graph_chunk_oids(f, GRAPH_OID_LEN, commits.list, commits.nr);
> -	write_graph_chunk_data(f, GRAPH_OID_LEN, commits.list, commits.nr);
> -	write_graph_chunk_large_edges(f, commits.list, commits.nr);
> +	if (report_progress)
> +		progress = start_delayed_progress(
> +			_("Writing out commit graph"),
> +			0);
> +	write_graph_chunk_fanout(f, commits.list, commits.nr, progress,
> +				 &progress_cnt);
> +	write_graph_chunk_oids(f, GRAPH_OID_LEN, commits.list, commits.nr,
> +			       progress, &progress_cnt);
> +	write_graph_chunk_data(f, GRAPH_OID_LEN, commits.list, commits.nr,
> +			       progress, &progress_cnt);
> +	write_graph_chunk_large_edges(f, commits.list, commits.nr, progress,
> +				      &progress_cnt);
> +	stop_progress(&progress);
>  
>  	close_commit_graph(the_repository);
>  	finalize_hashfile(f, NULL, CSUM_HASH_IN_STREAM | CSUM_FSYNC);
> -- 
> 2.20.0.rc0.387.gc7a69e6b6c
> 
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 50 of 133 in “commit-graph: add progress output”
  1. 0/2 commit-graph: add progress outputÆvar Arnfjörð Bjarmason, Sep 4, 2018
  2. 2/2 commit-graph verify: add progress outputÆvar Arnfjörð Bjarmason, Sep 4, 2018
  3. Junio C HamanoSep 4, 2018
  4. 1/2 commit-graph write: add progress outputÆvar Arnfjörð Bjarmason, Sep 4, 2018
  5. Eric SunshineSep 4, 2018
  6. Junio C HamanoSep 4, 2018
  7. Derrick StoleeSep 5, 2018
  8. Ævar Arnfjörð BjarmasonSep 5, 2018
  9. Junio C HamanoSep 5, 2018
  10. Derrick StoleeSep 5, 2018
  11. Ævar Arnfjörð BjarmasonSep 7, 2018
  12. Ævar Arnfjörð BjarmasonSep 7, 2018
  13. Jeff KingSep 7, 2018
  14. Derrick StoleeSep 7, 2018
  15. Derrick StoleeSep 5, 2018
  16. Ævar Arnfjörð BjarmasonSep 7, 2018
  17. Derrick StoleeSep 7, 2018
  18. Derrick StoleeSep 5, 2018
  19. 0/2 commit-graph: add progress outputÆvar Arnfjörð Bjarmason, Sep 7, 2018
  20. Junio C HamanoSep 11, 2018
  21. 1/2 commit-graph write: add progress outputÆvar Arnfjörð Bjarmason, Sep 7, 2018
  22. Derrick StoleeSep 21, 2018
  23. Junio C HamanoSep 21, 2018
  24. Junio C HamanoSep 21, 2018
  25. 2/2 commit-graph verify: add progress outputÆvar Arnfjörð Bjarmason, Sep 7, 2018
  26. Duy NguyenSep 16, 2018
  27. 0/2 commit-graph: add progress outputÆvar Arnfjörð Bjarmason, Sep 17, 2018
  28. 1/2 commit-graph write: add progress outputÆvar Arnfjörð Bjarmason, Sep 17, 2018
  29. SZEDER GáborOct 10, 2018
  30. Ævar Arnfjörð BjarmasonOct 10, 2018
  31. SZEDER GáborOct 10, 2018
  32. Ævar Arnfjörð BjarmasonOct 10, 2018
  33. Ævar Arnfjörð BjarmasonOct 11, 2018
  34. SZEDER GáborOct 15, 2018
  35. Junio C HamanoOct 12, 2018
  36. Ævar Arnfjörð BjarmasonOct 12, 2018
  37. Derrick StoleeOct 12, 2018
  38. SZEDER GáborOct 15, 2018
  39. SZEDER GáborNov 19, 2018
  40. commit-graph: split up close_reachable() progress outputÆvar Arnfjörð Bjarmason, Nov 19, 2018
  41. Derrick StoleeNov 19, 2018
  42. SZEDER GáborNov 19, 2018
  43. 0/6 commit-graph write: progress output improvementsÆvar Arnfjörð Bjarmason, Nov 20, 2018
  44. 1/6 commit-graph write: rephrase confusing progress outputÆvar Arnfjörð Bjarmason, Nov 20, 2018
  45. 2/6 commit-graph write: add more progress outputÆvar Arnfjörð Bjarmason, Nov 20, 2018
  46. SZEDER GáborNov 20, 2018
  47. 0/6 commit-graph write: progress output improvementsÆvar Arnfjörð Bjarmason, Nov 20, 2018
  48. 1/6 commit-graph write: rephrase confusing progress outputÆvar Arnfjörð Bjarmason, Nov 20, 2018
  49. 2/6 commit-graph write: add more progress outputÆvar Arnfjörð Bjarmason, Nov 20, 2018
  50. SZEDER GáborNov 20, 2018
  51. 3/6 commit-graph write: show progress for object searchÆvar Arnfjörð Bjarmason, Nov 20, 2018
  52. 4/6 commit-graph write: add more describing progress outputÆvar Arnfjörð Bjarmason, Nov 20, 2018
  53. 5/6 commit-graph write: remove empty line for readabilityÆvar Arnfjörð Bjarmason, Nov 20, 2018
  54. 6/6 commit-graph write: add even more progress outputÆvar Arnfjörð Bjarmason, Nov 20, 2018
  55. SZEDER Gábor, Nov 21, 2018
  56. 1/2 commit-graph: rename 'num_extra_edges' variable to 'num_large_edges'SZEDER Gábor, Nov 21, 2018
  57. Junio C HamanoNov 21, 2018
  58. Derrick StoleeNov 21, 2018
  59. 0/2 commit-graph: minor cleanup and optimizationSZEDER Gábor, Jan 18, 2019
  60. 1/2 commit-graph: rename "large edges" to "extra edges"SZEDER Gábor, Jan 18, 2019
  61. 2/2 commit-graph: don't call write_graph_chunk_large_edges() unnecessarilySZEDER Gábor, Jan 18, 2019
  62. Martin ÅgrenJan 19, 2019
  63. Junio C HamanoJan 18, 2019
  64. 2/2 commit-graph: don't call write_graph_chunk_large_edges() unnecessarilySZEDER Gábor, Nov 21, 2018
  65. Derrick StoleeNov 21, 2018
  66. 00/10 commit-graph write: progress output improvementsÆvar Arnfjörð Bjarmason, Nov 22, 2018
  67. 00/10 commit-graph write: progress output improvementsÆvar Arnfjörð Bjarmason, Nov 22, 2018
  68. 01/10 commit-graph: rename 'num_extra_edges' variable to 'num_large_edges'Ævar Arnfjörð Bjarmason, Nov 22, 2018
  69. 0/9 commit-graph write: progress output improvementsÆvar Arnfjörð Bjarmason, Jan 16, 2019
  70. Junio C HamanoJan 19, 2019
  71. 00/10 commit-graph write: progress output improvementsÆvar Arnfjörð Bjarmason, Jan 19, 2019
  72. Derrick StoleeJan 22, 2019
  73. Junio C HamanoJan 23, 2019
  74. Junio C HamanoJan 22, 2019
  75. 01/10 commit-graph write: use pack order when finding commitsÆvar Arnfjörð Bjarmason, Jan 19, 2019
  76. 02/10 commit-graph: rename "large edges" to "extra edges"Ævar Arnfjörð Bjarmason, Jan 19, 2019
  77. 03/10 commit-graph: don't call write_graph_chunk_large_edges() unnecessarilyÆvar Arnfjörð Bjarmason, Jan 19, 2019
  78. 03/10 commit-graph: don't call write_graph_chunk_extra_edges() unnecessarilySZEDER Gábor, Jan 23, 2019
  79. 04/10 commit-graph write: add "Writing out" progress outputÆvar Arnfjörð Bjarmason, Jan 19, 2019
  80. 05/10 commit-graph write: more descriptive "writing out" outputÆvar Arnfjörð Bjarmason, Jan 19, 2019
  81. 06/10 commit-graph write: show progress for object searchÆvar Arnfjörð Bjarmason, Jan 19, 2019
  82. 08/10 commit-graph write: remove empty line for readabilityÆvar Arnfjörð Bjarmason, Jan 19, 2019
  83. 07/10 commit-graph write: add more descriptive progress outputÆvar Arnfjörð Bjarmason, Jan 19, 2019
  84. 09/10 commit-graph write: add itermediate progressÆvar Arnfjörð Bjarmason, Jan 19, 2019
  85. 10/10 commit-graph write: emit a percentage for all progressÆvar Arnfjörð Bjarmason, Jan 19, 2019
  86. commit-graph: don't show progress percentages while expanding reachable commitsSZEDER Gábor, Mar 22, 2019
  87. Ævar Arnfjörð BjarmasonMar 22, 2019
  88. SZEDER GáborMar 22, 2019
  89. Ævar Arnfjörð BjarmasonMar 22, 2019
  90. Ævar Arnfjörð BjarmasonMar 22, 2019
  91. SZEDER GáborMar 22, 2019
  92. Ævar Arnfjörð BjarmasonMar 22, 2019
  93. SZEDER GáborMar 22, 2019
  94. SZEDER GáborMar 22, 2019
  95. Ævar Arnfjörð BjarmasonMar 22, 2019
  96. 1/9 commit-graph: rename 'num_extra_edges' variable to 'num_large_edges'Ævar Arnfjörð Bjarmason, Jan 16, 2019
  97. 2/9 commit-graph: don't call write_graph_chunk_large_edges() unnecessarilyÆvar Arnfjörð Bjarmason, Jan 16, 2019
  98. 3/9 commit-graph write: add "Writing out" progress outputÆvar Arnfjörð Bjarmason, Jan 16, 2019
  99. SZEDER GáborJan 18, 2019
  100. 4/9 commit-graph write: more descriptive "writing out" outputÆvar Arnfjörð Bjarmason, Jan 16, 2019
  101. 5/9 commit-graph write: show progress for object searchÆvar Arnfjörð Bjarmason, Jan 16, 2019
  102. 6/9 commit-graph write: add more descriptive progress outputÆvar Arnfjörð Bjarmason, Jan 16, 2019
  103. 7/9 commit-graph write: remove empty line for readabilityÆvar Arnfjörð Bjarmason, Jan 16, 2019
  104. 8/9 commit-graph write: add itermediate progressÆvar Arnfjörð Bjarmason, Jan 16, 2019
  105. 9/9 commit-graph write: emit a percentage for all progressÆvar Arnfjörð Bjarmason, Jan 16, 2019
  106. commit-graph write: use pack order when finding commitsÆvar Arnfjörð Bjarmason, Jan 17, 2019
  107. Derrick StoleeJan 17, 2019
  108. Derrick StoleeJan 17, 2019
  109. 02/10 commit-graph: don't call write_graph_chunk_large_edges() unnecessarilyÆvar Arnfjörð Bjarmason, Nov 22, 2018
  110. 03/10 commit-graph write: rephrase confusing progress outputÆvar Arnfjörð Bjarmason, Nov 22, 2018
  111. 05/10 commit-graph write: more descriptive "writing out" outputÆvar Arnfjörð Bjarmason, Nov 22, 2018
  112. 04/10 commit-graph write: add "Writing out" progress outputÆvar Arnfjörð Bjarmason, Nov 22, 2018
  113. 06/10 commit-graph write: show progress for object searchÆvar Arnfjörð Bjarmason, Nov 22, 2018
  114. 07/10 commit-graph write: add more descriptive progress outputÆvar Arnfjörð Bjarmason, Nov 22, 2018
  115. 08/10 commit-graph write: remove empty line for readabilityÆvar Arnfjörð Bjarmason, Nov 22, 2018
  116. 09/10 commit-graph write: add itermediate progressÆvar Arnfjörð Bjarmason, Nov 22, 2018
  117. 10/10 commit-graph write: emit a percentage for all progressÆvar Arnfjörð Bjarmason, Nov 22, 2018
  118. Eric SunshineNov 22, 2018
  119. 01/10 commit-graph: rename 'num_extra_edges' variable to 'num_large_edges'Ævar Arnfjörð Bjarmason, Nov 22, 2018
  120. 03/10 commit-graph write: rephrase confusing progress outputÆvar Arnfjörð Bjarmason, Nov 22, 2018
  121. 02/10 commit-graph: don't call write_graph_chunk_large_edges() unnecessarilyÆvar Arnfjörð Bjarmason, Nov 22, 2018
  122. 04/10 commit-graph write: add "Writing out" progress outputÆvar Arnfjörð Bjarmason, Nov 22, 2018
  123. 05/10 commit-graph write: more descriptive "writing out" outputÆvar Arnfjörð Bjarmason, Nov 22, 2018
  124. 06/10 commit-graph write: show progress for object searchÆvar Arnfjörð Bjarmason, Nov 22, 2018
  125. 07/10 commit-graph write: add more descriptive progress outputÆvar Arnfjörð Bjarmason, Nov 22, 2018
  126. 08/10 commit-graph write: remove empty line for readabilityÆvar Arnfjörð Bjarmason, Nov 22, 2018
  127. 09/10 commit-graph write: add itermediate progressÆvar Arnfjörð Bjarmason, Nov 22, 2018
  128. 10/10 commit-graph write: emit a percentage for all progressÆvar Arnfjörð Bjarmason, Nov 22, 2018
  129. 3/6 commit-graph write: show progress for object searchÆvar Arnfjörð Bjarmason, Nov 20, 2018
  130. 4/6 commit-graph write: add more describing progress outputÆvar Arnfjörð Bjarmason, Nov 20, 2018
  131. 5/6 commit-graph write: remove empty line for readabilityÆvar Arnfjörð Bjarmason, Nov 20, 2018
  132. 6/6 commit-graph write: add even more progress outputÆvar Arnfjörð Bjarmason, Nov 20, 2018
  133. 2/2 commit-graph verify: add progress outputÆvar Arnfjörð Bjarmason, Sep 17, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.