Ticket #138: scripts_1437eaaa5a5b.patch
File scripts_1437eaaa5a5b.patch, 5.7 KB (added by , 16 years ago) |
---|
-
new file scripts/check-sources.sh
# HG changeset patch # User Balazs Dezso <deba@inf.elte.hu> # Date 1222913319 -7200 # Node ID 1437eaaa5a5b583f9f91479c09b732c7ec363039 # Parent cbe3ec2d59d2d7c539ab62f2ca6796c960795237 New code checker script and improvements in unifier (ticket #138) The new check-sources.sh script checks the same things as unify-sources.sh, but it does not modify the files, just checks the conformity. It can be used as commit checker hg hook (for instructions see the comments in the file). The way how we enumerate the code files is changed in unify-sources.sh because the manifest command enumerates the already removed files, which raise error in the script. diff --git a/scripts/check-sources.sh b/scripts/check-sources.sh new file mode 100755
- + 1 #!/bin/bash 2 3 # Add to your .hg/hgrc the following section. 4 # [hooks] 5 # pretxncommit.checksources = scripts/check-sources.sh 6 7 YEAR=`date +2003-%Y` 8 HGROOT=`hg root` 9 10 TAB=`echo -e '\t'` 11 12 function check_header() { 13 HEADER=\ 14 "/* -*- mode: C++; indent-tabs-mode: nil; -*- 15 * 16 * This file is a part of LEMON, a generic C++ optimization library. 17 * 18 * Copyright (C) "$YEAR" 19 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 20 * (Egervary Research Group on Combinatorial Optimization, EGRES). 21 * 22 * Permission to use, modify and distribute this software is granted 23 * provided that this copyright notice appears in all copies. For 24 * precise terms see the accompanying LICENSE file. 25 * 26 * This software is provided \"AS IS\" with no warranty of any kind, 27 * express or implied, and with no claim as to its suitability for any 28 * purpose. 29 * 30 */" 31 32 HEADER_LENGTH=$(echo "$HEADER" | wc -l) 33 FILE_HEADER=$(cat $1 | head -n $HEADER_LENGTH) 34 35 [[ "$FILE_HEADER" != "$HEADER" ]] 36 } 37 38 function check_file() { 39 echo 'check' $1 ... 40 41 FILE_FAILED=NO 42 if check_header $1 43 then 44 echo "header failed" 45 FILE_FAILED=YES 46 GLOBAL_FAILED=YES 47 fi 48 49 if grep -q -E "$TAB" $1 50 then 51 echo "tabs failed:" 52 grep -n -E "$TAB" $1 53 FILE_FAILED=YES 54 GLOBAL_FAILED=YES 55 fi 56 57 if grep -q -E ' $' $1 58 then 59 echo "trailing spaces failed:" 60 grep -n -E ' $' $1 61 FILE_FAILED=YES 62 GLOBAL_FAILED=YES 63 fi 64 65 if grep -q -E '.{81,}' $1 66 then 67 echo "long lines failed:" 68 grep -n -E '.{81,}' $1 69 if [ $GLOBAL_FAILED != YES ] 70 then 71 echo -n "Abort commit? (yes/no) " 72 read RESULT 73 if [ "$RESULT" != "no" ] 74 then 75 FILE_FAILED=YES 76 GLOBAL_FAILED=YES 77 fi 78 fi 79 fi 80 81 if [[ $FILE_FAILED = YES ]]; 82 then 83 ((FAILED_FILES++)) 84 fi 85 } 86 87 FAILED_FILES=0 88 TOTAL_FILES=0 89 GLOBAL_FAILED=NO 90 91 function changed_files() { 92 { 93 if [ -n "$HG_PARENT1" ] 94 then 95 hg status --rev $HG_PARENT1:$HG_NODE -a -m 96 fi 97 if [ -n "$HG_PARENT2" ] 98 then 99 hg status --rev $HG_PARENT2:$HG_NODE -a -m 100 fi 101 } | cut -d ' ' -f 2 | grep -E '\.(cc|h|dox)$' | sort | uniq 102 } 103 104 if [ $# == 0 ]; then 105 echo Check all modified files... 106 107 while read FILENAME 108 do 109 check_file "$HGROOT/$FILENAME" 110 ((TOTAL_FILES++)) 111 done < <(changed_files) 112 echo ' done.' 113 else 114 for i in $@ 115 do 116 check_file $i 117 ((TOTAL_FILES++)) 118 done 119 fi 120 121 echo $FAILED_FILES out of $TOTAL_FILES files has failed. 122 123 [[ $GLOBAL_FAILED == NO ]] -
scripts/unify-sources.sh
diff --git a/scripts/unify-sources.sh b/scripts/unify-sources.sh
a b 25 25 * 26 26 */ 27 27 " 28 28 awk 'BEGIN { pm=0; } 29 29 pm==3 { print } 30 30 /\/\* / && pm==0 { pm=1;} 31 31 /[^:blank:]/ && (pm==0 || pm==2) { pm=3; print;} 32 32 /\*\// && pm==1 { pm=2;} 33 33 ' $1 34 34 ) >$TMP_FILE 35 35 36 36 HEADER_CH=`diff -q $TMP_FILE $FILE_NAME >/dev/null&&echo NO||echo YES` 37 37 … … 79 79 CHANGED=NO; 80 80 if [[ $HEADER_CH = YES ]]; 81 81 then 82 83 82 echo -n ' [header updated]' 83 CHANGED=YES; 84 84 fi 85 85 if [[ $TABS_CH = YES ]]; 86 86 then 87 88 87 echo -n ' [tabs removed]' 88 CHANGED=YES; 89 89 fi 90 90 if [[ $SPACES_CH = YES ]]; 91 91 then 92 93 92 echo -n ' [trailing spaces removed]' 93 CHANGED=YES; 94 94 fi 95 95 if long_line_test $1 ; 96 96 then 97 98 97 echo -n ' [LONG LINES]' 98 ((LONG_LINE_FILES++)) 99 99 fi 100 100 echo 101 101 if [[ $CHANGED = YES ]]; 102 102 then 103 103 ((CHANGED_FILES++)) 104 104 fi 105 } 106 107 function list_files() { 108 hg status -a -m -c | 109 cut -d ' ' -f 2 | grep -E '\.(cc|h|dox)$' | sort | uniq 105 110 } 106 111 107 112 CHANGED_FILES=0 … … 109 114 LONG_LINE_FILES=0 110 115 if [ $# == 0 ]; then 111 116 echo Update all source files... 112 for i in `hg manifest|grep -E '\.(cc|h|dox)$'`117 while read i 113 118 do 114 115 116 done 119 update_file $HGROOT/$i 120 ((TOTAL_FILES++)) 121 done < <(list_files) 117 122 echo ' done.' 118 123 else 119 for i in $ *124 for i in $@ 120 125 do 121 122 126 update_file $i 127 ((TOTAL_FILES++)) 123 128 done 124 129 fi 125 130 echo $CHANGED_FILES out of $TOTAL_FILES files has been changed. 126 131 if [[ $LONG_LINE_FILES -gt 1 ]]; then 127 132 echo 128 echo WARNING: $LONG_LINE_FILES files contains long lines! 133 echo WARNING: $LONG_LINE_FILES files contains long lines! 129 134 echo 130 135 elif [[ $LONG_LINE_FILES -gt 0 ]]; then 131 136 echo