cook.sh: separate reading and output of template in separate phases

This will make it possible to prepend new topics to the New Topics section when working incrementally.

Junio C Hamano committed Aug 23, 2009 at 16:52 UTC 8c4b727fb150a1f8a09840b8572126a3c3aa9375
1 file changed +44 -15
cook.sh
+44 -15
@@ -214,7 +214,7 @@ fi
214
215 master_at=$(git rev-parse --verify refs/heads/master)
216 next_at=$(git rev-parse --verify refs/heads/next)
217 -cat >"$tmp.output.0" <<EOF
217 +cat >"$tmp.output.blurb" <<EOF
218 To: git@vger.kernel.org
219 Subject: What's cooking in git.git ($monthname $year, #$issue; $dow, $date)
220 X-master-at: $master_at
@@ -239,16 +239,15 @@ fi
239 perl -w -e '
240 my $section = undef;
241 my $serial = 1;
242 - my $branch = "b:l:u:r:b";
242 + my $blurb = "b..l..u..r..b";
243 + my $branch = $blurb;
244 my $tmp = $ARGV[0];
245 my $incremental = $ARGV[1] eq "yes";
246 my $last_empty = undef;
246 -
247 - open TOC, ">$tmp.template.toc";
248 - open O, ">$tmp.template.0";
247 + my (@section, %section, @branch, %branch, %description, @leader);
248
249 while (<STDIN>) {
251 - if (defined $section && /^-{20,}/) {
250 + if (defined $section && /^-{20,}$/) {
251 $_ = "\n";
252 }
253 if (/^$/) {
@@ -261,19 +260,49 @@ perl -w -e '
260 if ($section eq "New Topics" && !$incremental) {
261 $section = "Old New Topics";
262 }
263 + if (!exists $section{$section}) {
264 + push @section, $section;
265 + $section{$section} = [];
266 + }
267 next;
268 }
269 if (defined $section && /^\* (\S+) /) {
270 $branch = $1;
271 $last_empty = 0;
269 - open O, ">$tmp.template.$serial";
270 - print TOC "$branch $serial $section\n";
271 - $serial++;
272 + if (!exists $branch{$branch}) {
273 + push @branch, [$branch, $section];
274 + $branch{$branch} = (scalar @branch) - 1;
275 + }
276 + push @{$section{$section}}, $branch;
277 }
278 if (defined $branch) {
274 - print O "\n" if ($last_empty);
279 + if ($last_empty) {
280 + $_ = "\n$_";
281 + }
282 $last_empty = 0;
276 - print O "$_";
283 + if (!exists $description{$branch}) {
284 + $description{$branch} = [];
285 + }
286 + push @{$description{$branch}}, $_;
287 + }
288 + }
289 +
290 + open O, ">$tmp.template.blurb";
291 + for (@{$description{$blurb}}) {
292 + print O $_;
293 + }
294 + close O;
295 +
296 + open TOC, ">$tmp.template.toc";
297 + for my $section (@section) {
298 + for my $branch (@{$section{$section}}) {
299 + my $serial = $branch{$branch};
300 + print TOC "$branch $serial $section\n";
301 + open O, ">$tmp.template.$serial";
302 + for (@{$description{$branch}}) {
303 + print O $_;
304 + }
305 + close O;
306 }
307 }
308 ' <"$template" "$tmp" "$incremental"
@@ -289,12 +318,12 @@ then
318 exec >"Meta/$lead/$issue.txt"
319 fi
320
292 -if test -s "$tmp.template.0"
321 +if test -s "$tmp.template.blurb"
322 then
294 - sed -e '/^---------------*/q' <"$tmp.output.0"
295 - sed -e '1,/^---------------*/d' <"$tmp.template.0"
323 + sed -e '/^---------------*/q' <"$tmp.output.blurb"
324 + sed -e '1,/^---------------*/d' <"$tmp.template.blurb"
325 else
297 - cat "$tmp.output.0"
326 + cat "$tmp.output.blurb"
327 fi | sed -e '$d'
328
329 while read branch serial