Repository: hive Updated Branches: refs/heads/master 5f12cb844 -> 2a89e83c2
HIVE-17988: Replace patch utility usage with git apply in ptest (Daniel Voros reviewed by Sergio Peña via Zoltan Haindrich) Signed-off-by: Zoltan Haindrich <k...@rxd.hu> Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/33841171 Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/33841171 Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/33841171 Branch: refs/heads/master Commit: 338411718ed4a73c1182d5e717230bfc33855d12 Parents: 5f12cb8 Author: Daniel Voros <daniel.vo...@gmail.com> Authored: Mon Dec 4 09:09:17 2017 +0100 Committer: Zoltan Haindrich <k...@rxd.hu> Committed: Mon Dec 4 09:09:17 2017 +0100 ---------------------------------------------------------------------- .../src/main/resources/smart-apply-patch.sh | 38 ++++++++------------ 1 file changed, 15 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/33841171/testutils/ptest2/src/main/resources/smart-apply-patch.sh ---------------------------------------------------------------------- diff --git a/testutils/ptest2/src/main/resources/smart-apply-patch.sh b/testutils/ptest2/src/main/resources/smart-apply-patch.sh index 5a133d5..6f69083 100644 --- a/testutils/ptest2/src/main/resources/smart-apply-patch.sh +++ b/testutils/ptest2/src/main/resources/smart-apply-patch.sh @@ -20,12 +20,10 @@ if [ -z "$PATCH_FILE" ]; then exit 1 fi -PATCH=${PATCH:-patch} # allow overriding patch binary - # Cleanup handler for temporary files TOCLEAN="" cleanup() { - rm $TOCLEAN + [ "x$TOCLEAN" != "x" ] && rm $TOCLEAN exit $1 } trap "cleanup 1" HUP INT QUIT TERM @@ -37,29 +35,26 @@ if [ "$PATCH_FILE" == "-" ]; then TOCLEAN="$TOCLEAN $PATCH_FILE" fi -# Come up with a list of changed files into $TMP -TMP=/tmp/tmp.paths.$$ -TOCLEAN="$TOCLEAN $TMP" - -if $PATCH -p0 -E --dry-run < $PATCH_FILE 2>&1 > $TMP; then +if git apply -p0 -3 --check $PATCH_FILE 2>&1 > /dev/null; then PLEVEL=0 - #if the patch applied at P0 there is the possability that all we are doing + + # if the patch applied at P0 there is the possibility that all we are doing # is adding new files and they would apply anywhere. So try to guess the # correct place to put those files. - TMP2=/tmp/tmp.paths.2.$$ - TOCLEAN="$TOCLEAN $TMP2" + CHANGED_FILES=/tmp/tmp.paths.2.$$ + TOCLEAN="$TOCLEAN $CHANGED_FILES" - egrep '^patching file |^checking file ' $TMP | awk '{print $3}' | grep -v /dev/null | sort | uniq > $TMP2 + git apply -p0 -3 --stat $PATCH_FILE | head -1 | awk '{print $1}' > $CHANGED_FILES - if [ ! -s $TMP2 ]; then + if [ ! -s $CHANGED_FILES ]; then echo "Error: Patch dryrun couldn't detect changes the patch would make. Exiting." cleanup 1 fi #first off check that all of the files do not exist FOUND_ANY=0 - for CHECK_FILE in $(cat $TMP2) + for CHECK_FILE in $(cat $CHANGED_FILES) do if [[ -f $CHECK_FILE ]]; then FOUND_ANY=1 @@ -71,21 +66,18 @@ if $PATCH -p0 -E --dry-run < $PATCH_FILE 2>&1 > $TMP; then # if all of the lines start with a/ or b/, then this is a git patch that # was generated without --no-prefix - if ! grep -qv '^a/\|^b/' $TMP2 ; then + if ! grep -qv '^a/\|^b/' $CHANGED_FILES ; then echo Looks like this is a git patch. Stripping a/ and b/ prefixes echo and incrementing PLEVEL PLEVEL=$[$PLEVEL + 1] - sed -i -e 's,^[ab]/,,' $TMP2 + sed -i -e 's,^[ab]/,,' $CHANGED_FILES fi fi -elif $PATCH -p1 -E --dry-run < $PATCH_FILE 2>&1 > /dev/null; then +elif git apply -p1 -3 --check $PATCH_FILE 2>&1 > /dev/null; then PLEVEL=1 -elif $PATCH -p2 -E --dry-run < $PATCH_FILE 2>&1 > /dev/null; then +elif git apply -p2 -3 --check $PATCH_FILE 2>&1 > /dev/null; then PLEVEL=2 -elif git apply -p0 --check $PATCH_FILE 2>&1 > /dev/null; then - git apply -p0 $PATCH_FILE - cleanup $? else echo "The patch does not appear to apply with p0, p1, or p2"; cleanup 1; @@ -96,7 +88,7 @@ if [[ -n $DRY_RUN ]]; then cleanup 0; fi -echo Going to apply patch with: $PATCH -p$PLEVEL -$PATCH -p$PLEVEL -E < $PATCH_FILE +echo Going to apply patch with: git apply -p$PLEVEL +git apply -p$PLEVEL -3 $PATCH_FILE cleanup $? \ No newline at end of file