7 if [ -n "$(hg st $1)" ]; then
11 # file enumaration modes
13 function all_files() {
15 cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' |
16 while read file; do echo $HGROOT/$file; done
19 function modified_files() {
21 cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' |
22 while read file; do echo $HGROOT/$file; done
25 function changed_files() {
27 if [ -n "$HG_PARENT1" ]
29 hg status --rev $HG_PARENT1:$HG_NODE -a -m
31 if [ -n "$HG_PARENT2" ]
33 hg status --rev $HG_PARENT2:$HG_NODE -a -m
35 } | cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' |
37 while read file; do echo $HGROOT/$file; done
40 function given_files() {
41 for file in $GIVEN_FILES
49 function update_action() {
50 if ! diff -q $1 $2 >/dev/null
52 echo -n " [$3 updated]"
59 function update_warning() {
60 echo -n " [$2 warning]"
64 function update_init() {
65 echo Update source files...
71 function update_done() {
72 echo $CHANGED_FILES out of $TOTAL_FILES files has been changed.
73 echo $WARNED_FILES out of $TOTAL_FILES files triggered warnings.
76 function update_begin() {
82 function update_end() {
83 if [ $CHANGED == YES ]
93 function check_action() {
96 if echo $2 | grep -q -v -E 'Makefile\.am$'
98 PATTERN=$(echo -e '\t')
102 elif [ "$3" == 'trailing spaces' ]
109 if ! diff -q $1 $2 >/dev/null
111 if [ "$PATTERN" == '*' ]
113 diff $1 $2 | grep '^[0-9]' | sed "s|^\(.*\)c.*$|$2:\1: check failed: $3|g" |
114 sed "s/:\([0-9]*\),\([0-9]*\):\(.*\)$/:\1:\3 (until line \2)/g"
116 grep -n -E "$PATTERN" $2 | sed "s|^\([0-9]*\):.*$|$2:\1: check failed: $3|g"
122 function check_warning() {
123 if [ "$2" == 'long lines' ]
125 grep -n -E '.{81,}' $1 | sed "s|^\([0-9]*\):.*$|$1:\1: warning: $2|g"
127 echo "$1: warning: $2"
132 function check_init() {
133 echo Check source files...
139 function check_done() {
140 echo $FAILED_FILES out of $TOTAL_FILES files has been failed.
141 echo $WARNED_FILES out of $TOTAL_FILES files triggered warnings.
143 if [ $WARNED_FILES -gt 0 -o $FAILED_FILES -gt 0 ]
145 if [ "$WARNING" == 'INTERACTIVE' ]
147 echo -n "Are the files with errors/warnings acceptable? (yes/no) "
150 if [ "$answer" == 'yes' ]
153 elif [ "$answer" == 'no' ]
157 echo -n "Are the files with errors/warnings acceptable? (yes/no) "
159 elif [ "$WARNING" == 'WERROR' ]
166 function check_begin() {
172 function check_end() {
173 if [ $FAILED == YES ]
177 if [ $WARNED == YES ]
187 function header_check() {
188 if echo $1 | grep -q -E 'Makefile\.am$'
195 (echo "/* -*- mode: C++; indent-tabs-mode: nil; -*-
197 * This file is a part of LEMON, a generic C++ optimization library.
199 * Copyright (C) 2003-"$(hg_year $1)"
200 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
201 * (Egervary Research Group on Combinatorial Optimization, EGRES).
203 * Permission to use, modify and distribute this software is granted
204 * provided that this copyright notice appears in all copies. For
205 * precise terms see the accompanying LICENSE file.
207 * This software is provided \"AS IS\" with no warranty of any kind,
208 * express or implied, and with no claim as to its suitability for any
215 /\/\* / && pm==0 { pm=1;}
216 /[^:blank:]/ && (pm==0 || pm==2) { pm=3; print;}
217 /\*\// && pm==1 { pm=2;}
221 "$ACTION"_action "$TMP_FILE" "$1" header
224 function tabs_check() {
225 if echo $1 | grep -q -v -E 'Makefile\.am$'
227 OLD_PATTERN=$(echo -e '\t')
231 NEW_PATTERN=$(echo -e '\t')
234 cat $1 | sed -e "s/$OLD_PATTERN/$NEW_PATTERN/g" >$TMP_FILE
236 "$ACTION"_action "$TMP_FILE" "$1" 'tabs'
239 function spaces_check() {
241 cat $1 | sed -e 's/ \+$//g' >$TMP_FILE
243 "$ACTION"_action "$TMP_FILE" "$1" 'trailing spaces'
246 function long_lines_check() {
247 if cat $1 | grep -q -E '.{81,}'
249 "$ACTION"_warning $1 'long lines'
255 function process_file() {
256 if [ "$ACTION" == 'update' ]
258 echo -n " $ACTION $1..."
260 echo " $ACTION $1..."
263 CHECKING="header tabs spaces long_lines"
266 for check in $CHECKING
271 if [ "$ACTION" == 'update' ]
277 function process_all {
289 if [ "$1" == '--help' ] || [ "$1" == '-h' ]
296 Check the files, but do not modify them.
298 If --dry-run is specified and the checker emits warnings,
299 then the user is asked if the warnings should be considered
302 Make all warnings into errors.
304 Check all source files in the repository.
306 Check only the modified (and new) source files. This option is
307 useful to check the modification before making a commit.
309 Check only the changed source files compared to the parent(s) of
310 the current hg node. This option is useful as hg hook script.
311 To automatically check all your changes before making a commit,
312 add the following section to the appropriate .hg/hgrc file.
315 pretxncommit.checksources = scripts/unify-sources.sh -c -n -i
318 Print this help message.
320 The files to check/unify. If no file names are given, the modified
321 source files will be checked/unified (just like using the
322 --modified|-m option).
325 elif [ "$1" == '--dry-run' ] || [ "$1" == '-n' ]
327 [ -n "$ACTION" ] && echo "Conflicting action options" >&2 && exit 1
329 elif [ "$1" == "--all" ] || [ "$1" == '-a' ]
331 [ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
333 elif [ "$1" == "--changed" ] || [ "$1" == '-c' ]
335 [ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
337 elif [ "$1" == "--modified" ] || [ "$1" == '-m' ]
339 [ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
341 elif [ "$1" == "--interactive" ] || [ "$1" == "-i" ]
343 [ -n "$WARNING" ] && echo "Conflicting warning options" >&2 && exit 1
344 WARNING='INTERACTIVE'
345 elif [ "$1" == "--werror" ] || [ "$1" == "-w" ]
347 [ -n "$WARNING" ] && echo "Conflicting warning options" >&2 && exit 1
349 elif [ $(echo x$1 | cut -c 2) == '-' ]
351 echo "Invalid option $1" >&2 && exit 1
353 [ -n "$FILES" ] && echo "Invalid option $1" >&2 && exit 1