forked from coreemu/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
revision.sh
executable file
·173 lines (142 loc) · 3.03 KB
/
revision.sh
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/sh
usage()
{
echo "usage: $(basename $0) (-d | <base version> [<version suffix>])" >&2
exit $1
}
func=revision
while getopts dh f; do
case $f in
d)
func=date
;;
h)
usage 0
;;
*)
usage 1
;;
esac
done
shift $(($OPTIND - 1))
case $func in
revision)
if [ $# -lt 1 -o $# -gt 2 ]; then
usage 1
fi
;;
date)
if [ $# -gt 0 ]; then
usage 1
fi
;;
*)
usage 1
;;
esac
_revision()
{
if [ -r .version ]; then
cat .version
else
echo $1$2
fi
}
git_revision()
{
local ver versuffix describe untagged commits branch sha dirty
ver=$1
versuffix=$2
describe=$(git describe --tags --dirty 2> /dev/null)
if [ "$describe" ]; then
echo "$describe" | sed -e 's/^release-//'
return
fi
if [ ! "$(git tag -l release-$ver)" ]; then
untagged=".untagged"
else
commits=$(git rev-list release-${ver}^..HEAD | wc -l)
if [ $commits -eq 0 ]; then
commits=""
else
commits=".$commits"
fi
fi
branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$branch" = master ]; then
branch=""
else
branch=".$(echo -n $branch | tr -sC '.[:alnum:]' '[.*]')"
fi
if [ "$untagged" -o "$commits" ]; then
sha=.g$(git log -1 --pretty="%h")
fi
if ! git diff --quiet; then
dirty=".dirty"
else
dirty=""
fi
echo ${ver}${versuffix}${untagged}${commits}${branch}${sha}${dirty}
}
svn_revision()
{
local ver versuffix tagrev untagged commits rev dirty
ver=$1
versuffix=$2
tagrev=$(svn log -q ^/tags/release-$ver --limit 1 2> /dev/null | \
awk '/^r/ {print $1}')
if [ ! "$tagrev" ];then
untagged=".untagged"
else
commits=$(svn log -q -r $tagrev:HEAD | grep '^r' | wc -l)
if [ $commits -eq 0 ]; then
commits=""
else
commits=".$commits"
fi
fi
if [ "$untagged" -o "$commits" ]; then
rev=.s$(svn info | awk '/^Revision:/ {print $2}')
fi
if (svn status -q | grep -q .); then
dirty=".dirty"
fi
echo ${ver}${versuffix}${untagged}${commits}${rev}${dirty}
}
_date()
{
if [ -r .version.date ]; then
cat .version.date
else
date '+%Y%m%d'
fi
}
git_date()
{
local date
if git diff --quiet; then
date=$(git log -1 --format='%ci' | \
awk '{gsub("-", "", $1); print $1}')
else
date=$(_date)
fi
echo $date
}
svn_date()
{
local date
if ! (svn status -q | grep -q .); then
date=$(svn log -q --limit 1 | \
awk '/^r[0-9]+/ {gsub("-", "", $5); print $5}')
else
date=$(_date)
fi
echo $date
}
repo=""
if test -d .git || git rev-parse --git-dir > /dev/null 2>&1; then
repo=git
elif test -d .svn || svn info > /dev/null 2>&1; then
repo=svn
fi
${repo}_${func} "$@"