diff options
author | Peter Simons <simons@cryp.to> | 2009-12-25 19:16:13 +0100 |
---|---|---|
committer | Peter Simons <simons@cryp.to> | 2009-12-25 19:16:13 +0100 |
commit | d3f4eecd553f4cf4e32a37eb4058e958ec266be6 (patch) | |
tree | 9ca94fa4ea471a1a81d736332981022a1de0c42c /set-serial.sh | |
parent | 0bd52b785290793a7ead9792e983b874da0c8cd9 (diff) | |
download | autoconf-archive-d3f4eecd553f4cf4e32a37eb4058e958ec266be6.tar.gz |
set-serial.sh: generate serial numbers automatically
Usage: ./set-serial.sh m4/ax_foo.m4 m4/ax_bar.m4 [...]
This script determines the number of revisions that have occurred to a
given m4 file, and patches an appropriate #serial number into the file
automatically. After that, the script checks whether git(1) regards that
file as modified now. If it does, the serial number is bumped one more
time to ensure that the number will be correct as soon as the changes
have been committed. Consequently, running this script on an unmodified
m4 file with correct serial number information is a no-op and doesn't
change anything.
Diffstat (limited to 'set-serial.sh')
-rwxr-xr-x | set-serial.sh | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/set-serial.sh b/set-serial.sh new file mode 100755 index 0000000..fe9b442 --- /dev/null +++ b/set-serial.sh @@ -0,0 +1,25 @@ +#! /bin/bash + +set -eu + +set-serial-number() +{ + sed >"$1.tmp" -e '/^$/q' "$1" + echo >>"$1.tmp" "#serial $2" + echo >>"$1.tmp" "" + sed >>"$1.tmp" -e '1,/^$/d' -e '/^#serial .*/,+1d' "$1" + mv "$1.tmp" "$1" +} + +for n in "$@"; do + echo "$n ... " + # Determine the number of revisions that have occurred to the macro. + revision=$(git log -- "$n" | egrep -c '^commit [0-9a-f]') + # Update the serial number in the m4 file. + set-serial-number "$n" "$revision" + # Check whether git regards the file as "modified" now. If it does, + # the serial nmuber needs to be bumped one more time. + if git >/dev/null status -- "$n"; then + set-serial-number "$n" "$((revision + 1))" + fi +done |