diff options
Diffstat (limited to 'pw-apply.sh')
-rwxr-xr-x | pw-apply.sh | 53 |
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 |