-
Notifications
You must be signed in to change notification settings - Fork 2
/
rev
executable file
·90 lines (79 loc) · 3.01 KB
/
rev
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
# Usage:
# rev R7
# or
# rev D0876R7
# Finds the most recent previous [PD]0876R*.tex and updates version references
# accordingly.
PNUM="0876"
cd "$(dirname "$0")"
# Convert user's specified revision (in any of several forms) to P0876Rx
pfx="${1:0:1}"
case "$pfx" in
P|D)
# user specified the entire P0876Rx
newrev="$1"
;;
R)
# user specified just the Rx
newrev="P$PNUM$1"
;;
*)
if [ $(($1+0)) == "$1" ]
then # $1 is an int
newrev="P${PNUM}R$1"
else
echo "Unrecognized revision '$1'" >&2
exit 1
fi
;;
esac
# There should be only one master .tex file, but in case we turn up more than
# one, reverse-sort names, skipping the first character, and take the first.
oldtex="$(ls [PD]${PNUM}R*.tex | sort -k1.2r | head -n 1)"
oldrev="${oldtex%.tex}"
# Find the URL for the published oldrev
oldurl="$(curl --silent --location --head --output /dev/null --write-out '%{url_effective}' -- https://wg21.link/$oldrev)"
# Find the rev previous to oldrev
prevrev="$(sed -n -E "s/^.*supersedes ([PD]0876R.*)\..*/\1/p" history.tex)"
echo "Updating $oldrev -> $newrev"
echo "$oldrev URL: $oldurl"
echo "Previous to $oldrev was $prevrev"
git mv "$oldtex" "$newrev.tex"
sed -i~ "s/$oldrev/$newrev/" "$newrev.tex"
sed -i~ "s/$prevrev\\\\cite{$prevrev}/$oldrev\\\\cite{$oldrev}/" abstract.tex
# For 'This document supersedes $prevrev', just update to $oldrev.
# For 'Changes since $prevrev', insert 'Changes since $oldrev' above it, with
# a blank line separating the two.
# H appends a newline character followed by the pattern space (the 'Changes
# since $prevrev' line) to the (previously-empty) hold space.
# Then update the pattern space to talk about 'Changes since $oldrev'.
# G appends a newline character followed by the hold space to the pattern
# space. The combination of those two newlines produces the desired blank
# line.
sed -i~ -E -f <(echo \
"/(supersedes )$prevrev/s//\\1$oldrev/
/Changes since $prevrev/{ H
s/$prevrev/$oldrev/
G
}") history.tex
# We want to inject a new \bibitem{$oldrev} block just like (and just after)
# the \bibitem{$prevrev} block. Each such block is 4 lines long, including the
# trailing blank line. So search for \bibitem{$prevrev}, then suck the next 3
# lines into the pattern space. Immediately print the pattern space BEFORE
# changing it -- that is, we want to append to the \bibitem{$prevrev} block
# rather than replacing it. Then substitute $prevrev with $oldrev. Then
# substitute the old url in \href{...} with \href{$oldurl}. But inside
# \href{...} we must use [^[:space:]]* rather than simply .* because .*, being
# greedy, spans lines and will eat through the close } and the subsequent open
# { and all the way up to the second }. Don't explicitly print the pattern
# space again because that's implied (since we didn't specify the -n switch).
sed -i~ -f <(echo \
"/\bibitem{$prevrev}/{ N
N
N
p
s/$prevrev/$oldrev/g
s!\href{[^[:space:]]*}!\href{$oldurl}!
}") references.tex
git diff