-
Notifications
You must be signed in to change notification settings - Fork 11
/
svnrev.guess
executable file
·144 lines (135 loc) · 4.17 KB
/
svnrev.guess
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
#!/bin/sh
#
# This script creates a package version for packages. The package
# version is the "release" or other version attached by the packaging
# software (eg, RPM or Dpkg) after the upstream software version.
#
# This software must be invoked like so:
#
# svnrev.guess <packagename>
#
# and it expects that release tags are of the form:
#
# /tags/<packagename>-<version>
#
# Note that release tag versioning expects a working connection to
# the repository (for SVN log), but all other branches don't require it.
#
# If there is no .svn directory or it cannot discover the repository
# version, the script sets a version of 0.local.
#
if [ $# -lt 1 ]
then
echo "Usage: svnrev.guess <packagename>" >&2
exit 1
fi
PACKAGE="$1"
getstat()
{
if [ ! -d .svn ]
then
return
fi
svn stat -v | awk 'BEGIN{modified = "false";lastrev = 0}
/Status against/{next}
/^\?/{next}
{
col1=substr($0, 0, 1);
if (col1 != " ") {modified = "true"}
sub(/^......../, "");
if ($1 > lastrev) { lastrev=$1 }
}
END{print modified,lastrev}'
}
#
# Branches that are not releases get a work-in-progress package version.
# This is 0.<svn_revision>[m]. The 0. ensures that an upcoming real
# release, with an package version of 1, will supercede this package.
# The "m" is added if the working tree has modifications to distinguish
# it from a committed revision.
#
# If there is no repository or there is a problem getting the revision,
# the package version is 0.local.
#
workingrev()
{
STATINFO="$(getstat)"
MODIFIED=$(echo "$STATINFO" | cut -f1 -d" ")
LASTREV=$(echo "$STATINFO" | cut -f2 -d" ")
if [ -z "$LASTREV" ]
then
PKG_VERSION=0.local
else
PKG_VERSION=0.${LASTREV}
if [ "$MODIFIED" = "true" ]
then
PKG_VERSION="${PKG_VERSION}m"
fi
fi
echo "$PKG_VERSION"
}
#
# If the branch is a tag (tags/project-x.y), it needs a release-based
# package version (-1, -2, etc). Generally, it will be the tip of the
# branch (package version 1). However, if there is a slight release
# fixup, that warrants bumping the package version.
#
# The logic is pretty simple. Walk the history looking for the
# creation of the tag (A /tags/project-x.y). For each revsion later
# than the creation of the tag, bump the package version.
#
releaserev()
{
BRANCH="$1"
BRANCH_SEARCH="`echo "$BRANCH" | sed -e 's/\//\\\\\//g'`"
svn log -v 2>&1 |
awk 'BEGIN{rev=0}
/^r[0-9]+ \|/{rev += 1}
/^ +A \/'"$BRANCH_SEARCH"'$/{exit}
/^ +A \/'"$BRANCH_SEARCH"' (.*)$/{exit}
END{print rev}'
}
#
# Tag branches are releases, and need a release-style package version.
# All other branches are non-release, and get an obviously
# work-in-progress package version.
#
# guessbranch() expects the standard Subversion layout of
# /trunk
# /branches/<branchname>
# /tags/<tagname>
#
guessbranch()
{
if [ ! -d .svn ]
then
return
fi
svn info | awk '/URL: .*\/trunk\/?$/{print "trunk"; exit 0}
/URL: .*\/branches\/[^/]+\/?/{
gsub(/\/$/, "", $2);
sub(/^.*\/branches\//, "", $2);
print "branches/"$2;
exit 0;
}
/URL: .*\/tags\/[^/]+\/?/{
gsub(/\/$/, "", $2);
sub(/^.*\/tags\//, "", $2);
print "tags/"$2;
exit 0;
}'
}
if ! which svn 1>/dev/null 2>&1
then
echo "0.local"
else
BRANCH=$(guessbranch)
case "$BRANCH" in
tags/${PACKAGE}*)
releaserev "$BRANCH"
;;
*)
workingrev
;;
esac
fi