sentry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sp...@apache.org
Subject sentry git commit: SENTRY-2212: smart-apply-patch.sh isn't so smart, won't apply changes when files have been moved or renamed (Steve Moist, reviewed by Sergio Pena)
Date Mon, 30 Apr 2018 15:27:01 GMT
Repository: sentry
Updated Branches:
  refs/heads/master 68f568a69 -> 0668237aa


SENTRY-2212: smart-apply-patch.sh isn't so smart, won't apply changes when files have been
moved or renamed (Steve Moist, reviewed by Sergio Pena)

Change-Id: I458fd0d5261ffacc2afb1dcea9fcf52f1d8058ac


Project: http://git-wip-us.apache.org/repos/asf/sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/0668237a
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/0668237a
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/0668237a

Branch: refs/heads/master
Commit: 0668237aa703e24602afb75a90e127839fb67e15
Parents: 68f568a
Author: Sergio Pena <sergio.pena@cloudera.com>
Authored: Mon Apr 30 10:25:54 2018 -0500
Committer: Sergio Pena <sergio.pena@cloudera.com>
Committed: Mon Apr 30 10:26:49 2018 -0500

----------------------------------------------------------------------
 dev-support/smart-apply-patch.sh | 35 +++++++++++++++--------------------
 1 file changed, 15 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sentry/blob/0668237a/dev-support/smart-apply-patch.sh
----------------------------------------------------------------------
diff --git a/dev-support/smart-apply-patch.sh b/dev-support/smart-apply-patch.sh
index fce2735..6f69083 100755
--- a/dev-support/smart-apply-patch.sh
+++ b/dev-support/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,17 +66,17 @@ 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
 else
   echo "The patch does not appear to apply with p0, p1, or p2";
@@ -93,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


Mime
View raw message