Skip to content

Commit

Permalink
backporting: Detect only one related commit
Browse files Browse the repository at this point in the history
[ upstream commit 9abbbbf ]

Recently, the check-stable script has suggested every single possible
match for commits where the name does not uniquely identify the commit.
This can be a bit confusing to backporters since it looks like there are
many commits to backport as part of this PR, but the second and later
ones are not necessary to backport.

 * PR: 16589 -- vagrant: Bump all Vagrant box versions (@pchaigno) -- #16589
   Merge with 1 commit(s) merged at: Tue, 22 Jun 2021 12:36:17 -0700!
     Branch:     master (!)                          refs/pull/16589/head
                 ----------                          -------------------
     v (start)
     |  edf76fb
5bef5d7
4dc60e6
816b323
51826b3
df8238d
a4e7bc6 via fb723f8 ("vagrant: Bump all Vagrant box versions")
     v (end)

Probably within the last year of commits, we should be able to correlate
the exact commit that needs backporting, so iterate through those to
find the exact commit. If none of those are the correct commit, fail out
and push back to the backporter to figure out.

This allows us to now accurately pick the correct commit in most cases:

 * PR: 16589 -- vagrant: Bump all Vagrant box versions (@pchaigno) -- #16589
   Merge with 1 commit(s) merged at: Tue, 22 Jun 2021 12:36:17 -0700!
     Branch:     master (!)                          refs/pull/16589/head
                 ----------                          -------------------
     v (start)
     |  edf76fb via fb723f8 ("vagrant: Bump all Vagrant box versions")
     v (end)

Manually tested by substituting a known commit into 'related_commits',
and by checking the current v1.8 backports which includes an ambiguous
commit due to a revert+reapply in the master branch.

Signed-off-by: Joe Stringer <joe@cilium.io>
Signed-off-by: Paul Chaignon <paul@cilium.io>
  • Loading branch information
joestringer authored and vadorovsky committed Jul 30, 2021
1 parent bd5c699 commit 30a1362
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions contrib/backporting/check-stable
Expand Up @@ -156,11 +156,17 @@ generate_commit_list_for_pr () {
entry_sha=${entry_array[1]}
entry_sub=${entry_array[@]:2}
entry_sub_re="^$(sed 's/[.^$*+?()[{\|]/\\&/g' <<< "$entry_sub")$" # adds backslashes for extended regex
upstream_commit="$(git log --since="1year" --pretty="%H" --no-merges --extended-regexp --grep "$entry_sub_re" $REMOTE/master)"
upstream_id="$(git log -n1 --pretty=format:"%ae%at" $upstream_commit)"
if [ "$entry_id" == "${upstream_id}" ]; then
echo -e " | ${upstream_commit} via $entry_sha (\"$entry_sub\")"
else
related_commits="$(git log --since="1year" --pretty="%H" --no-merges --extended-regexp --grep "$entry_sub_re" $REMOTE/master)"
found_commit=0
for upstream_commit in ${related_commits}; do
upstream_id="$(git log -n1 --pretty=format:"%ae%at" $upstream_commit)"
if [ "$entry_id" == "${upstream_id}" ]; then
echo -e " | ${upstream_commit} via $entry_sha (\"$entry_sub\")"
found_commit=1
break
fi
done
if [ "$found_commit" -ne 1 ]; then
echo -e " | Warning: No commit correlation found! via $entry_sha (\"$entry_sub\")"
fi
done < $tmp_file
Expand Down

0 comments on commit 30a1362

Please sign in to comment.