13804
|
1 |
#!/usr/bin/env bash
|
|
2 |
#
|
|
3 |
# Author: Stefan Berghofer, TU Muenchen
|
41511
|
4 |
# Author: Makarius
|
13804
|
5 |
#
|
|
6 |
# DESCRIPTION: display Isabelle version
|
|
7 |
|
41511
|
8 |
|
|
9 |
PRG="$(basename "$0")"
|
|
10 |
|
|
11 |
function usage()
|
|
12 |
{
|
|
13 |
echo
|
|
14 |
echo "Usage: isabelle $PRG [OPTIONS]"
|
|
15 |
echo
|
|
16 |
echo " Options are:"
|
|
17 |
echo " -i short identification (derived from Mercurial id)"
|
73481
|
18 |
echo " -t symbolic tags (derived from Mercurial id)"
|
41511
|
19 |
echo
|
|
20 |
echo " Display Isabelle version information."
|
|
21 |
echo
|
|
22 |
exit 1
|
|
23 |
}
|
|
24 |
|
|
25 |
function fail()
|
|
26 |
{
|
|
27 |
echo "$1" >&2
|
|
28 |
exit 2
|
|
29 |
}
|
|
30 |
|
|
31 |
|
|
32 |
## process command line
|
|
33 |
|
|
34 |
# options
|
|
35 |
|
|
36 |
SHORT_ID=""
|
73481
|
37 |
TAGS=""
|
41511
|
38 |
|
73481
|
39 |
while getopts "it" OPT
|
41511
|
40 |
do
|
|
41 |
case "$OPT" in
|
|
42 |
i)
|
|
43 |
SHORT_ID=true
|
|
44 |
;;
|
73481
|
45 |
t)
|
|
46 |
TAGS=true
|
|
47 |
;;
|
41511
|
48 |
\?)
|
|
49 |
usage
|
|
50 |
;;
|
|
51 |
esac
|
|
52 |
done
|
|
53 |
|
|
54 |
shift $(($OPTIND - 1))
|
|
55 |
|
|
56 |
|
|
57 |
# args
|
|
58 |
|
|
59 |
[ "$#" -ne 0 ] && usage
|
|
60 |
|
|
61 |
|
|
62 |
## main
|
|
63 |
|
73481
|
64 |
if [ -z "$SHORT_ID" -a -z "$TAGS" ]; then
|
67866
|
65 |
echo 'repository version' # filled in automatically!
|
41511
|
66 |
fi
|
73481
|
67 |
|
|
68 |
if [ -n "$SHORT_ID" ]; then
|
|
69 |
if [ -d "$ISABELLE_HOME/.hg" ]; then
|
|
70 |
"${HG:-hg}" -R "$ISABELLE_HOME" log -r "p1()" --template="{node|short}\n" 2>/dev/null || exit "$?"
|
|
71 |
elif [ -f "$ISABELLE_HOME/.hg_archival.txt" ]; then
|
|
72 |
RESULT="$(fgrep node: < "$ISABELLE_HOME/.hg_archival.txt" | cut -d " " -f2 | head -c12)"
|
|
73 |
[ -n "$RESULT" ] && echo "$RESULT"
|
|
74 |
elif [ -n "$ISABELLE_ID" ]; then
|
|
75 |
echo "$ISABELLE_ID"
|
|
76 |
fi
|
|
77 |
fi
|
|
78 |
|
|
79 |
if [ -n "$TAGS" ]; then
|
|
80 |
RESULT=""
|
|
81 |
if [ -d "$ISABELLE_HOME/.hg" ]; then
|
|
82 |
RESULT=$("${HG:-hg}" -R "$ISABELLE_HOME" id -t 2>/dev/null)
|
|
83 |
RC="$?"
|
|
84 |
elif [ -f "$ISABELLE_HOME/.hg_archival.txt" ]; then
|
|
85 |
RESULT="$(fgrep tag: < "$ISABELLE_HOME/.hg_archival.txt" | cut -d " " -f2)"
|
|
86 |
RC="$?"
|
|
87 |
fi
|
|
88 |
if [ "$RC" -ne 0 ]; then
|
|
89 |
exit "$RC"
|
|
90 |
elif [ -n "$RESULT" -a "$RESULT" != "tip" ]; then
|
|
91 |
echo "$RESULT"
|
|
92 |
fi
|
|
93 |
fi
|