summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Lyon <christophe.lyon@linaro.org>2024-02-27 19:22:33 +0000
committerChristophe Lyon <christophe.lyon@linaro.org>2024-03-01 14:23:19 +0000
commit56c1b1628c9f4150439d51a5fbf4b8063395aad1 (patch)
treed8611747addd5067cf3d5d4a04e87ae8cb3979ca
parenta1e55d37823dda77cfdcb28e4dbb61600c600323 (diff)
pw-apply.sh: Try to apply patches with -p1 then with -p0
Some contributors do not use git format-patch, and their patches do not include the "a/" and "b/" path prefixes, making 'git am' fail, since it defaults to using '-p1' to suppress that leading prefix. If applying the patches with -p1 fails, this patch retries with -p0. This will help us handle more patches in precommit CI. Change-Id: I91ccc267c6ec1d08974f2530c98096c65f7b2fee
-rwxr-xr-xpw-apply.sh53
1 files changed, 37 insertions, 16 deletions
diff --git a/pw-apply.sh b/pw-apply.sh
index 04c8346b..a016a912 100755
--- a/pw-apply.sh
+++ b/pw-apply.sh
@@ -116,28 +116,49 @@ trap "" EXIT
prev_head=$(git -C "$project" rev-parse HEAD)
res=0
-# Apply the whole series and then roll-back to the desired patch.
-if ! git -C "$project" pw series apply "$series_id"; then
- echo "WARNING: Series $series_id did not apply cleanly"
- # "git am" sometimes detects email text as a patch, and complains that it
- # has no actual code changes. Workaround this by skipping empty patches.
- res=4
- patch_file="$project/.git/rebase-apply/patch"
- while [ "$res" = "4" ] \
- && [ -f "$patch_file" ] && ! [ -s "$patch_file" ]; do
- # The patch is empty, so skip it.
- res=0
- if ! git -C "$project" am --skip; then
- res=4
- fi
- done
-fi
+apply_series()
+{
+ local patch_paths="$1"
+ local res=0
+
+ # Apply the whole series and then roll-back to the desired patch.
+ if ! git -C "$project" pw series apply "$series_id" "$patch_paths"; then
+ echo "WARNING: Series $series_id did not apply cleanly"
+ # "git am" sometimes detects email text as a patch, and complains that it
+ # has no actual code changes. Workaround this by skipping empty patches.
+ res=4
+ patch_file="$project/.git/rebase-apply/patch"
+ while [ "$res" = "4" ] \
+ && [ -f "$patch_file" ] && ! [ -s "$patch_file" ]; do
+ # The patch is empty, so skip it.
+ res=0
+ if ! git -C "$project" am --skip; then
+ res=4
+ fi
+ done
+ fi
+ return $res
+}
+
+# Try to apply patches with -p1 first
+apply_series "-p1" &
+res=0 && wait $! || res=$?
# It can happen that the patch series was merged between the trigger and
# this build. Make sure that we have applied enough patches to test
# something interesting.
patches_applied=$(git -C "$project" rev-list --count HEAD "^$prev_head")
+# If we couldn't apply any patch, retry with -p0
+if [ "$res" != "0" ] && [ "$patches_applied" = "0" ]; then
+ # Restore a clean state
+ git -C "$project" am --abort || true
+ git -C "$project" checkout --detach $prev_head
+ apply_series "-p0" &
+ res=0 && wait $! || res=$?
+ patches_applied=$(git -C "$project" rev-list --count HEAD "^$prev_head")
+fi
+
if [ "$patches_applied" -le "$num_patch" ]; then
apply_result="fail"
if [ "$res" = "0" ] && [ "$patches_applied" = "0" ]; then