Debian Codegraph @

batch/make/version

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/bin/sh
2 # determines the version of the sources
3 # usage: version <source directory>
4
5 # set -x
6
7 srcdir="$1"
8
9 # if we're building via CI from a protected tag, that is our version
10 if test "${CI_COMMIT_REF_PROTECTED}" = "true" && ! test -z "${CI_COMMIT_TAG}"; then
11 echo "${CI_COMMIT_TAG}" | sed -e s/^v//
12 exit 0
13 fi
14
15 # set version parts to defaults for CVS snapshot
16 major_version=`cat ${srcdir}/major_version`
17 minor_version_proto=`cat ${srcdir}/minor_version`
18 DATE=`date +%Y%m%d`
19
20 #echo $major_version
21 #echo $minor_version
22
23 bzr_count_revisions()
24 {
25 srcdir="$1"
26 limit="$2"
27
28 test -z "$limit" || limit="-l $limit"
29
30 count=$(bzr log -n 0 --line $limit "${srcdir}" 2>/dev/null | wc -l)
31 echo $count
32 }
33
34 # *TODO* once we get our superproject up on launchpad (and thus get saner branch nicks), use branch nicks for $major_version
35 # Check if bzr is installed, and if the path is versionned
36 bzr >/dev/null 2>&1
37 # But for now, ignore it
38 if test $? -eq 0 && test -d ${srcdir}/.bzr
39 #if test 1 -eq 0
40 then
41 # Crappily, we can't rely on revision numbers to do anything
42 # ( ie. when one merges then pushes, the last revno might be lower than originally)
43 # So we count revisions, including merged ones, also including fools which have empty
44 # lines with only "revno: 15" in their commit messages
45 revno=$( bzr revno ${srcdir} 2>/dev/null)
46 revcount=$( bzr_count_revisions ${srcdir} )
47 lca=$revno
48 lcaz=$revcount
49 versioned=#
50 branchurl=$( bzr info ${srcdir} 2>/dev/null | sed -ne 's/^ parent branch: \(.*\)$/\1/p' )
51
52
53 # We will check this branch diverged, and/or if tree changed
54 bzrmissingcout=$( cd ${srcdir} && bzr missing --this 2>/dev/null )
55 missing=$?
56 bzr diff ${srcdir} --quiet >/dev/null 2>&1
57 changed=$?
58
59
60 if test ${missing} -eq 1
61 # if it diverged:
62 then
63 # Count the revisions we added locally
64 localrevisions=$( echo "${bzrmissingcout}" | sed -ne '2,1s/[^0-9]//gp' )
65 # See how many steps it is, with the fool's number
66 stepsbackwards=$( bzr_count_revisions ${srcdir} ${localrevisions} )
67 # And start dancing.
68 minor_version=_alpha_z$(( ${revcount} - ${stepsbackwards} ))_${DATE}
69 # Set last common ancestors
70 lca=$(( ${revno} - ${localrevisions}))
71 lcaz=$(( ${revcount} - ${stepsbackwards} ))
72 srcchanged=#
73 elif test ${missing} -eq 0 && ( test ${changed} -eq 1 || test ${changed} -eq 2 )
74 then
75 # If a change was made and no more revision was added, just use revision fool's number plus build date
76 minor_version=_alpha_z${revcount}_${DATE}
77 # And this is versionned too
78 srcchanged=#
79 elif test ${missing} -eq 0
80 then
81 # If really no change was made, use the fool's number, with tag if any
82 # So check if we have tags
83 revno=$(bzr revno ${srcdir})
84 tag=$(bzr tags -r $revno | awk '{ print $1 }' | sed -e s/^v//)
85 if test ${tag}
86 then
87 # If it is tagged, use the tag
88 minor_version=_alpha_z${revcount}_${tag}
89 else
90 # If not, use fool's number only
91 minor_version=_alpha_z${revcount}
92 fi
93 # That's versioned as well
94 else
95 # Otherwise, this is just not versionned
96 versioned=
97 fi
98
99 if test $versioned
100 then
101 branchnick=$( cd ${srcdir}; bzr nick )
102 revid=$( bzr testament | sed -ne 's/^revision-id: \(.*\)/\1/p' )
103 fi
104 fi
105
106 # try to get a good guess about which branch we're on
107 GIT_BRANCH="alpha"
108
109 if test -e "${srcdir}/.git"; then
110 # check for a tag
111 cd $srcdir
112
113 # todo: once we have make tags, consider just git describe --tags as version ID, like this:
114 # git describe --tags | sed -e s/^v//
115 # exit 0
116
117 #if tag=`git describe --tags --candidates=0` > /dev/null 2>&1; then
118 # major_version=`echo ${tag} | sed -e s/version_// -e s/release_//` -e s/^v//
119 # minor_version=""
120 # DATE=""
121 #else
122 git update-index --refresh > /dev/null
123 if git diff-index --quiet HEAD --; then
124 # local checkout clean, just use revno
125 DATE=_z`git rev-list HEAD --count`
126 else
127 # local changes, add date
128 DATE=_z`git rev-list HEAD --count`_$DATE
129 fi
130 #fi
131
132 GIT_BRANCH=`git -C ${srcdir} rev-parse --abbrev-ref HEAD`
133 fi
134 test -z "${CI_COMMIT_BRANCH}" || GIT_BRANCH=${CI_COMMIT_BRANCH}
135
136 if test -z "$minor_version"
137 then
138 test -z "$DATE" || minor_version=`echo ${minor_version_proto} | sed -e "s,DATE,$DATE," -e "s,YYYYMMDD,$DATE,"`
139 fi
140
141 if test "${CI_COMMIT_REF_PROTECTED}" = "true"; then
142 # determine alpha/beta/rc status based on branch
143 if echo ${GIT_BRANCH} | grep -q "^beta"; then
144 minor_version=`echo ${minor_version} | sed -e s,alpha,beta,`
145 elif echo ${GIT_BRANCH} | grep -q "^release"; then
146 minor_version=`echo ${minor_version} | sed -e s,alpha,rc,`
147 fi
148 fi
149
150 echo $major_version$minor_version