Root/debian/changelog.upstream.awk

1#!/bin/awk -f
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.
5#
6# Requires a working /dev/stderr.
7#
8# Usage:
9# dpkg-parsechangelog --format rfc822 --all |
10# awk -f debian/changelog.upstream.awk
11
12# If argument matches /^Version: /, return remaining text.
13# Result is nonempty if and only if argument matches.
14function version_line(line) {
15    if (line ~ /^Version: /) {
16        sub(/^Version: /, "", line);
17        return line;
18    }
19    return "";
20}
21
22# If argument matches /^\*.* from commit /, return remaining text.
23# Result is nonempty if and only if argument matches.
24function commit_id_line(line) {
25    if (line ~ / from commit /) {
26        sub(/^.* from commit /, "", line);
27        sub(/[(][Cc]loses.*/, "", line);
28        sub(/[^0-9a-f]*$/, "", line);
29        return line;
30    }
31    return "";
32}
33
34# Read standard input, scanning for a changelog entry of the
35# form “* New snapshot, taken from commit <blah>.”
36# Result is <blah>.
37# Result is empty and writes a message to standard error if no such entry is
38# found before the next Version: line with a different upstream
39# version (or EOF).
40# Argument is the upstream version sought.
41function read_commit_id(upstream, line,version,corresponding_upstream,commit) {
42    while (getline line) {
43        version = version_line(line);
44        corresponding_upstream = version;
45        sub(/-[^-]*$/, "", corresponding_upstream);
46        if (version != "" && corresponding_upstream != upstream)
47            break;
48
49        commit = commit_id_line(line);
50        if (commit != "")
51            return commit;
52    }
53
54    print "No commit id for " upstream >> "/dev/stderr";
55    return "";
56}
57
58BEGIN {
59    last = "none";
60    last_cid = "none";
61    cl = "debian/changelog.upstream";
62}
63
64# Add a list of all revisions up to last to debian/changelog.upstream
65# and set last = new_cid.
66# new is a user-readable name for the commit new_cide.
67function add_version(new,new_cid, limiter,versionline,command,line) {
68    if (last == "none") {
69        printf "" > cl;
70        last = new;
71        last_cid = new_cid;
72        return 0;
73    }
74
75    if (new == "none") {
76        versionline = "Version " last;
77        limiter = "";
78    } else {
79        versionline = "Version " last "; changes since " new ":";
80        limiter = new_cid "..";
81    }
82    print versionline >> cl;
83    gsub(/./, "-", versionline);
84    print versionline >> cl;
85
86    print "" >> cl;
87    command = "git shortlog \"" limiter last_cid "\"";
88    while(command | getline line)
89        print line >> cl;
90
91    if (new != "none")
92        print "" >> cl;
93    last = new;
94    last_cid = new_cid;
95}
96
97{
98    version = version_line($0);
99    if (version != "") {
100        # strip Debian revision
101        upstream_version = version;
102        sub(/-[^-]*$/, "", upstream_version);
103
104        commit = read_commit_id(upstream_version);
105        if (commit == "")
106            exit 1;
107        add_version(upstream_version, commit);
108    }
109}
110
111END {
112    add_version("none", "none");
113}
114

Archive Download this file



interactive