summaryrefslogtreecommitdiff
path: root/v4l/scripts/hghead.pl
blob: abca09c4540ecc5c857bfe47bb96a55a3b14ea34 (plain)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/usr/bin/perl
use strict;

#################################################################
# analyse diffs

my $in = shift;
my $line;
my $subject;
my $sub_ok=0;
my $init=0;
my $num=0;
my $hgimport=0;
my $mmimport=0;
my $maint_ok=0;
my $noblank=1;
my $maintainer_name=$ENV{CHANGE_LOG_NAME};
my $maintainer_email=$ENV{CHANGE_LOG_EMAIL_ADDRESS};
my $from="";
my $body="";
my $priority="";
my $signed="";
my $fromname="";

open IN,  "<$in";

while ($line = <IN>) {
	if ($line =~ m/^\s*Index.*/) {
		last;
	}
	if ($line =~ m/^diff .*/) {
		last;
	}
	if ($line =~ m/^\-\-\- .*/) {
		last;
	}
	if ($line =~ m/^\-\-\-\-.*/) {
		$body="";
		next;
	}
	if ($line =~ m/^\-\-\-.*/) {
		last;
	}
	if ($line =~ m/^\+\+\+ .*/) {
		last;
	}

	if ($line =~ m/^#\s*Date\s*(.*)/) {
		print "#Date: $1\n";
		next;
	}

	if ($line =~ m/^Date:\s*(.*)/) {
		print "#Date: $1\n";
		next;
	}

	$line =~ s/^#\sUser/From:/;

	my $tag=$line;
	my $arg=$line;
	$tag =~ s/\s*([^\s]+:)\s*(.*)\n/\1/;
	$arg =~ s/\s*([^\s]+:)\s*(.*)\n/\2/;

	$tag =~ tr/A-Z/a-z/;

	if ($tag =~ m/^from:/) {
		if ($arg =~ m/^[\s\"]*([^\"]*)[\s\"]*<(.*)>/) {
			if ($1 eq "") {
				next;
			}
			my $name=$1;
			my $email=$2;
			$name =~ s/\s+$//;
			$email =~ s/\s+$//;
			$fromname="$name <$email>";
			$from= "From: $fromname\n";
			next;
		}
		if ($line =~ m/^From:\sakpm\@osdl.org/) {
			$mmimport=1;
			next;
		}
		print "Bad: author line have a wrong syntax: $line\n";
		die;
	}

	if ($tag =~ m/^subject:/) {
		$subject = "$arg\n";
		$sub_ok = 1;
		next;
	}

	if ($tag =~ m/^priority:/) {
		$arg =~ tr/A-Z/a-z/;

		# Replace the -git branch names for high/normal/low
		$arg =~ s/^fixes$/high/;
		$arg =~ s/^fix$/high/;
		$arg =~ s/^working$/normal/;
		$arg =~ s/^work$/normal/;
		$arg =~ s/^pending$/low/;
		$priority = "Priority: $arg";
		next;
	}

	if ($line =~ m;^ .*\/.*\| *[0-9]*;) {
		next;
	}
	if ($line =~m/\d+\s*file.* changed, /) {
		next;
	}

	if ($tag =~ m/^signed-off-by:.*/) {
		$noblank=1;
		if ($line =~ m/$maintainer_name/) {
			$maint_ok=1;
		}

		$signed="$signed$line";
		next;
	}
	if ( ($line =~ m/^\# HG changeset patch/) ||
	     ($line =~ m/^has been added to the -mm tree.  Its filename is/) ) {
		$sub_ok=0;
		$init=0;
		$num=0;
		$maint_ok=0;
		$noblank=1;
		$from="";
		$body="";
		$subject="";
		$hgimport=1;
		next;
	}

	if ($tag =~ m/^(acked-by|thanks-to|reviewed-by|noticed-by|tested-by|cc):/) {
		$signed="$signed$line";
		next;
	}

	# Keep review lines together with the signatures
	if ($line =~ m/^\[.*\@.*\:.*\]\n/) {
		$signed="$signed$line";
		next;
	}

	if ($tag =~ m/changeset:\s*(.*)\n/) {
		$num=$1;
	}

	if ($line =~ m|^(V4L\/DVB\s*\(.+\)\s*:.*\n)|) {
		$subject=$1;
		$sub_ok = 1;
		$line="\n";
	}

	if ($line =~ m/^#/) {
		next;
	}
	if ($sub_ok == 0) {
		if ($line =~ m/^\s*\n/) {
			next;
		}
		$sub_ok=1;
		if ($subject =~ m|V4L\/DVB\s*(.+)|) {
			$subject=$1;
		}
		$subject=$line;
		next;
	}

	if ($noblank) {
		if ($line =~ m/^\n/) {
			next;
		}
	}
	if (!$init) {
		$init=1;
		$noblank=0;
	}
	$body="$body$line";
}
close IN;

if ($from eq "") {
	print "Bad: author doesn't exist!\n";
	die;
}

if (!$maint_ok && $maintainer_name && $maintainer_email) {
	print "#No maintainer's signature. Adding it.\n";
	$signed=$signed."Signed-off-by: $maintainer_name <$maintainer_email>\n";
}

if (!$signed =~ m/$from/) {
	print "Bad: Author didn't signed his patch!\n";
	die;
}

$from=~s/^[\n\s]+//;
$from=~s/[\n\s]+$//;

$subject=~s/^[\n\s]+//;
$subject=~s/[\n\s]+$//;

$body=~s/^[\n]+//;
$body=~s/[\n\s]+$//;

if ($priority ne "") {
	$body="$body\n\n$priority";
}

$body="$body\n\n$signed";

$body=~s/^[\n\s]+//;
$body=~s/[\n\s]+$//;

# First from is used by hg to recognize commiter name
print "#Committer: $maintainer_name <$maintainer_email>\n";
print "$subject\n\n$from\n\n$body\n";