You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@yetus.apache.org by aw...@apache.org on 2018/08/21 14:51:14 UTC
yetus git commit: YETUS-45. the test patch script should check for
filenames that differ only in case
Repository: yetus
Updated Branches:
refs/heads/master 12f4fe040 -> 31d2ca6a5
YETUS-45. the test patch script should check for filenames that differ only in case
Signed-off-by: Sean Busbey <bu...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/yetus/repo
Commit: http://git-wip-us.apache.org/repos/asf/yetus/commit/31d2ca6a
Tree: http://git-wip-us.apache.org/repos/asf/yetus/tree/31d2ca6a
Diff: http://git-wip-us.apache.org/repos/asf/yetus/diff/31d2ca6a
Branch: refs/heads/master
Commit: 31d2ca6a5c89e35a659f7414ba7eadf6ef61c39a
Parents: 12f4fe0
Author: Allen Wittenauer <aw...@apache.org>
Authored: Sun Aug 19 21:23:58 2018 -0700
Committer: Allen Wittenauer <aw...@apache.org>
Committed: Tue Aug 21 07:49:50 2018 -0700
----------------------------------------------------------------------
precommit/test-patch.d/dupname.sh | 124 +++++++++++++++++++++++++++++++++
1 file changed, 124 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/yetus/blob/31d2ca6a/precommit/test-patch.d/dupname.sh
----------------------------------------------------------------------
diff --git a/precommit/test-patch.d/dupname.sh b/precommit/test-patch.d/dupname.sh
new file mode 100755
index 0000000..6795308
--- /dev/null
+++ b/precommit/test-patch.d/dupname.sh
@@ -0,0 +1,124 @@
+#!/usr/bin/env 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.
+
+# dupname check ALWAYS gets activated
+add_test_type dupname
+add_test dupname
+
+
+## @description Sort an array by its elements, ignoring case
+## @audience private
+## @stability evolving
+## @replaceable yes
+## @param arrayvar
+function dupname_icase_sort_array
+{
+ declare arrname=$1
+ declare arrref="${arrname}[@]"
+ declare array=("${!arrref}")
+
+ declare globstatus
+ declare oifs
+ declare -a sa
+
+ globstatus=$(set -o | grep noglob | awk '{print $NF}')
+
+ if [[ -n ${IFS} ]]; then
+ oifs=${IFS}
+ fi
+ set -f
+ # shellcheck disable=SC2034
+ IFS=$'\n' sa=($(sort -f <<<"${array[*]}"))
+ # shellcheck disable=SC1083
+ eval "${arrname}"=\(\"\${sa[@]}\"\)
+
+ if [[ -n "${oifs}" ]]; then
+ IFS=${oifs}
+ else
+ unset IFS
+ fi
+
+ if [[ "${globstatus}" = off ]]; then
+ set +f
+ fi
+}
+
+## @description Check the current patchfile for case issues
+## @audience private
+## @stability evolving
+## @replaceable no
+## @return 0 on success
+## @return 1 on failure
+function dupname_precheck
+{
+ declare -i count=0
+ declare cur
+ declare fn
+ declare prev
+ declare -a tmpfiles
+
+ tmpfiles=("${CHANGED_FILES[@]}")
+
+ big_console_header "Checking for duplicated filenames that differ only in case"
+ start_clock
+
+ pushd "${BASEDIR}" >/dev/null || return 1
+
+ # check the existing tree
+ for fn in "${CHANGED_FILES[@]}"; do
+ existing=$(${GIT} ls-files ":(icase)${fn}")
+ if [[ -n "${existing}" ]]; then
+ if [[ "${existing}" != "${fn}" ]]; then
+ echo "patch:${fn} tree:${existing}" >> "${PATCH_DIR}/dupnames.txt"
+ ((count=count + 1))
+ fi
+ fi
+ done
+
+ popd >/dev/null || return 1
+
+ dupname_icase_sort_array tmpfiles
+
+ for cur in "${tmpfiles[@]}"; do
+ if [[ -n ${prev} ]]; then
+ if [[ "${cur}" != "${prev}" ]]; then
+ curlc=$(echo "${cur}" | tr '[:upper:]' '[:lower:]')
+ if [[ "${curlc}" == "${prevlc}" ]]; then
+ echo "patch:${cur} patch:${prev}" >> "${PATCH_DIR}/dupnames.txt"
+ ((count=count + 1))
+ fi
+ fi
+ fi
+ prev=${cur}
+ prevlc=${curlc}
+ done
+
+ if [[ ${count} -gt 0 ]]; then
+ if [[ "${BUILDMODE}" != full ]]; then
+ add_vote_table -1 dupname "The patch has ${count}" \
+ " duplicated filenames that differ only in case."
+ add_footer_table dupname "@@BASE@@/dupnames.txt"
+ yetus_error "ERROR: Won't apply the patch; may break the workspace."
+ return 1
+ else
+ add_vote_table -1 dupname "Source has ${count}" \
+ " duplicated filenames that differ only in case."
+ add_footer_table dupname "@@BASE@@/dupnames.txt"
+ fi
+ fi
+
+ return 0
+}
\ No newline at end of file