Generate redo version codes in Documentation/*.1 automatically.

We have to go through some pretty scary gyrations to extract this
information from git, but it can be done.  This works with both tarballs
generated by 'git archive', or with your local git repo.

(Requested by 'David' on the mailing list.)
This commit is contained in:
Avery Pennarun 2011-01-17 23:00:20 -08:00
commit 94b34ea031
23 changed files with 104 additions and 20 deletions

1
version/.gitattributes vendored Normal file
View file

@ -0,0 +1 @@
gitvars.pre export-subst

3
version/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
/vars
/gitvars
/_version.py

1
version/__init__.py Normal file
View file

@ -0,0 +1 @@
from _version import COMMIT, TAG, DATE

3
version/_version.py.do Normal file
View file

@ -0,0 +1,3 @@
redo-ifchange vars
cat vars

2
version/all.do Normal file
View file

@ -0,0 +1,2 @@
redo-ifchange vars _version.py

3
version/clean.do Normal file
View file

@ -0,0 +1,3 @@
rm -f *~ .*~ *.pyc _version.py vars gitvars

24
version/gitvars.do Normal file
View file

@ -0,0 +1,24 @@
redo-ifchange gitvars.pre prodname
read PROD <prodname
# Fix each line from gitvars.pre where git may or may not have already
# substituted the variables. If someone generated a tarball with 'git archive',
# then the data will have been substituted already. If we're in a checkout of
# the git repo, then it won't, but we can just ask git to do the substitutions
# right now.
while read line; do
# Lines *may* be of the form: $Format: ... $
x=${line#\$Format:} # remove prefix
if [ "$x" != "$line" ]; then
# git didn't substitute it
x=${x%\$} # remove trailing $
if [ "$x" == "%d" ]; then
tag=$(git describe --match="$PROD-*")
x="(tag: $tag)"
else
x=$(git log -1 --pretty=format:"$x")
fi
fi
echo "$x"
done <gitvars.pre

3
version/gitvars.pre Normal file
View file

@ -0,0 +1,3 @@
$Format:%H$
$Format:%d$
$Format:%ci$

1
version/prodname Normal file
View file

@ -0,0 +1 @@
redo

40
version/vars.do Normal file
View file

@ -0,0 +1,40 @@
redo-ifchange gitvars prodname
read PROD <prodname
exec <gitvars
read COMMIT
read NAMES
read DATE
# the list of names is of the form:
# (x,y,tag: $PROD-####,tag: $PROD-####,a,b)
# The entries we want are the ones starting with "tag: $PROD-" since those
# refer to the right actual git tags.
names_to_tag()
{
x=${1#\(}
x=${x%\)}
cur=
while [ "$cur" != "$x" ]; do
cur=${x%%,*}
cur=${cur#tag: }
cur=${cur## }
tagpost=${cur#$PROD-}
if [ "$cur" != "$tagpost" ]; then
echo "$tagpost"
return 0
fi
x=${x#*,}
done
commitpost=${COMMIT#???????}
commitpre=${COMMIT%$commitpost}
echo "unknown-$commitpre"
}
sTAG=$(names_to_tag "$NAMES")
echo "COMMIT='$COMMIT'"
echo "TAG='$sTAG'"
echo "DATE='${DATE%% *}'"