summaryrefslogtreecommitdiff
path: root/set-serial.sh
blob: 7e52ed4768d3b4d83d692a2356b66c1af7702535 (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
#! /usr/bin/env 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)
  # Check whether git regards the file as "modified" now. If it does,
  # the serial number needs to be bumped one more time.
  if ! git diff --quiet --exit-code HEAD -- "$n"; then
    revision="$((revision + 1))"
  fi
  # Update the serial number in the m4 file.
  set_serial_number "$n" "$revision"
done