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

Re: [GSoC][RFC PATCH] show-branch: use commit-slab for flag storage

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 18, 2025, 18:40 UTC
Message-ID
<xmqqseobksfe.fsf@gitster.g>
In-Reply-To
<20250217055049.9217-1-meetsoni3017@gmail.com>
Meet Soni <meetsoni3017@gmail.com> writes:
Show 6 quoted lines
> Replace direct accesses to commit->object.flags with the commit-slab
> mechanism. Introduce `get_commit_flags()` and `set_commit_flags()` to
> retrieve and update flags, respectively, and include `revision.h` so that
> the canonical UNINTERESTING definition is used.
>
> Signed-off-by: Meet Soni <meetsoni3017@gmail.com>

Ohhhh. I thought people somehow have "refactored" the commit traversal code here to share more with the machinery used by the "log" family of commands, but the change in this patch being contained within the single "show-branch" file indicates that it is not the case, which is good ;-)

And the MAX_REVS limitation has been with us from the very beginning of the "show-branch" command. Lifting it is very good ;-) ;-).

> ---
> I'm not entirely sure what the TODO comment meant by storing a pointer to
> the "ref name" directly, so I've assumed that the intent was to store
> flags (of type int) directly in the commit-slab instead of commit->object.

It has been forever since I looked at the code around here the last time, but I suspect that it meant the final mapping the code makes at the output phase from the bit position in the flags bits to which reference the bit (i.e. "I am reachable from that ref") could be omitted if we make the slab entry a set of (interned) refnames.

But I think using a slab whose element is still a bag of bits that is wider than object.flags word is is the most straight-forward way to lift MAX_REVS limitation. If we can leave everything else unchanged, that would be great.

> I've tested these changes using:
>  - test suite -- they passed.
>  - github ci result -- https://github.com/inosmeet/git/actions/runs/13355488433

New tests that traverse from more than historical MAX_REVS would be the most interesting.

It is not exactly surprising if the existing tests do not exercise such a case (even though it probably should have been checking that the command refused to accept more than MAX_REVS refs to prevent it from producing garbage results).

If there were such a test to illustrate what happens when too many refs are given, we can demonstrate how the behaviour changes, for the better, with this change ;-)

However ...
Show 10 quoted lines
> +static int get_commit_flags(struct commit *commit)
> +{
> +	int *result = commit_flags_peek(&commit_flags, commit);
> +	return result ? *result : 0;
> +}
> +
> +static void set_commit_flags(struct commit *commit, int flags)
> +{
> +	*commit_flags_at(&commit_flags, commit) = flags;
> +}

... it does not make much sense to use the slab mechanism if we are still limited to bitsizeof(type(flags)). If your "int" is 32 bit, and the command line fed 100 revs, we'd want a flags parameter that can house at least 100 bits passed into the "set" function, and yields the result that can hold at least 100 bits from the "get" function. I'd expect that the interface would be more like

    static int get_commit_flags(struct commit *commit, unsigned flags[]);
    static int set_commit_flags(struct commit *commit, unsigned flags[]);

with a file-scope static variable signaling how many bits we are dealing with (allowing these functions to infer how many words flags[] array has), and the return values from these helpers to indicate success (with 0) and failure (with a negative value). On a 32-bit platform, you'd need at least 4 words in flags[] array to deal with 100 revs. On a 64-bit box, 2 words would be sufficient.

I would imagine that we would need two more helpers
    static int set_flag_bit(unsigned flags[], unsigned n);
    static int get_flag_bit(unsigned flags[], unsigned n);
to query the n-th bit in a set of bits stored in flags[] array.
Thanks.
Previous: Meet SoniNext: Jeff King
Message 2 of 6 in “show-branch: use commit-slab for flag storage”
  1. Meet SoniFeb 17, 2025
  2. Junio C HamanoFeb 18, 2025
  3. Jeff KingFeb 21, 2025
  4. Junio C HamanoFeb 21, 2025
  5. Jeff KingFeb 25, 2025
  6. Ghanshyam ThakkarMar 2, 2025

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.