Skip to content

Commit d0c8cbd

Browse files
committed
git-backport-diff: Default to newest commit
It is more likely that a backport refers to a newer commit than to an old one. One reason not to do so is because a later commit may reference the existing commit in its message. To get around this, only look at commits that actually have a matching subject and ignore their message body. As a side effect, this generally makes the script faster because the git-log process is quit once the first valid match is found.
1 parent d8ee7c3 commit d0c8cbd

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

git-backport-diff

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,19 @@ compare_git()
228228
subj=${hashsubj:40}
229229
downhash=${hashsubj:0:40}
230230
# A little bit hackish, but find the match by looking at upstream
231-
# subject lines, and using the last one. Not all backports contain
231+
# subject lines, and using the newest one. Not all backports contain
232232
# the phrase "cherry-pick", so we can't really try and find the
233233
# upstream hash from that...
234-
uphash=`git log $upstream --pretty=format:"%H" --fixed-strings --grep="${subj}" |tail -n 1`
234+
uphash=""
235+
while read uphashsubj
236+
do
237+
if [[ "${uphashsubj:40}" == "$subj" ]]
238+
then
239+
uphash=${uphashsubj:0:40}
240+
break
241+
fi
242+
done < <(git log $upstream --pretty=tformat:"%H%s" --fixed-strings --grep="${subj}")
243+
235244
if [[ -n "$uphash" ]]
236245
then
237246
numdiff=`diff -u <(git diff $uphash^! |egrep ^[-+])\

0 commit comments

Comments
 (0)