HADOOP-10926. Improve test-patch.sh to apply binary diffs (cmccabe)

This commit is contained in:
Colin Patrick Mccabe 2014-10-27 18:22:28 -07:00
parent 518a7f4af3
commit b0e19c9d54
2 changed files with 32 additions and 7 deletions

View File

@ -37,11 +37,31 @@ if [ "$PATCH_FILE" == "-" ]; then
TOCLEAN="$TOCLEAN $PATCH_FILE" TOCLEAN="$TOCLEAN $PATCH_FILE"
fi fi
# Was the patch generated by git? If so, we can definitely use 'git apply' to
# apply it. This is nice because it allows us to handle binary files. If
# not, we fall back to applying the patch with "patch", since that's most
# likely what was used to create it.
if git --version &>/dev/null && grep -q -- '^diff --git' "$PATCH_FILE"; then
PATCH_TYPE="git"
PATCH_DRY_RUN="git apply --check"
PATCH_APPLY="git apply"
else
PATCH_TYPE="non-git"
PATCH_DRY_RUN="patch --dry-run -E"
PATCH_APPLY="patch -E"
fi
# Come up with a list of changed files into $TMP # Come up with a list of changed files into $TMP
TMP=/tmp/tmp.paths.$$ TMP=/tmp/tmp.paths.$$
TOCLEAN="$TOCLEAN $TMP" TOCLEAN="$TOCLEAN $TMP"
if $PATCH -p0 -E --dry-run < $PATCH_FILE 2>&1 > $TMP; then # This file contains the error messages from all patch application attempts.
# We only print it when the script fails.
DRY_RUN_ERRORS=/tmp/dry-run-errors.$$
TOCLEAN="$TOCLEAN $DRY_RUN_ERRORS"
touch $DRY_RUN_ERRORS
if $PATCH_DRY_RUN -p0 < $PATCH_FILE 2>>$DRY_RUN_ERRORS 1> $TMP; then
PLEVEL=0 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 possability that all we are doing
# is adding new files and they would apply anywhere. So try to guess the # is adding new files and they would apply anywhere. So try to guess the
@ -59,7 +79,7 @@ if $PATCH -p0 -E --dry-run < $PATCH_FILE 2>&1 > $TMP; then
#first off check that all of the files do not exist #first off check that all of the files do not exist
FOUND_ANY=0 FOUND_ANY=0
for CHECK_FILE in $(cat $TMP2) for CHECK_FILE in $(cat -- $TMP2)
do do
if [[ -f $CHECK_FILE ]]; then if [[ -f $CHECK_FILE ]]; then
FOUND_ANY=1 FOUND_ANY=1
@ -97,12 +117,15 @@ if $PATCH -p0 -E --dry-run < $PATCH_FILE 2>&1 > $TMP; then
cleanup 1 cleanup 1
fi fi
fi fi
elif $PATCH -p1 -E --dry-run < $PATCH_FILE 2>&1 > /dev/null; then elif $PATCH_DRY_RUN -p1 < $PATCH_FILE 2>>$DRY_RUN_ERRORS 1> /dev/null; then
PLEVEL=1 PLEVEL=1
elif $PATCH -p2 -E --dry-run < $PATCH_FILE 2>&1 > /dev/null; then elif $PATCH_DRY_RUN -p2 < $PATCH_FILE 2>>$DRY_RUN_ERRORS 1> /dev/null; then
PLEVEL=2 PLEVEL=2
else else
echo "The patch does not appear to apply with p0 to p2"; echo "The ${PATCH_TYPE} patch does not appear to apply with p0 to p2.";
echo
echo "Dry run errors:"
cat -- $DRY_RUN_ERRORS
cleanup 1; cleanup 1;
fi fi
@ -111,7 +134,7 @@ if [[ -n $DRY_RUN ]]; then
cleanup 0; cleanup 0;
fi fi
echo Going to apply patch with: $PATCH -p$PLEVEL echo Going to apply ${PATCH_TYPE} patch with: ${PATCH_APPLY} -p$PLEVEL
$PATCH -p$PLEVEL -E < $PATCH_FILE ${PATCH_APPLY} -p$PLEVEL < $PATCH_FILE
cleanup $? cleanup $?

View File

@ -137,6 +137,8 @@ Trunk (Unreleased)
HADOOP-11231. Remove dead code in ServletUtil. (Li Lu via wheat9) HADOOP-11231. Remove dead code in ServletUtil. (Li Lu via wheat9)
HADOOP-10926. Improve test-patch.sh to apply binary diffs. (cmccabe)
BUG FIXES BUG FIXES
HADOOP-9451. Fault single-layer config if node group topology is enabled. HADOOP-9451. Fault single-layer config if node group topology is enabled.