-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeb_changelog.sh
executable file
·67 lines (55 loc) · 2.08 KB
/
deb_changelog.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
#!/bin/bash
# Use output of git log and git describe to create a debian changelog
# Debian "native" source packages can't have a hyphen in the version
# such as 1.2-14, because that indicates there is an upstream
# tarball *-1.2.orig.tar.gz.
# So when git describe returns v1.2-14-g..., that gets converted
# to a debian version 1.2+14.
usage() {
echo "${0##*/} pkgname"
exit 1
}
if [ $# -lt 1 ]; then
usage
fi
pkg=$1
awkcom=`mktemp /tmp/${script}_XXXXXX.awk`
trap "{ rm -f $awkcom; }" EXIT
# In the changelog, copy most recent commit subject lines
# since this tag (max of 100).
# sincetag=v1.0
# to get the most recent tag of the form: vN
sincetag=$(git tag -l --sort=version:refname "[vV][0-9]*" | tail -n 1)
if ! gitdesc=$(git describe --match "v[0-9]*"); then
echo "git describe failed, looking for a tag of the form v[0-9]*"
exit 1
fi
# example output of git describe: v2.0-14-g9abcdef
# awk script to convert output of git log to changelog format
# run git describe on each hash to create a version
cat << \EOD | sed 's/...pkg...'/$pkg/ > $awkcom
/^[0-9a-f]{7}/ {
cmd = "git describe --match '[vV][0-9]*' " $0 " 2>/dev/null"
res = (cmd | getline gitdesc)
close(cmd)
if (res == 0) {
gitdesc = ""
}
else {
# print "gitdesc=" gitdesc
hash = gensub(".*-g([0-9a-f]+)","\\1",1,gitdesc)
# convert v2.0-14-g9abcdef to 2.0+14
version = gensub("^v([^-]+)-([0-9]+)-.*$","\\1+\\2",1,gitdesc)
# print "version=" version ",hash=" hash
}
}
/^...pkg.../ { print $0 " (" version ") stable; urgency=low" }
# truncate "*" line to 74 characters, 14 + max of 60 from commit subject
/^ \*/ { out = gensub("XXXXXXX",hash,1); print substr(out,1,74);}
/^ --/ { print $0 }
/^$/ { print $0 }
EOD
# create Debian changelog from git log messages since the tag $sincetag.
# Put SHA hash by itself on first line. Above awk script then
# runs git describe on that hash in order to get a X.Y-Z version.
git log --max-count=100 --date-order --format="%H%n${pkg}%n * (XXXXXXX) %s%n -- %aN <%ae> %cD" --date=local ${sincetag}.. | awk -f $awkcom