File: changelog.upstream.awk

package info (click to toggle)
fpgatools 0.0%2B201212-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,176 kB
  • sloc: ansic: 25,528; makefile: 284; sh: 119; awk: 75
file content (113 lines) | stat: -rw-r--r-- 2,813 bytes parent folder | download | duplicates (5)
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
#!/bin/awk -f
# Generate debian/changelog.upstream from debian/changelog and
# the git revision log.  Inspired by Gerrit Pape’s
# debian/changelog.upstream.sh, from the git-core Debian package.
#
# Requires a working /dev/stderr.
#
# Usage:
#	dpkg-parsechangelog --format rfc822 --all |
#	awk -f debian/changelog.upstream.awk

# If argument matches /^Version: /, return remaining text.
# Result is nonempty if and only if argument matches.
function version_line(line) {
	if (line ~ /^Version: /) {
		sub(/^Version: /, "", line);
		return line;
	}
	return "";
}

# If argument matches /^\*.* from commit /, return remaining text.
# Result is nonempty if and only if argument matches.
function commit_id_line(line) {
	if (line ~ / from commit /) {
		sub(/^.* from commit /, "", line);
		sub(/[(][Cc]loses.*/, "", line);
		sub(/[^0-9a-f]*$/, "", line);
		return line;
	}
	return "";
}

# Read standard input, scanning for a changelog entry of the
# form “* New snapshot, taken from commit <blah>.”
# Result is <blah>.
# Result is empty and writes a message to standard error if no such entry is
# found before the next Version: line with a different upstream
# version (or EOF).
# Argument is the upstream version sought.
function read_commit_id(upstream, line,version,corresponding_upstream,commit) {
	while (getline line) {
		version = version_line(line);
		corresponding_upstream = version;
		sub(/-[^-]*$/, "", corresponding_upstream);
		if (version != "" && corresponding_upstream != upstream)
			break;

		commit = commit_id_line(line);
		if (commit != "")
			return commit;
	}

	print "No commit id for " upstream >> "/dev/stderr";
	return "";
}

BEGIN {
	last = "none";
	last_cid = "none";
	cl = "debian/changelog.upstream";
}

# Add a list of all revisions up to last to debian/changelog.upstream
# and set last = new_cid.
# new is a user-readable name for the commit new_cide.
function add_version(new,new_cid, limiter,versionline,command,line) {
	if (last == "none") {
		printf "" > cl;
		last = new;
		last_cid = new_cid;
		return 0;
	}

	if (new == "none") {
		versionline = "Version " last;
		limiter = "";
	} else {
		versionline = "Version " last "; changes since " new ":";
		limiter = new_cid "..";
	}
	print versionline >> cl;
	gsub(/./, "-", versionline);
	print versionline >> cl;

	print "" >> cl;
	command = "git shortlog \"" limiter last_cid "\"";
	while(command | getline line)
		print line >> cl;

	if (new != "none")
		print "" >> cl;
	last = new;
	last_cid = new_cid;
}

{
	version = version_line($0);
	if (version != "") {
		# strip Debian revision
		upstream_version = version;
		sub(/-[^-]*$/, "", upstream_version);

		commit = read_commit_id(upstream_version);
		if (commit == "")
			exit 1;
		add_version(upstream_version, commit);
	}
}

END {
	add_version("none", "none");
}