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

Re: [PATCH v3 1/2] submodule: use the submodule repository to abbreviate commits

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 10, 2026, 20:26 UTC
Message-ID
<xmqq7bikqvpm.fsf@gitster.g>
In-Reply-To
<01c3cc25738c43d61aff153805e02db872ff21de.1794335969.git.gitgitgadget@gmail.com>

"Srujith A Poojary via GitGitGadget" <gitgitgadget@gmail.com> writes:

Show 9 quoted lines
> diff --git a/submodule.c b/submodule.c
> index 6fcb606f7e..1302c11ddf 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -543,6 +543,7 @@ static void show_submodule_header(struct diff_options *o,
>  		struct commit **left, struct commit **right,
>  		struct commit_list **merge_bases)
>  {
> +	struct repository *repo = sub ? sub : o->repo;

Let's step back a bit. Use of any repository other than 'sub' is wrong as a way to correctly find suitable abbreviation of object names in the 'sub' repository. Now, the variable sub is NULL when the submodule is not initialized, in which case we won't know how many hexdigits we need to abbreviate "one" and "two" to, because there is no repository that has any object from that submodule to begin with.

Show 9 quoted lines
> @@ -599,9 +600,9 @@ static void show_submodule_header(struct diff_options *o,
>  
>  output_header:
>  	strbuf_addf(&sb, "Submodule %s ", path);
> -	strbuf_add_unique_abbrev(&sb, one, DEFAULT_ABBREV);
> +	strbuf_repo_add_unique_abbrev(&sb, repo, one, DEFAULT_ABBREV);
>  	strbuf_addstr(&sb, (fast_backward || fast_forward) ? ".." : "...");
> -	strbuf_add_unique_abbrev(&sb, two, DEFAULT_ABBREV);
> +	strbuf_repo_add_unique_abbrev(&sb, repo, two, DEFAULT_ABBREV);

And that means the above patch is an utterly wrong rewrite, isn't it?

Because using o->repo is just as wrong as using the_repository, replacing strbuf_add_unique_abbrev(), which uses the_repository, with a call to strbuf_repo_add_unique_abbrev() and using o->repo does not fix anything.

So when (sub == NULL), the code probably should just grab the first DEFAULT_ABBREV hexdigits of one and two and be done with it. Guaranteeing uniqueness of the abbreviations within o->repo does not help anybody anyway, right?

On the other hand, when (sub != NULL), the rewrite in this patch is absolutely the right thing to do. Thanks for working on it.

Previous: Srujith A Poojary via GitGitGadgetNext: Srujith Poojary
Message 13 of 23 in “archive: remove USE_THE_REPOSITORY_VARIABLE from archival modules”
  1. 0/2 [Outreachy PATCH] archive: remove USE_THE_REPOSITORY_VARIABLE from archival modulesSrujith A Poojary via GitGitGadget, Nov 9, 2026
  2. 1/2 submodule: use the submodule repository to abbreviate commitsSrujith A Poojary via GitGitGadget, Nov 9, 2026
  3. 2/2 archive: remove USE_THE_REPOSITORY_VARIABLE from archival modulesSrujith A Poojary via GitGitGadget, Nov 9, 2026
  4. Junio C HamanoNov 9, 2026
  5. Srujith PoojaryNov 10, 2026
  6. 0/2 [Outreachy PATCH] archive: remove USE_THE_REPOSITORY_VARIABLE from archival modulesSrujith A Poojary via GitGitGadget, Nov 10, 2026
  7. 1/2 submodule: use the submodule repository to abbreviate commitsSrujith A Poojary via GitGitGadget, Nov 10, 2026
  8. 2/2 archive: remove USE_THE_REPOSITORY_VARIABLE from archival modulesSrujith A Poojary via GitGitGadget, Nov 10, 2026
  9. Junio C HamanoNov 10, 2026
  10. Srujith PoojaryNov 10, 2026
  11. 0/2 [Outreachy PATCH] archive: remove USE_THE_REPOSITORY_VARIABLE from archival modulesSrujith A Poojary via GitGitGadget, Nov 10, 2026
  12. 1/2 submodule: use the submodule repository to abbreviate commitsSrujith A Poojary via GitGitGadget, Nov 10, 2026
  13. Junio C HamanoNov 10, 2026
  14. Srujith PoojaryNov 11, 2026
  15. 2/2 archive: remove USE_THE_REPOSITORY_VARIABLE from archival modulesSrujith A Poojary via GitGitGadget, Nov 10, 2026
  16. Junio C HamanoNov 10, 2026
  17. Srujith PoojaryNov 11, 2026
  18. Srujith PoojaryNov 11, 2026
  19. Junio C HamanoNov 10, 2026
  20. archive: remove USE_THE_REPOSITORY_VARIABLE from archival modulesSrujith A Poojary via GitGitGadget, Nov 11, 2026
  21. Karthik NayakNov 11, 2026
  22. Srujith PoojaryNov 11, 2026
  23. archive-tar: add comments explaining configuration precedenceSrujith A Poojary via GitGitGadget, Nov 11, 2026

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.