summaryrefslogtreecommitdiff
path: root/set-serial.sh
blob: bc53cbfcaa5b9f600e01a7de055c28663cd81b5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 --oneline -- "$n" | wc -l)
  # 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 diff --quiet --exit-code -- "$n"; then
    set-serial-number "$n" "$((revision + 1))"
  fi
done