This is an automated email from the ASF dual-hosted git repository.
ndimiduk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/yetus.git
The following commit(s) were added to refs/heads/main by this push:
new 8bff1d01 YETUS-1276. Add --patch-mode flag to control diff-vs-patch
preference (#385)
8bff1d01 is described below
commit 8bff1d01b0ee3938b4263dfc309e34cbe0d32e95
Author: Nick Dimiduk <[email protected]>
AuthorDate: Thu May 21 11:19:40 2026 +0200
YETUS-1276. Add --patch-mode flag to control diff-vs-patch preference (#385)
YETUS-983 hardcoded dryrun_both_files to prefer cumulative .diff over
per-commit .patch. This may not work for all projects (binary handling
is a known concern), so make the preference configurable.
--patch-mode=diff (default) preserves YETUS-983 behavior.
--patch-mode=patch restores pre-YETUS-983 behavior.
The non-preferred format is always tried as fallback.
---
precommit/src/main/shell/core.d/01-common.sh | 5 ++++
precommit/src/main/shell/core.d/patchfiles.sh | 39 +++++++++++++++++++--------
precommit/src/main/shell/test-patch.sh | 1 +
3 files changed, 34 insertions(+), 11 deletions(-)
diff --git a/precommit/src/main/shell/core.d/01-common.sh
b/precommit/src/main/shell/core.d/01-common.sh
index a81668fa..329b7e67 100755
--- a/precommit/src/main/shell/core.d/01-common.sh
+++ b/precommit/src/main/shell/core.d/01-common.sh
@@ -201,6 +201,11 @@ function common_args
delete_parameter "${i}"
PATCH=${i#*=}
;;
+ --patch-mode=*)
+ delete_parameter "${i}"
+ #shellcheck disable=SC2034
+ PATCH_MODE=${i#*=}
+ ;;
--patch-dir=*)
delete_parameter "${i}"
PATCH_DIR=${i#*=}
diff --git a/precommit/src/main/shell/core.d/patchfiles.sh
b/precommit/src/main/shell/core.d/patchfiles.sh
index d8dd4d5d..6684a14b 100755
--- a/precommit/src/main/shell/core.d/patchfiles.sh
+++ b/precommit/src/main/shell/core.d/patchfiles.sh
@@ -26,6 +26,7 @@ PATCH_METHOD=""
PATCH_METHODS=("gitapply" "patchcmd")
PATCH_LEVEL=0
PATCH_HINT=""
+PATCH_MODE="diff"
## @description Use curl to download the patch as a last resort
## @audience private
@@ -340,23 +341,39 @@ function patchfile_dryrun_driver
return 1
}
-## @description dryrun both PATCH and DIFF and determine which one to use
+## @description dryrun both PATCH and DIFF and determine which one to use.
+## @description PATCH_MODE controls try-order: "diff" (default) avoids
stale-file
+## @description bugs from per-commit .patch stanzas (YETUS-983); "patch"
restores
+## @description the pre-YETUS-983 behavior for repos that need it.
## @replaceable no
## @audience private
## @stability evolving
function dryrun_both_files
{
- # prefer the cumulative diff: it represents the PR's net change and avoids
- # stale-file bugs when per-commit .patch stanzas add then rename/delete files
- # (YETUS-983). Binary files are preserved when the diff is generated locally
- # with --binary.
- if [[ -f "${INPUT_DIFF_FILE}" ]] && patchfile_dryrun_driver
"${INPUT_DIFF_FILE}"; then
- INPUT_APPLY_TYPE="diff"
- INPUT_APPLIED_FILE="${INPUT_DIFF_FILE}"
+ declare first_file
+ declare first_type
+ declare second_file
+ declare second_type
+
+ if [[ "${PATCH_MODE}" == "patch" ]]; then
+ first_file="${INPUT_PATCH_FILE}"
+ first_type="patch"
+ second_file="${INPUT_DIFF_FILE}"
+ second_type="diff"
+ else
+ first_file="${INPUT_DIFF_FILE}"
+ first_type="diff"
+ second_file="${INPUT_PATCH_FILE}"
+ second_type="patch"
+ fi
+
+ if [[ -f "${first_file}" ]] && patchfile_dryrun_driver "${first_file}"; then
+ INPUT_APPLY_TYPE="${first_type}"
+ INPUT_APPLIED_FILE="${first_file}"
return 0
- elif [[ -f "${INPUT_PATCH_FILE}" ]] && patchfile_dryrun_driver
"${INPUT_PATCH_FILE}"; then
- INPUT_APPLY_TYPE="patch"
- INPUT_APPLIED_FILE="${INPUT_PATCH_FILE}"
+ elif [[ -f "${second_file}" ]] && patchfile_dryrun_driver "${second_file}";
then
+ INPUT_APPLY_TYPE="${second_type}"
+ INPUT_APPLIED_FILE="${second_file}"
return 0
else
return 1
diff --git a/precommit/src/main/shell/test-patch.sh
b/precommit/src/main/shell/test-patch.sh
index b471ccf9..2e26f1ff 100755
--- a/precommit/src/main/shell/test-patch.sh
+++ b/precommit/src/main/shell/test-patch.sh
@@ -675,6 +675,7 @@ function yetus_usage
yetus_add_option "--multijdktests=<list>" "Comma delimited tests to use when
multijdkdirs is used. (default: '${jdktlist}')"
yetus_add_option "--offline" "Avoid connecting to the network"
yetus_add_option "--patch-dir=<dir>" "The directory for working and output
files (default '/tmp/test-patch-${PROJECT_NAME}/pid')"
+ yetus_add_option "--patch-mode=<diff|patch>" "Try cumulative diff or
per-commit patch first (default: '${PATCH_MODE}')"
yetus_add_option "--personality=<file>" "The personality file to load"
yetus_add_option "--plugins=<list>" "Specify which plug-ins to add/delete
(comma delimited; use 'all' for all found) e.g. --plugins=all,-ant,-scalac (all
plugins except ant and scalac)"
yetus_add_option "--proclimit=<num>" "Limit on the number of processes
(default: ${PROC_LIMIT})"