| 1 | 1 |
#!/bin/bash |
| 2 | 2 |
|
| 3 | 3 |
YEAR=`date +%Y` |
| 4 | 4 |
HGROOT=`hg root` |
| 5 | 5 |
|
| 6 | 6 |
function hg_year() {
|
| 7 | 7 |
if [ -n "$(hg st $1)" ]; then |
| 8 | 8 |
echo $YEAR |
| 9 |
else |
|
| 10 |
hg log -l 1 --template='{date|isodate}\n' $1 |
|
|
| 11 |
cut -d '-' -f 1 |
|
| 12 |
fi |
|
| 9 | 13 |
} |
| 10 | 14 |
|
| 11 | 15 |
# file enumaration modes |
| 12 | 16 |
|
| 13 | 17 |
function all_files() {
|
| 14 | 18 |
hg status -a -m -c | |
| 15 | 19 |
cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' | |
| 16 | 20 |
while read file; do echo $HGROOT/$file; done |
| 17 | 21 |
} |
| 18 | 22 |
|
| 19 | 23 |
function modified_files() {
|
| 20 | 24 |
hg status -a -m | |
| 21 | 25 |
cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' | |
| 22 | 26 |
while read file; do echo $HGROOT/$file; done |
| 23 | 27 |
} |
| 24 | 28 |
|
| 25 | 29 |
function changed_files() {
|
| 26 | 30 |
{
|
| 27 | 31 |
if [ -n "$HG_PARENT1" ] |
| 28 | 32 |
then |
| 29 | 33 |
hg status --rev $HG_PARENT1:$HG_NODE -a -m |
| 30 | 34 |
fi |
| 31 | 35 |
if [ -n "$HG_PARENT2" ] |
| 32 | 36 |
then |
| 33 | 37 |
hg status --rev $HG_PARENT2:$HG_NODE -a -m |
| 34 | 38 |
fi |
| 35 | 39 |
} | cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' | |
| 36 | 40 |
sort | uniq | |
| 37 | 41 |
while read file; do echo $HGROOT/$file; done |
| 38 | 42 |
} |
| 39 | 43 |
|
| 40 | 44 |
function given_files() {
|
| 41 | 45 |
for file in $GIVEN_FILES |
| 42 | 46 |
do |
| 43 | 47 |
echo $file |
| 44 | 48 |
done |
| 45 | 49 |
} |
| 46 | 50 |
|
| 47 | 51 |
# actions |
| 48 | 52 |
|
| 49 | 53 |
function update_action() {
|
| 50 | 54 |
if ! diff -q $1 $2 >/dev/null |
| 51 | 55 |
then |
| 52 | 56 |
echo -n " [$3 updated]" |
| 53 | 57 |
rm $2 |
| 54 | 58 |
mv $1 $2 |
| 55 | 59 |
CHANGED=YES |
| 56 | 60 |
fi |
| 57 | 61 |
} |
| 58 | 62 |
|
| 59 | 63 |
function update_warning() {
|
| 60 | 64 |
echo -n " [$2 warning]" |
| 61 | 65 |
WARNED=YES |
| 62 | 66 |
} |
| 63 | 67 |
|
| 64 | 68 |
function update_init() {
|
| 65 | 69 |
echo Update source files... |
| 66 | 70 |
TOTAL_FILES=0 |
| 67 | 71 |
CHANGED_FILES=0 |
| 68 | 72 |
WARNED_FILES=0 |
| 69 | 73 |
} |
| 70 | 74 |
|
| 71 | 75 |
function update_done() {
|
| 72 | 76 |
echo $CHANGED_FILES out of $TOTAL_FILES files has been changed. |
| 73 | 77 |
echo $WARNED_FILES out of $TOTAL_FILES files triggered warnings. |
| 74 | 78 |
} |
| 75 | 79 |
|
| 76 | 80 |
function update_begin() {
|
| 77 | 81 |
((TOTAL_FILES++)) |
| 78 | 82 |
CHANGED=NO |
| 79 | 83 |
WARNED=NO |
| 80 | 84 |
} |
| 81 | 85 |
|
| 82 | 86 |
function update_end() {
|
| 83 | 87 |
if [ $CHANGED == YES ] |
| 84 | 88 |
then |
| 85 | 89 |
((++CHANGED_FILES)) |
| 86 | 90 |
fi |
| 87 | 91 |
if [ $WARNED == YES ] |
| 88 | 92 |
then |
| 89 | 93 |
((++WARNED_FILES)) |
| 90 | 94 |
fi |
| 91 | 95 |
} |
| 92 | 96 |
|
| 93 | 97 |
function check_action() {
|
| 94 | 98 |
if [ "$3" == 'tabs' ] |
| 95 | 99 |
then |
| 96 | 100 |
if echo $2 | grep -q -v -E 'Makefile\.am$' |
| 97 | 101 |
then |
| 98 | 102 |
PATTERN=$(echo -e '\t') |
| 99 | 103 |
else |
| 100 | 104 |
PATTERN=' ' |
| 101 | 105 |
fi |
| 102 | 106 |
elif [ "$3" == 'trailing spaces' ] |
| 103 | 107 |
then |
| 104 | 108 |
PATTERN='\ +$' |
0 comments (0 inline)