yetus-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject yetus git commit: YETUS-33. committer mode for smart-apply-patch (aw)
Date Fri, 09 Oct 2015 04:06:52 GMT
Repository: yetus
Updated Branches:
  refs/heads/master 19fe8bc87 -> 82b4d0a54


YETUS-33. committer mode for smart-apply-patch (aw)

Signed-off-by: Allen Wittenauer <aw@apache.org>


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

Branch: refs/heads/master
Commit: 82b4d0a548a89f203266a39144eabc004332389d
Parents: 19fe8bc
Author: Allen Wittenauer <aw@apache.org>
Authored: Thu Oct 8 13:01:10 2015 -0700
Committer: Allen Wittenauer <aw@apache.org>
Committed: Thu Oct 8 21:05:19 2015 -0700

----------------------------------------------------------------------
 .../latest/precommit-smart-apply-patch.md       | 51 +++++++++++++++
 dev-support/core.d/common.sh                    |  9 ++-
 dev-support/smart-apply-patch.sh                | 65 +++++++++++++++++---
 3 files changed, 114 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/yetus/blob/82b4d0a5/asf-site-src/source/documentation/latest/precommit-smart-apply-patch.md
----------------------------------------------------------------------
diff --git a/asf-site-src/source/documentation/latest/precommit-smart-apply-patch.md b/asf-site-src/source/documentation/latest/precommit-smart-apply-patch.md
new file mode 100644
index 0000000..74dc0c3
--- /dev/null
+++ b/asf-site-src/source/documentation/latest/precommit-smart-apply-patch.md
@@ -0,0 +1,51 @@
+<!---
+  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.
+-->
+
+smart-apply-patch
+=================
+
+`smart-apply-patch` is a command to help apply patches easily.  It uses the same plug-ins
and many of the same options as test-patch.  This means that it can, for example, fetch patches
from JIRA and apply them to a local source tree.
+
+# Usage
+
+Its simpliest form is used when a patch is stored in a local file:
+
+```bash
+$ smart-apply-patch patch
+```
+
+This will cause the command to run through various ways to verify and then apply the patch
to the current repo, including deducing a patch level.
+
+Perhaps you just want to see if the patch even applies without changing your local repo.
 The `--dry-run` option will just test for applicability:
+
+```bash
+$ smart-apply-patch --dry-run patch
+```
+
+For committers of projects, there is a special mode:
+
+```bash
+$ smart-apply-patch --committer patch
+```
+
+that in addition to applying the patch will also attempt to:
+
+* use `--whitespace=fix` mode
+* add all newly created files in the repo
+* use `--signoff` and commit the change via git-am

http://git-wip-us.apache.org/repos/asf/yetus/blob/82b4d0a5/dev-support/core.d/common.sh
----------------------------------------------------------------------
diff --git a/dev-support/core.d/common.sh b/dev-support/core.d/common.sh
index bc13b8a..7fe108c 100755
--- a/dev-support/core.d/common.sh
+++ b/dev-support/core.d/common.sh
@@ -172,7 +172,7 @@ function yetus_error
 ## @param        string
 function yetus_debug
 {
-  if [[ -n "${YETUS_SHELL_SCRIPT_DEBUG}" ]]; then
+  if [[ "${YETUS_SHELL_SCRIPT_DEBUG}" = true ]]; then
     echo "[$(date) DEBUG]: $*" 1>&2
   fi
 }
@@ -423,7 +423,7 @@ function patchfile_verify_zero
   declare dir
   declare changed_files1
   declare changed_files2
-  declare $filename
+  declare filename
 
   # don't return /dev/null
   # shellcheck disable=SC2016
@@ -554,6 +554,11 @@ function patchfile_dryrun_driver
 function gitapply_apply
 {
   declare patchfile=$1
+  declare extraopts
+
+  if [[ "${COMMITMODE}" = true ]]; then
+    extraopts="--whitespace=fix"
+  fi
 
   echo "Applying the patch:"
   yetus_run_and_redirect "${PATCH_DIR}/apply-patch-git-apply.log" \

http://git-wip-us.apache.org/repos/asf/yetus/blob/82b4d0a5/dev-support/smart-apply-patch.sh
----------------------------------------------------------------------
diff --git a/dev-support/smart-apply-patch.sh b/dev-support/smart-apply-patch.sh
index abd4513..bf5e5bf 100755
--- a/dev-support/smart-apply-patch.sh
+++ b/dev-support/smart-apply-patch.sh
@@ -1,15 +1,18 @@
 #!/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
+# 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
+#     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.
+# 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.
 
 # Make sure that bash version meets the pre-requisite
 
@@ -83,6 +86,7 @@ function yetus_usage
 {
   echo "Usage: apply-patch.sh [options] patch-file | issue-number | http"
   echo
+  echo "--committer            Apply patches like a boss."
   echo "--debug                If set, then output some extra stuff to stderr"
   echo "--dry-run              Check for patch viability without applying"
   echo "--modulelist=<list>    Specify additional modules to test (comma delimited)"
@@ -129,6 +133,9 @@ function parse_args
 
   for i in "$@"; do
     case ${i} in
+      --committer)
+        COMMITMODE=true
+      ;;
       --dry-run)
         PATCH_DRYRUNMODE=true
       ;;
@@ -152,6 +159,36 @@ function parse_args
   fi
 }
 
+## @description  git am dryrun
+## @replaceable  no
+## @audience     private
+## @stability    evolving
+function gitam_dryrun
+{
+
+  # there is no dryrun method for git-am, so just
+  # use apply instead.
+  gitapply_dryrun "$@"
+
+  if [[ -n ${PATCH_METHOD}="gitapply" ]]; then
+    PATCH_METHOD="gitam"
+  fi
+}
+
+## @description  git am signoff
+## @replaceable  no
+## @audience     private
+## @stability    evolving
+function gitam_apply
+{
+  declare patchfile=$1
+
+  echo "Applying the patch:"
+  yetus_run_and_redirect "${PATCH_DIR}/apply-patch-git-am.log" \
+    "${GIT}" am --signoff --whitespace=fix "-p${PATCH_LEVEL}" "${patchfile}"
+  ${GREP} -v "^Checking" "${PATCH_DIR}/apply-patch-git-am.log"
+}
+
 trap "cleanup_and_exit 1" HUP INT QUIT TERM
 
 setup_defaults
@@ -170,6 +207,10 @@ plugins_initialize
 
 locate_patch
 
+if [[ ${COMMITMODE} = true ]]; then
+  PATCH_METHODS=("gitam" "${PATCH_METHODS[@]}")
+fi
+
 patchfile_dryrun_driver "${PATCH_DIR}/patch"
 RESULT=$?
 
@@ -183,4 +224,10 @@ if [[ ${PATCH_DRYRUNMODE} == false ]]; then
   RESULT=$?
 fi
 
+if [[ ${COMMITMODE} = true
+   && ${PATCH_METHOD} != "gitam" ]]; then
+  yetus_debug "Running git add -A"
+  git add -A
+fi
+
 cleanup_and_exit ${RESULT}


Mime
View raw message