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

Re: [PATCH v2 2/3] for-each-ref: add 'is-base' token

From
Derrick Stolee <stolee@gmail.com>
Date
Aug 13, 2024, 13:44 UTC
Message-ID
<8b1b05fa-829b-4f3d-9c25-cbb478176531@gmail.com>
In-Reply-To
<xmqqsev9zc2j.fsf@gitster.g>
On 8/12/24 5:05 PM, Junio C Hamano wrote:
> "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 10 quoted lines
>> +		} else if (atom_type == ATOM_ISBASE) {
>> +			if (ref->is_base && ref->is_base[is_base_atoms]) {
>> +				v->s = xstrfmt("(%s)", ref->is_base[is_base_atoms]);
>> +				free(ref->is_base[is_base_atoms]);
>> +			} else {
>> +				/* Not a commit. */
> 
> This is unexpected.  I thought that most of the branches except at
> most one that gets annotated with "Yeah, this is forked from branch
> B" would take the "else" side.  They are still commits, no?

You are correct. This is leftover from copy-pasting the ahead-behind section. Will remove.

Show 11 quoted lines
>> +	for (size_t i = 0; i < array->nr; i++) {
>> +		const char *name = array->items[i]->refname;
>> +		struct commit *c = lookup_commit_reference_by_name(name);
>> +
>> +		CALLOC_ARRAY(array->items[i]->is_base, format->is_base_tips.nr);
>> +
>> +		if (!c)
>> +			continue;
> 
> Hmph, wouldn't we want to leave array->items[i]->is_base NULL if
> "name" looked up to "c" happens to be non-commit (i.e. NULL)?
Your comment initially made me second-guess the logic here, but...
>> +		back_index[bases_nr] = array->items[i];
>> +		bases[bases_nr] = c;
>> +		bases_nr++;

This array of "back_index" is intended to allow the array being passed to get_branch_base_for_tip() to have no gaps with NULL commits. The indices are then translated back to the original array items when scanning the results.

This matches the behavior of the ahead-behind code, giving an existing behavior. The alternative would be to allow get_branch_base_for_tip() to be sensitive to NULL commits in the 'bases' array. But since we need to create an array of commit pointers (different from the array of ref items that we start with) this is likely the simplest approach.

You did inspire me to double-check that this code works in the presence of non-commit refs, so I'll update some things and send a v3 with a new test. It will also include some things to make error messages quieter for that case.

Thanks, -Stolee

Previous: Junio C HamanoNext: Derrick Stolee via GitGitGadget
Message 12 of 23 in “git for-each-ref: is-base atom and base branches”
  1. 0/3 git for-each-ref: is-base atom and base branchesDerrick Stolee via GitGitGadget, Aug 1, 2024
  2. 2/3 for-each-ref: add 'is-base' tokenDerrick Stolee via GitGitGadget, Aug 1, 2024
  3. 1/3 commit-reach: add get_branch_base_for_tipDerrick Stolee via GitGitGadget, Aug 1, 2024
  4. 3/3 p1500: add is-base performance testsDerrick Stolee via GitGitGadget, Aug 1, 2024
  5. Junio C HamanoAug 1, 2024
  6. Derrick StoleeAug 2, 2024
  7. Junio C HamanoAug 2, 2024
  8. Junio C HamanoAug 2, 2024
  9. 0/3 git for-each-ref: is-base atom and base branchesDerrick Stolee via GitGitGadget, Aug 11, 2024
  10. 2/3 for-each-ref: add 'is-base' tokenDerrick Stolee via GitGitGadget, Aug 11, 2024
  11. Junio C HamanoAug 12, 2024
  12. Derrick StoleeAug 13, 2024
  13. 1/3 commit-reach: add get_branch_base_for_tipDerrick Stolee via GitGitGadget, Aug 11, 2024
  14. Junio C HamanoAug 12, 2024
  15. Derrick StoleeAug 13, 2024
  16. 3/3 p1500: add is-base performance testsDerrick Stolee via GitGitGadget, Aug 11, 2024
  17. 0/4 git for-each-ref: is-base atom and base branchesDerrick Stolee via GitGitGadget, Aug 14, 2024
  18. 1/4 commit-reach: add get_branch_base_for_tipDerrick Stolee via GitGitGadget, Aug 14, 2024
  19. 2/4 commit: add gentle reference lookup methodDerrick Stolee via GitGitGadget, Aug 14, 2024
  20. 3/4 for-each-ref: add 'is-base' tokenDerrick Stolee via GitGitGadget, Aug 14, 2024
  21. 4/4 p1500: add is-base performance testsDerrick Stolee via GitGitGadget, Aug 14, 2024
  22. Junio C HamanoAug 19, 2024
  23. Derrick StoleeAug 20, 2024

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.