From commits-return-1093-archive-asf-public=cust-asf.ponee.io@yetus.apache.org Tue Aug 21 16:51:15 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 712E2180630 for ; Tue, 21 Aug 2018 16:51:15 +0200 (CEST) Received: (qmail 56524 invoked by uid 500); 21 Aug 2018 14:51:14 -0000 Mailing-List: contact commits-help@yetus.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@yetus.apache.org Delivered-To: mailing list commits@yetus.apache.org Received: (qmail 56515 invoked by uid 99); 21 Aug 2018 14:51:14 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Aug 2018 14:51:14 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 10EA8DFCB9; Tue, 21 Aug 2018 14:51:14 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aw@apache.org To: commits@yetus.apache.org Message-Id: <8a0c672c2fab4f319f65ef14a4684f85@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: yetus git commit: YETUS-45. the test patch script should check for filenames that differ only in case Date: Tue, 21 Aug 2018 14:51:14 +0000 (UTC) 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 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 Authored: Sun Aug 19 21:23:58 2018 -0700 Committer: Allen Wittenauer 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