You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by cm...@apache.org on 2014/11/24 21:40:57 UTC

hadoop git commit: HADOOP-10926. Improve smart-apply-patch.sh to apply binary diffs (cmccabe)

Repository: hadoop
Updated Branches:
  refs/heads/trunk 380a361cf -> 2967c17fe


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


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/2967c17f
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/2967c17f
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/2967c17f

Branch: refs/heads/trunk
Commit: 2967c17fef0fabe9683437a1b13475e7480ec9a3
Parents: 380a361
Author: Colin Patrick Mccabe <cm...@cloudera.com>
Authored: Mon Nov 24 11:50:38 2014 -0800
Committer: Colin Patrick Mccabe <cm...@cloudera.com>
Committed: Mon Nov 24 12:40:49 2014 -0800

----------------------------------------------------------------------
 dev-support/smart-apply-patch.sh                | 47 ++++++++++++++++++++
 hadoop-common-project/hadoop-common/CHANGES.txt |  2 +
 2 files changed, 49 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/2967c17f/dev-support/smart-apply-patch.sh
----------------------------------------------------------------------
diff --git a/dev-support/smart-apply-patch.sh b/dev-support/smart-apply-patch.sh
index 49f083c..3542fb4 100755
--- a/dev-support/smart-apply-patch.sh
+++ b/dev-support/smart-apply-patch.sh
@@ -13,6 +13,40 @@
 
 set -e
 
+#
+# Determine if the patch file is a git diff file with prefixes.
+# These files are generated via "git diff" *without* the --no-prefix option.
+#
+# We can apply these patches more easily because we know that the a/ and b/
+# prefixes in the "diff" lines stands for the project root directory.
+# So we don't have to hunt for the project root.
+# And of course, we know that the patch file was generated using git, so we
+# know git apply can handle it properly.
+#
+# Arguments: file name.
+# Return: 0 if it is a git diff; 1 otherwise.
+#
+is_git_diff_with_prefix() {
+  DIFF_TYPE="unknown"
+  while read -r line; do
+    if [[ "$line" =~ ^diff\  ]]; then
+      if [[ "$line" =~ ^diff\ \-\-git ]]; then
+        DIFF_TYPE="git"
+      else
+        return 1 # All diff lines must be diff --git lines.
+      fi
+    fi
+    if [[ "$line" =~ ^\+\+\+\  ]] ||
+       [[ "$line" =~ ^\-\-\-\  ]]; then
+      if ! [[ "$line" =~ ^....[ab]/ ]]; then
+        return 1 # All +++ and --- lines must start with a/ or b/.
+      fi
+    fi
+  done < $1
+  [ x$DIFF_TYPE == x"git" ] || return 1
+  return 0 # return true (= 0 in bash)
+}
+
 PATCH_FILE=$1
 DRY_RUN=$2
 if [ -z "$PATCH_FILE" ]; then
@@ -37,6 +71,19 @@ if [ "$PATCH_FILE" == "-" ]; then
   TOCLEAN="$TOCLEAN $PATCH_FILE"
 fi
 
+# Special case for git-diff patches without --no-prefix
+if is_git_diff_with_prefix "$PATCH_FILE"; then
+  GIT_FLAGS="--binary -p1 -v"
+  if [[ -z $DRY_RUN ]]; then
+      GIT_FLAGS="$GIT_FLAGS --stat --apply "
+      echo Going to apply git patch with: git apply "${GIT_FLAGS}"
+  else
+      GIT_FLAGS="$GIT_FLAGS --check "
+  fi
+  git apply ${GIT_FLAGS} "${PATCH_FILE}"
+  exit $?
+fi
+
 # Come up with a list of changed files into $TMP
 TMP=/tmp/tmp.paths.$$
 TOCLEAN="$TOCLEAN $TMP"

http://git-wip-us.apache.org/repos/asf/hadoop/blob/2967c17f/hadoop-common-project/hadoop-common/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt
index eda6399..fe1eb8e 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -143,6 +143,8 @@ Trunk (Unreleased)
 
     HADOOP-11208. Replace "daemon" with better name in script subcommands (aw)
 
+    HADOOP-10926. Improve smart-apply-patch.sh to apply binary diffs (cmccabe)
+
   BUG FIXES
 
     HADOOP-9451. Fault single-layer config if node group topology is enabled.