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

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

From
SPSrujith Poojary <poojarysrujith@gmail.com>
Date
Nov 2, 2026, 19:49 UTC
Message-ID
<CABh_KWhHP0bxE0PAGvn-1=DNSoLUCmr_Aq6n-p3wC+VFXkCjZA@mail.gmail.com>
In-Reply-To
<a8c54b929255679ebd02ca06ef1f58de87448064.1793648430.git.gitgitgadget@gmail.com>

On Tue, Nov 3, 2026 at 1:10 AM Srujith A Poojary via GitGitGadget <gitgitgadget@gmail.com> wrote:

Show 73 quoted lines
>
> From: Srujith A Poojary <poojarysrujith@gmail.com>
>
> The commit IDs shown in a submodule diff header belong to the
> submodule's object database. However, strbuf_add_unique_abbrev()
> uses the_repository, so it checks the superproject's object
> database when abbreviating those IDs.
>
> Use the submodule repository when it is available, and fall back
> to the repository from the diff options when it is not.
>
> Signed-off-by: Srujith A Poojary <poojarysrujith@gmail.com>
> ---
>  submodule.c                      |  5 +++--
>  t/t4041-diff-submodule-option.sh | 18 ++++++++++++++++++
>  2 files changed, 21 insertions(+), 2 deletions(-)
>
> 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;
>         const char *message = NULL;
>         struct strbuf sb = STRBUF_INIT;
>         int fast_forward = 0, fast_backward = 0;
> @@ -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);
>         if (message)
>                 strbuf_addf(&sb, " %s\n", message);
>         else
> diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh
> index 4dd4954260..e80472af32 100755
> --- a/t/t4041-diff-submodule-option.sh
> +++ b/t/t4041-diff-submodule-option.sh
> @@ -14,6 +14,24 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
>
>  . ./test-lib.sh
>
> +test_expect_success SHA1 'submodule commit abbreviation uses submodule object database' '
> +       test_when_finished "rm -rf collision-super" &&
> +       git init -q collision-super &&
> +       git init -q collision-super/sm1 &&
> +       printf "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n\nb1rwzyc3\n" >collision-super/sm1/a0blgqsjc &&
> +       git -C collision-super/sm1 add a0blgqsjc &&
> +       tree=$(git -C collision-super/sm1 write-tree) &&
> +       commit1=$(GIT_AUTHOR_DATE="1112911993 -0700" GIT_COMMITTER_DATE="1112911993 -0700" git -C collision-super/sm1 commit-tree "$tree" -m a2onsxbvj) &&
> +       commit2=$(printf "child\n" | GIT_AUTHOR_DATE="1112912053 -0700" GIT_COMMITTER_DATE="1112912053 -0700" git -C collision-super/sm1 commit-tree "$tree" -p "$commit1") &&
> +       git -C collision-super/sm1 checkout -q "$commit2" &&
> +       git -C collision-super update-index --add --cacheinfo 160000,"$commit1",sm1 &&
> +       git -C collision-super commit -q -m "Add submodule" &&
> +       git -C collision-super diff --submodule=log >actual &&
> +       printf "Submodule sm1 0000000000e..%s:\n  > child\n" \
> +               "$(git -C collision-super/sm1 rev-parse --short "$commit2")" >expected &&
> +       test_cmp expected actual
> +'
> +
>  # Test non-UTF-8 encoding in case iconv is available.
>  if test_have_prereq ICONV
>  then
> --
> gitgitgadget
>
Hi Junio,
Thanks for the suggestion.

I've updated the t4041 test to use `test_oid_cache` with separate expected abbreviations for SHA-1 and SHA-256. I've also removed the SHA1-only prerequisite so that the test runs with both hash algorithms.

I tested the updated test script using both configurations:
- SHA-1: all 48 tests passed.
- SHA-256: all 48 tests passed.

I've updated the commit message, added the Signed-off-by trailer, and submitted the revised v4 patch series.

The updated patch series is available here: https://lore.kernel.org/git/pull.2288.v4.git.1793648490.gitgitgadget@gmail.com/

Thanks for the suggestion and review.

Regards, Srujith

Previous: Srujith A Poojary via GitGitGadgetNext: Srujith A Poojary via GitGitGadget
Message 11 of 18 in “t4041: use submodule repository for commit abbreviations”
  1. [Outreachy PATCH] t4041: use submodule repository for commit abbreviationsSrujith A Poojary via GitGitGadget, Oct 31, 2026
  2. Okhuomon AjayiOct 31, 2026
  3. Srujith PoojaryOct 31, 2026
  4. Submodule: use the submodule repository to abbreviate commitsSrujith A Poojary via GitGitGadget, Oct 31, 2026
  5. Okhuomon AjayiOct 31, 2026
  6. Srujith PoojaryOct 31, 2026
  7. submodule: use the submodule repository to abbreviate commitsSrujith A Poojary via GitGitGadget, Oct 31, 2026
  8. Junio C HamanoNov 1, 2026
  9. 0/2 [Outreachy PATCH] t4041: use submodule repository for commit abbreviationsSrujith A Poojary via GitGitGadget, Nov 2, 2026
  10. 1/2 submodule: use the submodule repository to abbreviate commitsSrujith A Poojary via GitGitGadget, Nov 2, 2026
  11. Srujith PoojaryNov 2, 2026
  12. 2/2 t4041: test SHA-256 submodule abbreviationsSrujith A Poojary via GitGitGadget, Nov 2, 2026
  13. Junio C HamanoNov 3, 2026
  14. Srujith PoojaryNov 4, 2026
  15. Junio C HamanoNov 3, 2026
  16. submodule: use the submodule repository to abbreviate commitsSrujith A Poojary via GitGitGadget, Nov 4, 2026
  17. Junio C HamanoNov 4, 2026
  18. submodule: use the submodule repository to abbreviate commitsSrujith A Poojary via GitGitGadget, Nov 4, 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.