commit c61bf2e73af6db59f8f533cfc11473480a824145 Author: nspiegelberg Date: 19 minutes ago HBASE-5743 Support GIT patches with Hadoop QA diff --git dev-support/smart-apply-patch.sh dev-support/smart-apply-patch.sh new file mode 100755 index 0000000..e4cef6b --- /dev/null +++ dev-support/smart-apply-patch.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +PATCH_FILE=$1 +if [ -z "$PATCH_FILE" ]; then + echo usage: $0 patch-file + exit 1 +fi + +PATCH=${PATCH:-patch} # allow overriding patch binary + +# Cleanup handler for temporary files +TOCLEAN="" +cleanup() { + rm $TOCLEAN + exit $1 +} +trap "cleanup 1" HUP INT QUIT TERM + +# Allow passing "-" for stdin patches +if [ "$PATCH_FILE" == "-" ]; then + PATCH_FILE=/tmp/tmp.in.$$ + cat /dev/fd/0 > $PATCH_FILE + TOCLEAN="$TOCLEAN $PATCH_FILE" +fi + +# Come up with a list of changed files into $TMP +TMP=/tmp/tmp.paths.$$ +TOCLEAN="$TOCLEAN $TMP" +grep '^+++ \|^--- ' $PATCH_FILE | cut -c '5-' | grep -v /dev/null | sort | uniq > $TMP + +# Assume p0 to start +PLEVEL=0 + +# 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/' $TMP ; 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]/,,' $TMP +fi + +echo Going to apply patch with: $PATCH -p$PLEVEL +$PATCH -p$PLEVEL -E < $PATCH_FILE + +cleanup 0 diff --git dev-support/test-patch.sh dev-support/test-patch.sh index bdef3ab..71ed936 100755 --- dev-support/test-patch.sh +++ dev-support/test-patch.sh @@ -334,7 +334,8 @@ applyPatch () { echo "" echo "" - $PATCH -p0 -E < $PATCH_DIR/patch + export PATCH + $BASEDIR/dev-support/smart-apply-patch.sh $PATCH_DIR/patch if [[ $? != 0 ]] ; then echo "PATCH APPLICATION FAILED" JIRA_COMMENT="$JIRA_COMMENT