mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hamdy Abou El Anein <info@daylightlinux.ch>
To: sashal@kernel.org
Cc: hamdy.aea@protonmail.com, linux-kernel@vger.kernel.org
Subject: [PATCH v2] scripts: git-resolve: search beyond ten body-only matches
Date: Wed,  4 Nov 2026 06:43:40 +0100	[thread overview]
Message-ID: <20261104054340.10911-1-info@daylightlinux.ch> (raw)
In-Reply-To: <20261103164202.129634-1-info@daylightlinux.ch>

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

The forced subject lookup asks git log for at most ten matches before
checking their subjects. Since --grep also searches message bodies, ten
newer body-only matches can hide an older commit with the requested
subject.

Match commit subjects directly, so body-only matches cannot hide an
older subject and grep stops at the first matching subject.

Tested with a target commit followed by eleven commits whose bodies,
but not subjects, match the query. Forced lookup returns the target.

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 | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/scripts/git-resolve.sh b/scripts/git-resolve.sh
index 7d14cf279e86..f04a56c5fba0 100755
--- a/scripts/git-resolve.sh
+++ b/scripts/git-resolve.sh
@@ -74,13 +74,8 @@ git_resolve_commit() {
 		if [ ${#matches[@]} -eq 0 ] && [ $force -eq 1 ]; then
 			# Use git log to search, but filter to ensure subject matches exactly
 			local match
-			match=$(git log --format="%H %s" --grep="$grep_pattern" --perl-regexp -10 | \
-					while read -r hash subject; do
-						if echo "$subject" | grep -qP "$grep_pattern"; then
-							echo "$hash"
-							break
-						fi
-					done)
+			match=$(git log --format="%H %s" | \
+				grep -m1 -P "^[0-9a-f]+ ${grep_pattern#^}" | cut -d" " -f1)
 			if [ -n "$match" ]; then
 				echo "$match"
 				return 0
-- 
2.56.0


      parent reply	other threads:[~2026-11-04  5:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 16:42 [PATCH] " Hamdy Abou El Anein
2026-11-03 17:26 ` Sasha Levin
2026-11-04  5:43 ` Hamdy Abou El Anein [this message]

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=20261104054340.10911-1-info@daylightlinux.ch \
    --to=info@daylightlinux.ch \
    --cc=hamdy.aea@protonmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sashal@kernel.org \
    /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

all inboxes | Powered by JetHome®