mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] scripts: git-resolve: ignore non-commit objects
@ 2026-11-03 16:42 Hamdy Abou El Anein
  2026-11-03 17:26 ` Sasha Levin
  0 siblings, 1 reply; 2+ messages in thread
From: Hamdy Abou El Anein @ 2026-11-03 16:42 UTC (permalink / raw)
  To: sashal; +Cc: hamdy.aea, linux-kernel

From: Hamdy Abou El Anein <hamdy.aea@protonmail.com>

git rev-parse --disambiguate lists objects of every type. A unique blob
or tree prefix is therefore returned successfully as a commit ID. Such
an ID cannot be used as a commit reference or Fixes tag.

Filter the candidates by object type before deciding whether the prefix
is unique or looking up its subject.

Tested in a temporary Git repository: a real commit prefix resolves to
its full ID, while a stored blob prefix is rejected with no output.

AI assistance: ChatGPT/Codex identified the issue and prepared the
change, commit message and executable regression tests.

Fixes: 7ae52a3d7f51 ("scripts: Add git-resolve tool for full SHA-1 resolution")
Signed-off-by: Hamdy Abou El Anein <hamdy.aea@protonmail.com>
---
 scripts/git-resolve.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/scripts/git-resolve.sh b/scripts/git-resolve.sh
index e9b5940c0f2..0be8838cd13 100755
--- a/scripts/git-resolve.sh
+++ b/scripts/git-resolve.sh
@@ -49,7 +49,9 @@ git_resolve_commit() {
 
 	# Get all possible matching commit IDs
 	local matches
-	readarray -t matches < <(git rev-parse --disambiguate="$commit_id" 2>/dev/null)
+	readarray -t matches < <(git rev-parse --disambiguate="$commit_id" 2>/dev/null |
+		git cat-file --batch-check='%(objectname) %(objecttype)' |
+		awk '$2 == "commit" { print $1 }')
 
 	# Return immediately if we have exactly one match
 	if [ ${#matches[@]} -eq 1 ]; then

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] scripts: git-resolve: ignore non-commit objects
  2026-11-03 16:42 [PATCH] scripts: git-resolve: ignore non-commit objects Hamdy Abou El Anein
@ 2026-11-03 17:26 ` Sasha Levin
  0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2026-11-03 17:26 UTC (permalink / raw)
  To: Hamdy Abou El Anein; +Cc: Hamdy Abou El Anein, linux-kernel, Sasha Levin

On Tue, Nov 03, 2026 at 05:42:02PM +0100, Hamdy Abou El Anein wrote:
>git rev-parse --disambiguate lists objects of every type. A unique blob
>or tree prefix is therefore returned successfully as a commit ID. Such
>an ID cannot be used as a commit reference or Fixes tag.
>
>Filter the candidates by object type before deciding whether the prefix
>is unique or looking up its subject.

This also fixes a more common case: an abbreviated ID that collides only
with trees or blobs used to fail unless a subject was given. 117 of the
last 2000 commits in linux.git have a 7 character abbreviation like that.

The argument check at the bottom of the script still counts every object
type, so a prefix that matches only a blob now exits 1 without printing
the "does not match any git commit" error. Could you send a follow-up
that filters that check the same way?

Acked-by: Sasha Levin <sashal@kernel.org>

-- 
Thanks,
Sasha

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-03 17:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03 16:42 [PATCH] scripts: git-resolve: ignore non-commit objects Hamdy Abou El Anein
2026-11-03 17:26 ` Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®