This is an automated email from the ASF dual-hosted git repository. aw pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/yetus.git
commit 721f544a4763aebfc73aaec70740e8ad9e95889b Author: Allen Wittenauer <a...@apache.org> AuthorDate: Sun Dec 30 16:07:05 2018 -0800 YETUS-750. don't try patch on a git format-patch file Signed-off-by: Allen Wittenauer <a...@apache.org> --- precommit/src/main/shell/core.d/01-common.sh | 6 ----- precommit/src/main/shell/core.d/patchfiles.sh | 37 +++++++++++++++++++++++++-- precommit/src/main/shell/smart-apply-patch.sh | 2 +- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/precommit/src/main/shell/core.d/01-common.sh b/precommit/src/main/shell/core.d/01-common.sh index e292336..db87e97 100755 --- a/precommit/src/main/shell/core.d/01-common.sh +++ b/precommit/src/main/shell/core.d/01-common.sh @@ -49,12 +49,6 @@ function common_defaults PATCH_DIR=/tmp/yetus-${RANDOM}.${RANDOM} done #shellcheck disable=SC2034 - PATCH_METHOD="" - #shellcheck disable=SC2034 - PATCH_METHODS=("gitapply" "patchcmd") - #shellcheck disable=SC2034 - PATCH_LEVEL=0 - #shellcheck disable=SC2034 PATCH_SYSTEM="" PROJECT_NAME=unknown # seed $RANDOM diff --git a/precommit/src/main/shell/core.d/patchfiles.sh b/precommit/src/main/shell/core.d/patchfiles.sh index 381573c..e0db5fc 100755 --- a/precommit/src/main/shell/core.d/patchfiles.sh +++ b/precommit/src/main/shell/core.d/patchfiles.sh @@ -14,6 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +PATCH_METHOD="" +PATCH_METHODS=("gitapply" "patchcmd") +PATCH_LEVEL=0 +PATCH_HINT="" + ## @description Use curl to download the patch as a last resort ## @audience private ## @stability evolving @@ -73,6 +78,28 @@ function guess_patch_file patchfile_dryrun_driver "${patch}" } +## @description Provide a hint on what tool should be used to process a patch file +## @description Sets PATCH_HINT to provide the hint. Will not do anything if +## @description PATCH_HINT or PATCH_METHOD is already set +## @audience private +## @stability evolving +## @replaceable no +## @param path to patch file to test +function patch_file_hinter +{ + declare patch=$1 + + if [[ -z "${PATCH_HINT}" ]] && [[ -z "${PATCH_METHOD}" ]]; then + if head -n 1 "${patch}" | "${GREP}" -q -E "^From [a-z0-9]* Mon Sep 17 00:00:00 2001" && + "${GREP}" -q "^From: " "${patch}" && + "${GREP}" -q "^Subject: \[PATCH" "${patch}" && + "${GREP}" -q "^---" "${patch}"; then + PATCH_HINT="git" + return + fi + fi +} + ## @description Given ${PATCH_OR_ISSUE}, determine what type of patch file is in use, ## @description and do the necessary work to place it into ${PATCH_DIR}/patch. ## @audience private @@ -204,7 +231,7 @@ function gitapply_dryrun declare patchfile=$1 declare prefixsize=${2:-0} - while [[ ${prefixsize} -lt 4 + while [[ ${prefixsize} -lt 2 && -z ${PATCH_METHOD} ]]; do if yetus_run_and_redirect "${PATCH_DIR}/patch-dryrun.log" \ "${GIT}" apply --binary -v --check "-p${prefixsize}" "${patchfile}"; then @@ -234,7 +261,7 @@ function patchcmd_dryrun declare patchfile=$1 declare prefixsize=${2:-0} - while [[ ${prefixsize} -lt 4 + while [[ ${prefixsize} -lt 2 && -z ${PATCH_METHOD} ]]; do # shellcheck disable=SC2153 if yetus_run_and_redirect "${PATCH_DIR}/patch-dryrun.log" \ @@ -265,8 +292,14 @@ function patchfile_dryrun_driver declare patchfile=$1 declare method + patch_file_hinter "${patchfile}" + #shellcheck disable=SC2153 for method in "${PATCH_METHODS[@]}"; do + if [[ -n "${PATCH_HINT}" ]] && + [[ ! "${method}" =~ ${PATCH_HINT} ]]; then + continue + fi if declare -f "${method}_dryrun" >/dev/null; then "${method}_dryrun" "${patchfile}" fi diff --git a/precommit/src/main/shell/smart-apply-patch.sh b/precommit/src/main/shell/smart-apply-patch.sh index bf44a8f..bdee4cb 100755 --- a/precommit/src/main/shell/smart-apply-patch.sh +++ b/precommit/src/main/shell/smart-apply-patch.sh @@ -324,7 +324,7 @@ if [[ ${COMMITMODE} = true ]]; then fi PATCH_METHODS=("gitam" "${PATCH_METHODS[@]}") fi - +patch_file_hinter "${PATCH_DIR}/patch" patchfile_dryrun_driver "${PATCH_DIR}/patch" RESULT=$?