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

Re: [PATCH v2 8/8] commit-reach: add tips_reachable_from_bases()

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Mar 15, 2023, 14:13 UTC
Message-ID
<230315.864jqmxfd9.gmgdl@evledraar.gmail.com>
In-Reply-To
<f3fb6833bd71d559a3076d9617a235614ad9a5f8.1678468864.git.gitgitgadget@gmail.com>
On Fri, Mar 10 2023, Derrick Stolee via GitGitGadget wrote:
> From: Derrick Stolee <derrickstolee@github.com>
> +{
> +	size_t i;
Ditto the decl suggestion in an earlier commit, i.e...
Show 18 quoted lines
> +	struct commit_and_index *commits;
> +	unsigned int min_generation_index = 0;
> +	timestamp_t min_generation;
> +	struct commit_list *stack = NULL;
> +
> +	if (!bases || !tips || !tips_nr)
> +		return;
> +
> +	/*
> +	 * Do a depth-first search starting at 'bases' to search for the
> +	 * tips. Stop at the lowest (un-found) generation number. When
> +	 * finding the lowest commit, increase the minimum generation
> +	 * number to the next lowest (un-found) generation number.
> +	 */
> +
> +	CALLOC_ARRAY(commits, tips_nr);
> +
> +	for (i = 0; i < tips_nr; i++) {
...move this here?
Show 17 quoted lines
> +		commits[i].commit = tips[i];
> +		commits[i].index = i;
> +		commits[i].generation = commit_graph_generation(tips[i]);
> +	}
> +
> +	/* Sort with generation number ascending. */
> +	QSORT(commits, tips_nr, compare_commit_and_index_by_generation);
> +	min_generation = commits[0].generation;
> +
> +	while (bases) {
> +		parse_commit(bases->item);
> +		commit_list_insert(bases->item, &stack);
> +		bases = bases->next;
> +	}
> +
> +	while (stack) {
> +		unsigned int j;
...ditto...
Show 7 quoted lines
> +		int explored_all_parents = 1;
> +		struct commit_list *p;
> +		struct commit *c = stack->item;
> +		timestamp_t c_gen = commit_graph_generation(c);
> +
> +		/* Does it match any of our tips? */
> +		for (j = min_generation_index; j < tips_nr; j++) {
...to here...
Show 47 quoted lines
> +			if (c_gen < commits[j].generation)
> +				break;
> +
> +			if (commits[j].commit == c) {
> +				tips[commits[j].index]->object.flags |= mark;
> +
> +				if (j == min_generation_index) {
> +					unsigned int k = j + 1;
> +					while (k < tips_nr &&
> +					       (tips[commits[k].index]->object.flags & mark))
> +						k++;
> +
> +					/* Terminate early if all found. */
> +					if (k >= tips_nr)
> +						goto done;
> +
> +					min_generation_index = k;
> +					min_generation = commits[k].generation;
> +				}
> +			}
> +		}
> +
> +		for (p = c->parents; p; p = p->next) {
> +			parse_commit(p->item);
> +
> +			/* Have we already explored this parent? */
> +			if (p->item->object.flags & SEEN)
> +				continue;
> +
> +			/* Is it below the current minimum generation? */
> +			if (commit_graph_generation(p->item) < min_generation)
> +				continue;
> +
> +			/* Ok, we will explore from here on. */
> +			p->item->object.flags |= SEEN;
> +			explored_all_parents = 0;
> +			commit_list_insert(p->item, &stack);
> +			break;
> +		}
> +
> +		if (explored_all_parents)
> +			pop_commit(&stack);
> +	}
> +
> +done:
> +	free(commits);
> +	repo_clear_commit_marks(the_repository, SEEN);

I didn't see this in my earlier suggestion for passing "struct repository", but I think we should do the same here, i.e. have this function take a "r" argument.

Show 35 quoted lines
> [...]
> @@ -2390,33 +2390,21 @@ static void reach_filter(struct ref_array *array,
>  			 struct commit_list *check_reachable,
>  			 int include_reached)
>  {
> -	struct rev_info revs;
>  	int i, old_nr;
>  	struct commit **to_clear;
> -	struct commit_list *cr;
>  
>  	if (!check_reachable)
>  		return;
>  
>  	CALLOC_ARRAY(to_clear, array->nr);
> -
> -	repo_init_revisions(the_repository, &revs, NULL);
> -
>  	for (i = 0; i < array->nr; i++) {
>  		struct ref_array_item *item = array->items[i];
> -		add_pending_object(&revs, &item->commit->object, item->refname);
>  		to_clear[i] = item->commit;
>  	}
>  
> -	for (cr = check_reachable; cr; cr = cr->next) {
> -		struct commit *merge_commit = cr->item;
> -		merge_commit->object.flags |= UNINTERESTING;
> -		add_pending_object(&revs, &merge_commit->object, "");
> -	}
> -
> -	revs.limited = 1;
> -	if (prepare_revision_walk(&revs))
> -		die(_("revision walk setup failed"));
> +	tips_reachable_from_bases(check_reachable,
> +				  to_clear, array->nr,
> +				  UNINTERESTING);

I.e. it's not ideal, but we had a the_repository in this function before (should probably have passed it from further up, but whatever), so we could pass that to the new tips_reachable_from_bases() still.

Show 5 quoted lines
> -test_perf 'ahead-behind counts: git rev-list' '
> -	for r in $(cat refs)
> -	do
> -		git rev-list --count "HEAD..$r" || return 1
> -	done

Why does this change require deleting the old perf test? Your commit 7/8 notes this test, but here we're deleting it, let's keep it and instead note if the results changed, or stayed the same?

More generally, your commit message says:
> Add extra tests for this behavior in t6600-test-reach.sh as the
> interesting data shape of that repository can sometimes demonstrate
> corner case bugs.

And here for a supposed optimization commit you're adding new tests, but when I try them with the C code at 7/8 they pass.

So it seems we should add them earlier, and this is a pure-optimization commit, but one that's a bit confused about what goes where? :)

Previous: Derrick Stolee via GitGitGadgetNext: Derrick Stolee
Message 47 of 90 in “ahead-behind: new builtin for counting multiple commit ranges”
  1. 0/8 ahead-behind: new builtin for counting multiple commit rangesDerrick Stolee via GitGitGadget, Mar 6, 2023
  2. 1/8 ahead-behind: create empty builtinDerrick Stolee via GitGitGadget, Mar 6, 2023
  3. Junio C HamanoMar 6, 2023
  4. Taylor BlauMar 7, 2023
  5. Derrick StoleeMar 8, 2023
  6. Junio C HamanoMar 8, 2023
  7. 2/8 ahead-behind: parse tip referencesDerrick Stolee via GitGitGadget, Mar 6, 2023
  8. Taylor BlauMar 7, 2023
  9. 3/8 ahead-behind: implement --ignore-missing optionDerrick Stolee via GitGitGadget, Mar 6, 2023
  10. Taylor BlauMar 7, 2023
  11. 4/8 commit-graph: combine generation computationsDerrick Stolee via GitGitGadget, Mar 6, 2023
  12. 5/8 commit-graph: return generation from memoryDerrick Stolee via GitGitGadget, Mar 6, 2023
  13. 6/8 commit-graph: introduce `ensure_generations_valid()`Taylor Blau via GitGitGadget, Mar 6, 2023
  14. Junio C HamanoMar 6, 2023
  15. Taylor BlauMar 7, 2023
  16. 7/8 ahead-behind: implement ahead_behind() logicDerrick Stolee via GitGitGadget, Mar 6, 2023
  17. Taylor BlauMar 7, 2023
  18. Derrick StoleeMar 9, 2023
  19. 8/8 ahead-behind: add --contains modeDerrick Stolee via GitGitGadget, Mar 6, 2023
  20. Junio C HamanoMar 6, 2023
  21. Derrick StoleeMar 6, 2023
  22. Junio C HamanoMar 6, 2023
  23. Taylor BlauMar 7, 2023
  24. Jeff KingMar 9, 2023
  25. Junio C HamanoMar 9, 2023
  26. Taylor BlauMar 7, 2023
  27. 0/8 ref-filter: ahead/behind counting, faster --merged optionDerrick Stolee via GitGitGadget, Mar 10, 2023
  28. 1/8 for-each-ref: add --stdin optionDerrick Stolee via GitGitGadget, Mar 10, 2023
  29. Junio C HamanoMar 10, 2023
  30. Phillip WoodMar 13, 2023
  31. Derrick StoleeMar 13, 2023
  32. Taylor BlauMar 13, 2023
  33. Ævar Arnfjörð BjarmasonMar 15, 2023
  34. Jeff KingMar 15, 2023
  35. Jeff KingMar 15, 2023
  36. Junio C HamanoMar 15, 2023
  37. Jeff KingMar 15, 2023
  38. 2/8 for-each-ref: explicitly test no matchesDerrick Stolee via GitGitGadget, Mar 10, 2023
  39. 3/8 commit-graph: combine generation computationsDerrick Stolee via GitGitGadget, Mar 10, 2023
  40. 4/8 commit-graph: return generation from memoryDerrick Stolee via GitGitGadget, Mar 10, 2023
  41. 5/8 commit-graph: introduce `ensure_generations_valid()`Taylor Blau via GitGitGadget, Mar 10, 2023
  42. 6/8 commit-reach: implement ahead_behind() logicDerrick Stolee via GitGitGadget, Mar 10, 2023
  43. Ævar Arnfjörð BjarmasonMar 15, 2023
  44. Junio C HamanoMar 15, 2023
  45. Derrick StoleeMar 15, 2023
  46. 8/8 commit-reach: add tips_reachable_from_bases()Derrick Stolee via GitGitGadget, Mar 10, 2023
  47. Ævar Arnfjörð BjarmasonMar 15, 2023
  48. Derrick StoleeMar 15, 2023
  49. Derrick StoleeMar 15, 2023
  50. 7/8 for-each-ref: add ahead-behind format atomDerrick Stolee via GitGitGadget, Mar 10, 2023
  51. Junio C HamanoMar 10, 2023
  52. Ævar Arnfjörð BjarmasonMar 15, 2023
  53. Junio C HamanoMar 15, 2023
  54. Derrick StoleeMar 15, 2023
  55. Derrick StoleeMar 15, 2023
  56. Junio C HamanoMar 10, 2023
  57. Derrick StoleeMar 10, 2023
  58. Jeff KingMar 15, 2023
  59. Derrick StoleeMar 15, 2023
  60. Junio C HamanoMar 15, 2023
  61. Ævar Arnfjörð BjarmasonMar 15, 2023
  62. Derrick StoleeMar 15, 2023
  63. 0/8 ref-filter: ahead/behind counting, faster --merged optionDerrick Stolee via GitGitGadget, Mar 15, 2023
  64. 1/8 for-each-ref: add --stdin optionDerrick Stolee via GitGitGadget, Mar 15, 2023
  65. Jeff KingMar 15, 2023
  66. Junio C HamanoMar 15, 2023
  67. Jonathan TanMar 15, 2023
  68. 2/8 for-each-ref: explicitly test no matchesDerrick Stolee via GitGitGadget, Mar 15, 2023
  69. 5/8 commit-graph: introduce `ensure_generations_valid()`Taylor Blau via GitGitGadget, Mar 15, 2023
  70. 3/8 commit-graph: combine generation computationsDerrick Stolee via GitGitGadget, Mar 15, 2023
  71. Jonathan TanMar 15, 2023
  72. Derrick StoleeMar 17, 2023
  73. 6/8 commit-reach: implement ahead_behind() logicDerrick Stolee via GitGitGadget, Mar 15, 2023
  74. Jonathan TanMar 15, 2023
  75. Derrick StoleeMar 17, 2023
  76. 4/8 commit-graph: return generation from memoryDerrick Stolee via GitGitGadget, Mar 15, 2023
  77. Jonathan TanMar 15, 2023
  78. 8/8 commit-reach: add tips_reachable_from_bases()Derrick Stolee via GitGitGadget, Mar 15, 2023
  79. 7/8 for-each-ref: add ahead-behind format atomDerrick Stolee via GitGitGadget, Mar 15, 2023
  80. 0/9 ref-filter: ahead/behind counting, faster --merged optionDerrick Stolee via GitGitGadget, Mar 20, 2023
  81. 1/9 for-each-ref: add --stdin optionDerrick Stolee via GitGitGadget, Mar 20, 2023
  82. 2/9 for-each-ref: explicitly test no matchesDerrick Stolee via GitGitGadget, Mar 20, 2023
  83. 4/9 commit-graph: simplify compute_generation_numbers()Derrick Stolee via GitGitGadget, Mar 20, 2023
  84. 3/9 commit-graph: refactor compute_topological_levels()Derrick Stolee via GitGitGadget, Mar 20, 2023
  85. 5/9 commit-graph: return generation from memoryDerrick Stolee via GitGitGadget, Mar 20, 2023
  86. 6/9 commit-graph: introduce `ensure_generations_valid()`Taylor Blau via GitGitGadget, Mar 20, 2023
  87. 7/9 commit-reach: implement ahead_behind() logicDerrick Stolee via GitGitGadget, Mar 20, 2023
  88. Jonathan TanMar 20, 2023
  89. 9/9 commit-reach: add tips_reachable_from_bases()Derrick Stolee via GitGitGadget, Mar 20, 2023
  90. 8/9 for-each-ref: add ahead-behind format atomDerrick Stolee via GitGitGadget, Mar 20, 2023

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.