Git development
 help / color / mirror / Atom feed
From: "Srujith A Poojary via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Srujith A Poojary <poojarysrujith@gmail.com>,
	Srujith A Poojary <poojarysrujith@gmail.com>
Subject: [PATCH 1/2] submodule: use the submodule repository to abbreviate commits
Date: Mon, 09 Nov 2026 19:04:59 +0000	[thread overview]
Message-ID: <01c3cc25738c43d61aff153805e02db872ff21de.1794251100.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2305.git.1794251100.gitgitgadget@gmail.com>

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.

As the expected abbreviation depends on the hash algorithm used,
the test uses the test_oid mechanism to switch the expectation
between SHA-1 and SHA-256 repositories.

Signed-off-by: Srujith A Poojary <poojarysrujith@gmail.com>
---
 submodule.c                      |  5 +++--
 t/t4041-diff-submodule-option.sh | 23 +++++++++++++++++++++++
 2 files changed, 26 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..4539d6bba5 100755
--- a/t/t4041-diff-submodule-option.sh
+++ b/t/t4041-diff-submodule-option.sh
@@ -14,6 +14,29 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
 . ./test-lib.sh
 
+test_expect_success 'submodule commit abbreviation uses submodule object database' '
+	test_oid_cache <<-EOF &&
+	submodule_commit1_abbrev sha1:0000000000e
+	submodule_commit1_abbrev sha256:24c81a5
+	EOF
+	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 %s..%s:\n  > child\n" \
+		"$(test_oid submodule_commit1_abbrev)" \
+		"$(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


  reply	other threads:[~2026-11-09 19:05 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 19:04 [PATCH 0/2] [Outreachy PATCH] archive: remove USE_THE_REPOSITORY_VARIABLE from archival modules Srujith A Poojary via GitGitGadget
2026-11-09 19:04 ` Srujith A Poojary via GitGitGadget [this message]
2026-11-09 19:05 ` [PATCH 2/2] " Srujith A Poojary via GitGitGadget
2026-11-09 20:45   ` Junio C Hamano
2026-11-10  8:13     ` Srujith Poojary
2026-11-10  6:03 ` [PATCH v2 0/2] [Outreachy PATCH] " Srujith A Poojary via GitGitGadget
2026-11-10  6:03   ` [PATCH v2 1/2] submodule: use the submodule repository to abbreviate commits Srujith A Poojary via GitGitGadget
2026-11-10  6:03   ` [PATCH v2 2/2] archive: remove USE_THE_REPOSITORY_VARIABLE from archival modules Srujith A Poojary via GitGitGadget
2026-11-10 16:07     ` Junio C Hamano
2026-11-10 18:33       ` Srujith Poojary
2026-11-10 18:39 ` [PATCH v3 0/2] [Outreachy PATCH] " Srujith A Poojary via GitGitGadget
2026-11-10 18:39   ` [PATCH v3 1/2] submodule: use the submodule repository to abbreviate commits Srujith A Poojary via GitGitGadget
2026-11-10 20:26     ` Junio C Hamano
2026-11-11  4:19       ` Srujith Poojary
2026-11-10 18:39   ` [PATCH v3 2/2] archive: remove USE_THE_REPOSITORY_VARIABLE from archival modules Srujith A Poojary via GitGitGadget
2026-11-10 20:40     ` Junio C Hamano
2026-11-11  4:17       ` Srujith Poojary
2026-11-11  8:34       ` Srujith Poojary
2026-11-10 19:17   ` [PATCH v3 0/2] [Outreachy PATCH] " Junio C Hamano
2026-11-11  8:25 ` [PATCH v4] " Srujith A Poojary via GitGitGadget
2026-11-11 11:08   ` Karthik Nayak
2026-11-11 12:24     ` Srujith Poojary
2026-11-11 12:45 ` [PATCH v5] archive-tar: add comments explaining configuration precedence Srujith A Poojary via GitGitGadget

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=01c3cc25738c43d61aff153805e02db872ff21de.1794251100.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=poojarysrujith@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox