# patch-scripts: Implemented (format and apply ).

Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/82a93c5c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/82a93c5c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/82a93c5c

Branch: refs/heads/ignite-593
Commit: 82a93c5cdb0d8cad85af5e8de57e9fde0c1a1a97
Parents: 3af6914
Author: Artem Shutak <ashu...@gridgain.com>
Authored: Fri Apr 3 16:30:44 2015 +0300
Committer: Artem Shutak <ashu...@gridgain.com>
Committed: Fri Apr 3 16:30:44 2015 +0300

----------------------------------------------------------------------
 .gitignore                     |   2 +-
 scripts/git-apply-patch.sh     |  88 ++++++++++++++++++++++++
 scripts/git-format-patch.sh    |  84 +++++++++++++++++++++++
 scripts/git-patch-functions.sh | 132 ++++++++++++++++++++++++++++++++++++
 scripts/git-patch-prop.sh      |  28 ++++++++
 5 files changed, 333 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/82a93c5c/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index cd1e894..296e130 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,6 +17,6 @@ xcuserdata/
 atlassian-ide-plugin.xml
 *.iml
 target
-target/*
 /libs/
 pom-installed.xml
+git-patch-prop-local.sh
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/82a93c5c/scripts/git-apply-patch.sh
----------------------------------------------------------------------
diff --git a/scripts/git-apply-patch.sh b/scripts/git-apply-patch.sh
new file mode 100644
index 0000000..448421b
--- /dev/null
+++ b/scripts/git-apply-patch.sh
@@ -0,0 +1,88 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+#
+# Git patch-file applyer.
+#
+echo 'Usage: scripts/git-apply-patch.sh <ignite-task> [-ih|--ignitehome 
<path>] [-idb|--ignitedefbranch <branch-name>] [-ph|--patchhome <path>]'
+echo "It should be called from IGNITE_HOME directory."
+echo "Patch will be applied to DEFAULT_BRANCH from PATCHES_HOME."
+echo "Note: you can use ${IGNITE_HOME}/scripts/git-patch-prop-local.sh to set 
your own local properties (to rewrite settings at git-patch-prop-local.sh). "
+echo
+
+#
+# Ignite task.
+#
+IGNITE_TASK=$1
+
+#
+# Read command line params.
+#
+while [[ $# > 1 ]]
+do
+    key="$1"
+
+    case $key in
+        -ih|--ignitehome)
+        IGNITE_HOME="$2"
+        shift
+        ;;
+        -idb|--ignitedefbranch)
+        IGNITE_DEFAULT_BRANCH="$2"
+        shift
+        ;;
+        -ph|--patchhome)
+        PATCHES_HOME="$2"
+        shift
+        ;;
+        *)
+                # unknown option
+        ;;
+    esac
+    shift
+done
+
+if [ -z ${IGNITE_HOME} ] # Script can be called from not IGNITE_HOME if 
IGNITE_HOME was set.
+    then IGNITE_HOME=$PWD
+fi
+
+. ${IGNITE_HOME}/scripts/git-patch-prop.sh # Import properties.
+. ${IGNITE_HOME}/scripts/git-patch-functions.sh # Import patch functions.
+
+if [ -f ${IGNITE_HOME}/scripts/git-patch-prop-local.sh ] # Whether a local 
user properties file exists.
+    then . ${IGNITE_HOME}/scripts/git-patch-prop-local.sh # Import user 
properties (it will rewrite global properties).
+fi
+
+echo "IGNITE_HOME    : ${IGNITE_HOME}"
+echo "Master branch  : ${IGNITE_DEFAULT_BRANCH}"
+echo "Ignite task    : ${IGNITE_TASK}"
+echo
+echo "PATCHES_HOME   : ${PATCHES_HOME}"
+echo
+
+#
+# Main script logic.
+#
+
+currentAndDefaultBranchesShouldBeEqual ${IGNITE_HOME} ${IGNITE_DEFAULT_BRANCH}
+
+requireCleanWorkTree ${IGNITE_HOME}
+
+IGNITE_PATCH_FILE=${PATCHES_HOME}/${IGNITE_DEFAULT_BRANCH}_${IGNITE_TASK}_ignite.patch
+
+applyPatch ${IGNITE_HOME} ${IGNITE_DEFAULT_BRANCH} ${IGNITE_PATCH_FILE}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/82a93c5c/scripts/git-format-patch.sh
----------------------------------------------------------------------
diff --git a/scripts/git-format-patch.sh b/scripts/git-format-patch.sh
new file mode 100644
index 0000000..575a7bb
--- /dev/null
+++ b/scripts/git-format-patch.sh
@@ -0,0 +1,84 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+#
+# Git patch-file maker.
+#
+echo 'Usage: scripts/git-format-patch.sh [-ih|--ignitehome <path>] 
[-idb|--ignitedefbranch <branch-name>] [-ph|--patchhome <path>]'
+echo "It should be called from IGNITE_HOME directory."
+echo "Patch will be created at PATCHES_HOME between Master branch 
(IGNITE_DEFAULT_BRANCH) and Current branch."
+echo "Note: you can use ${IGNITE_HOME}/scripts/git-patch-prop-local.sh to set 
your own local properties (to rewrite settings at git-patch-prop-local.sh). "
+echo
+
+#
+# Read command line params.
+#
+while [[ $# > 1 ]]
+do
+    key="$1"
+
+    case $key in
+        -ih|--ignitehome)
+        IGNITE_HOME="$2"
+        shift
+        ;;
+        -idb|--ignitedefbranch)
+        IGNITE_DEFAULT_BRANCH="$2"
+        shift
+        ;;
+        -ph|--patchhome)
+        PATCHES_HOME="$2"
+        shift
+        ;;
+        *)
+                # unknown option
+        ;;
+    esac
+    shift
+done
+
+#
+# Init home and import properties and functions.
+#
+if [ -z ${IGNITE_HOME} ] # Script can be called from not IGNITE_HOME if 
IGNITE_HOME was set.
+    then IGNITE_HOME=$PWD
+fi
+
+. ${IGNITE_HOME}/scripts/git-patch-prop.sh # Import properties.
+. ${IGNITE_HOME}/scripts/git-patch-functions.sh # Import patch functions.
+
+if [ -f ${IGNITE_HOME}/scripts/git-patch-prop-local.sh ] # Whether a local 
user properties file exists.
+    then . ${IGNITE_HOME}/scripts/git-patch-prop-local.sh # Import user 
properties (it will rewrite global properties).
+fi
+
+IGNITE_CURRENT_BRANCH=$( determineCurrentBranch ${IGNITE_HOME} )
+
+echo "IGNITE_HOME    : ${IGNITE_HOME}"
+echo "Master branch  : ${IGNITE_DEFAULT_BRANCH}"
+echo "Current branch : ${IGNITE_CURRENT_BRANCH}"
+echo
+echo "PATCHES_HOME   : ${PATCHES_HOME}"
+echo
+
+#
+# Main script logic.
+#
+
+requireCleanWorkTree ${IGNITE_HOME}
+
+formatPatch ${IGNITE_HOME} ${IGNITE_DEFAULT_BRANCH} ${IGNITE_CURRENT_BRANCH} 
_ignite.patch
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/82a93c5c/scripts/git-patch-functions.sh
----------------------------------------------------------------------
diff --git a/scripts/git-patch-functions.sh b/scripts/git-patch-functions.sh
new file mode 100644
index 0000000..ab9bec3
--- /dev/null
+++ b/scripts/git-patch-functions.sh
@@ -0,0 +1,132 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+#
+# Git patch functions.
+#
+
+#
+# Define functions.
+#
+formatPatch () {
+    GIT_HOME=$1
+    DEFAULT_BRANCH=$2
+    PATCHED_BRANCH=$3
+    PATCH_SUFFIX=$4
+
+    cd ${GIT_HOME}
+
+    git checkout ${DEFAULT_BRANCH}
+    git checkout -b tmppatch
+    
+    git merge --no-edit ${PATCHED_BRANCH}
+#    Or we can 'squashe' merge to make only one commit.
+#    git merge --squash ${PATCHED_BRANCH}
+#    git commit -a -m "# PATCHED_BRANCH"
+
+    
PATCH_FILE=${PATCHES_HOME}'/'${DEFAULT_BRANCH}_${PATCHED_BRANCH}${PATCH_SUFFIX}
+
+    git format-patch ${DEFAULT_BRANCH}  --stdout > ${PATCH_FILE}
+    echo "Patch file created."
+
+    git checkout ${PATCHED_BRANCH}
+    
+    git branch -D tmppatch # Delete tmp branch.
+    
+    echo 
+    echo "Patch created: ${PATCH_FILE}"
+}
+
+determineCurrentBranch () {
+    GIT_HOME=$1
+    
+    cd ${GIT_HOME}
+    
+    CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
+    
+    echo "$CURRENT_BRANCH"
+}
+
+requireCleanWorkTree () {
+    cd $1 # At git home.
+
+    # Update the index
+    git update-index -q --ignore-submodules --refresh
+    err=0
+
+    # Disallow unstaged changes in the working tree
+    if ! git diff-files --quiet --ignore-submodules --
+    then
+        echo $0", ERROR:"
+        echo >&2 "You have unstaged changes."
+        git diff-files --name-status -r --ignore-submodules -- >&2
+        err=1
+    fi
+
+    # Disallow uncommitted changes in the index
+    if ! git diff-index --cached --quiet HEAD --ignore-submodules --
+    then
+        echo $0", ERROR:"
+        echo >&2 "Your index contains uncommitted changes."
+        git diff-index --cached --name-status -r --ignore-submodules HEAD -- 
>&2
+        err=1
+    fi
+
+    if [ $err = 1 ]
+    then
+        echo >&2 "Please commit or stash them."
+        exit 1
+    fi
+}
+
+applyPatch () {
+    GIT_HOME=$1
+    DEFAULT_BRANCH=$2
+    PATCH_FILE=$3
+
+    cd ${GIT_HOME}
+    
+    if [ ! -f ${PATCH_FILE} ]
+    then
+        echo $0", ERROR:"
+        echo "Expected patch file not found: $PATCH_FILE."
+        
+        exit 1
+    fi
+
+    echo "Patch $PATCH_FILE will be applied to $DEFAULT_BRANCH branch."
+#    git apply ${PATCH_FILE}
+    git am ${PATCH_FILE}
+}
+
+currentAndDefaultBranchesShouldBeEqual () {
+    GIT_HOME=$1
+    DEFAULT_BRANCH=$2
+
+    cd ${GIT_HOME}
+
+    CURRENT_BRANCH=$( determineCurrentBranch ${GIT_HOME} )
+    
+    if [ "$CURRENT_BRANCH" != "$DEFAULT_BRANCH" ]
+    then 
+        echo $0", ERROR:"
+        echo "You are not on an expected branch. Your current branch at 
$GIT_HOME is $CURRENT_BRANCH, should be $DEFAULT_BRANCH."
+        
+        exit 1
+    fi
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/82a93c5c/scripts/git-patch-prop.sh
----------------------------------------------------------------------
diff --git a/scripts/git-patch-prop.sh b/scripts/git-patch-prop.sh
new file mode 100644
index 0000000..7eb3639
--- /dev/null
+++ b/scripts/git-patch-prop.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+#
+# Git patch-file maker/applyer properties.
+#
+if [ "${IGNITE_DEFAULT_BRANCH}" = "" ]
+    then IGNITE_DEFAULT_BRANCH='sprint-2'
+fi
+
+if [ "${PATCHES_HOME}" = "" ]
+    then PATCHES_HOME=${GG_HOME}
+fi
\ No newline at end of file

Reply via email to