7 if [ -n "$(hg st $1)" ]; then
10 hg log -l 1 --template='{date|isodate}\n' $1 |
15 # file enumaration modes
17 function all_files() {
19 cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' |
20 while read file; do echo $HGROOT/$file; done
23 function modified_files() {
25 cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' |
26 while read file; do echo $HGROOT/$file; done
29 function changed_files() {
31 if [ -n "$HG_PARENT1" ]
33 hg status --rev $HG_PARENT1:$HG_NODE -a -m
35 if [ -n "$HG_PARENT2" ]
37 hg status --rev $HG_PARENT2:$HG_NODE -a -m
39 } | cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' |
41 while read file; do echo $HGROOT/$file; done
44 function given_files() {
45 for file in $GIVEN_FILES
53 function update_action() {
54 if ! diff -q $1 $2 >/dev/null
56 echo -n " [$3 updated]"
63 function update_warning() {
64 echo -n " [$2 warning]"
68 function update_init() {
69 echo Update source files...
75 function update_done() {
76 echo $CHANGED_FILES out of $TOTAL_FILES files has been changed.
77 echo $WARNED_FILES out of $TOTAL_FILES files triggered warnings.
80 function update_begin() {
86 function update_end() {
87 if [ $CHANGED == YES ]
97 function check_action() {
100 if echo $2 | grep -q -v -E 'Makefile\.am$'
102 PATTERN=$(echo -e '\t')
106 elif [ "$3" == 'trailing spaces' ]
113 if ! diff -q $1 $2 >/dev/null
115 if [ "$PATTERN" == '*' ]
117 diff $1 $2 | grep '^[0-9]' | sed "s|^\(.*\)c.*$|$2:\1: check failed: $3|g" |
118 sed "s/:\([0-9]*\),\([0-9]*\):\(.*\)$/:\1:\3 (until line \2)/g"
120 grep -n -E "$PATTERN" $2 | sed "s|^\([0-9]*\):.*$|$2:\1: check failed: $3|g"
126 function check_warning() {
127 if [ "$2" == 'long lines' ]
129 grep -n -E '.{81,}' $1 | sed "s|^\([0-9]*\):.*$|$1:\1: warning: $2|g"
131 echo "$1: warning: $2"
136 function check_init() {
137 echo Check source files...
143 function check_done() {
144 echo $FAILED_FILES out of $TOTAL_FILES files has been failed.
145 echo $WARNED_FILES out of $TOTAL_FILES files triggered warnings.
147 if [ $WARNED_FILES -gt 0 -o $FAILED_FILES -gt 0 ]
149 if [ "$WARNING" == 'INTERACTIVE' ]
151 echo -n "Are the files with errors/warnings acceptable? (yes/no) "
154 if [ "$answer" == 'yes' ]
157 elif [ "$answer" == 'no' ]
161 echo -n "Are the files with errors/warnings acceptable? (yes/no) "
163 elif [ "$WARNING" == 'WERROR' ]
170 function check_begin() {
176 function check_end() {
177 if [ $FAILED == YES ]
181 if [ $WARNED == YES ]
191 function header_check() {
192 if echo $1 | grep -q -E 'Makefile\.am$'
199 (echo "/* -*- mode: C++; indent-tabs-mode: nil; -*-
201 * This file is a part of LEMON, a generic C++ optimization library.
203 * Copyright (C) 2003-"$(hg_year $1)"
204 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
205 * (Egervary Research Group on Combinatorial Optimization, EGRES).
207 * Permission to use, modify and distribute this software is granted
208 * provided that this copyright notice appears in all copies. For
209 * precise terms see the accompanying LICENSE file.
211 * This software is provided \"AS IS\" with no warranty of any kind,
212 * express or implied, and with no claim as to its suitability for any
219 /\/\* / && pm==0 { pm=1;}
220 /[^:blank:]/ && (pm==0 || pm==2) { pm=3; print;}
221 /\*\// && pm==1 { pm=2;}
225 "$ACTION"_action "$TMP_FILE" "$1" header
228 function tabs_check() {
229 if echo $1 | grep -q -v -E 'Makefile\.am$'
231 OLD_PATTERN=$(echo -e '\t')
235 NEW_PATTERN=$(echo -e '\t')
238 cat $1 | sed -e "s/$OLD_PATTERN/$NEW_PATTERN/g" >$TMP_FILE
240 "$ACTION"_action "$TMP_FILE" "$1" 'tabs'
243 function spaces_check() {
245 cat $1 | sed -e 's/ \+$//g' >$TMP_FILE
247 "$ACTION"_action "$TMP_FILE" "$1" 'trailing spaces'
250 function long_lines_check() {
251 if cat $1 | grep -q -E '.{81,}'
253 "$ACTION"_warning $1 'long lines'
259 function process_file() {
260 if [ "$ACTION" == 'update' ]
262 echo -n " $ACTION $1..."
264 echo " $ACTION $1..."
267 CHECKING="header tabs spaces long_lines"
270 for check in $CHECKING
275 if [ "$ACTION" == 'update' ]
281 function process_all {
293 if [ "$1" == '--help' ] || [ "$1" == '-h' ]
300 Check the files, but do not modify them.
302 If --dry-run is specified and the checker emits warnings,
303 then the user is asked if the warnings should be considered
306 Make all warnings into errors.
308 Check all source files in the repository.
310 Check only the modified (and new) source files. This option is
311 useful to check the modification before making a commit.
313 Check only the changed source files compared to the parent(s) of
314 the current hg node. This option is useful as hg hook script.
315 To automatically check all your changes before making a commit,
316 add the following section to the appropriate .hg/hgrc file.
319 pretxncommit.checksources = scripts/unify-sources.sh -c -n -i
322 Print this help message.
324 The files to check/unify. If no file names are given, the modified
325 source files will be checked/unified (just like using the
326 --modified|-m option).
329 elif [ "$1" == '--dry-run' ] || [ "$1" == '-n' ]
331 [ -n "$ACTION" ] && echo "Conflicting action options" >&2 && exit 1
333 elif [ "$1" == "--all" ] || [ "$1" == '-a' ]
335 [ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
337 elif [ "$1" == "--changed" ] || [ "$1" == '-c' ]
339 [ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
341 elif [ "$1" == "--modified" ] || [ "$1" == '-m' ]
343 [ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
345 elif [ "$1" == "--interactive" ] || [ "$1" == "-i" ]
347 [ -n "$WARNING" ] && echo "Conflicting warning options" >&2 && exit 1
348 WARNING='INTERACTIVE'
349 elif [ "$1" == "--werror" ] || [ "$1" == "-w" ]
351 [ -n "$WARNING" ] && echo "Conflicting warning options" >&2 && exit 1
353 elif [ $(echo x$1 | cut -c 2) == '-' ]
355 echo "Invalid option $1" >&2 && exit 1
357 [ -n "$FILES" ] && echo "Invalid option $1" >&2 && exit 1