debian/rules: Use /bin/sh as POSIX shell regardless of build environment
[xz/debian.git] / debian / changelog.upstream.sh
blobafaec0fcfd0b0385e365753a8f35215b41b250bd
1 #!/bin/sh
2 # Generate debian/changelog.upstream from debian/changelog and
3 # the git revision log. Inspired by Gerrit Pape’s
4 # debian/changelog.upstream.sh, from the git-core Debian package.
6 set -e
8 # If argument matches /^Version: /, output remaining text.
9 # Result is true if and only if argument matches.
10 version_line() {
11 local line result
12 line=$1
13 result=${line#Version: }
15 if test "$result" = "$line"
16 then
17 return 1
18 else
19 printf "%s\n" "$result"
20 return 0
24 # If argument matches /^\* New.*snapshot.*commit /,
25 # output remaining text.
26 # Result is true if and only if argument matches.
27 commit_id_line() {
28 local line result
29 line=$1
30 result=${line#\* New*snapshot*commit }
32 if test "$result" = "$line"
33 then
34 return 1
35 else
36 printf "%s\n" "$result"
37 return 0
41 # Read standard input, scanning for a changelog entry of the
42 # form “New snapshot, taken from upstream commit <blah>.”
43 # Output is <blah>.
44 # Fails and writes a message to standard error if no such entry is
45 # found before the next Version: line with a different upstream
46 # version (or EOF).
47 # $1 is the upstream version sought.
48 read_commit_id() {
49 local upstream_version line version cid
50 upstream_version=$1
52 while read line
55 version=$(version_line "$line") &&
56 test "${version%-*}" != "$upstream_version"
57 then
58 break
61 if cid=$(commit_id_line "$line")
62 then
63 printf "%s\n" "${cid%.}"
64 return 0
66 done
68 echo >&2 "No commit id for $upstream_version"
69 return 1
72 last=none
73 last_cid=none
74 # Add a list of all revisions up to $last to debian/changelog.upstream
75 # and set last=$2.
76 # $1 is a user-readable name for the commit $2
77 add_version() {
78 local new new_cid limiter
79 new=$1
80 new_cid=$2
82 if test "$last" = none
83 then
84 : > debian/changelog.upstream
85 last=$new
86 last_cid=$new_cid
87 return 0
90 exec >> debian/changelog.upstream
91 if test "$new" = none
92 then
93 echo "Version $last:"
94 echo "Version $last:" | tr "[:print:]" -
95 limiter=
96 elif test "$new" = "$last"
97 then
98 return 0
99 else
100 echo "Version $last; changes since $new:"
101 echo "Version $last; changes since $new:" | tr "[:print:]" -
102 limiter="$new_cid.."
104 echo
105 git rev-list --no-merges "$limiter$last_cid" |
106 git diff-tree --date=iso --stat --format=medium --stdin
107 test "$new" = none || echo
109 last=$new
110 last_cid=$new_cid
113 dpkg-parsechangelog --format rfc822 --all | {
114 while read line
116 if version=$(version_line "$line")
117 then
118 # strip Debian revision
119 upstream_version=${version%-*}
121 if git rev-parse --verify -q "v$upstream_version" > /dev/null
122 then
123 # upstream release
124 add_version "$upstream_version" "v$upstream_version"
125 else
126 # snapshot
127 cid=$(read_commit_id "$upstream_version") || exit 1
128 add_version "$upstream_version" "$cid"
131 done
132 add_version none none