From 8c4b727fb150a1f8a09840b8572126a3c3aa9375 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 23 Aug 2009 16:52:31 -0700 Subject: [PATCH] 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. --- cook.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/cook.sh b/cook.sh index 54b1d66fb8..471a8da98e 100755 --- a/cook.sh +++ b/cook.sh @@ -214,7 +214,7 @@ fi master_at=$(git rev-parse --verify refs/heads/master) next_at=$(git rev-parse --verify refs/heads/next) -cat >"$tmp.output.0" <"$tmp.output.blurb" <$tmp.template.toc"; - open O, ">$tmp.template.0"; + my (@section, %section, @branch, %branch, %description, @leader); while () { - if (defined $section && /^-{20,}/) { + if (defined $section && /^-{20,}$/) { $_ = "\n"; } if (/^$/) { @@ -261,19 +260,49 @@ perl -w -e ' if ($section eq "New Topics" && !$incremental) { $section = "Old New Topics"; } + if (!exists $section{$section}) { + push @section, $section; + $section{$section} = []; + } next; } if (defined $section && /^\* (\S+) /) { $branch = $1; $last_empty = 0; - open O, ">$tmp.template.$serial"; - print TOC "$branch $serial $section\n"; - $serial++; + if (!exists $branch{$branch}) { + push @branch, [$branch, $section]; + $branch{$branch} = (scalar @branch) - 1; + } + push @{$section{$section}}, $branch; } if (defined $branch) { - print O "\n" if ($last_empty); + if ($last_empty) { + $_ = "\n$_"; + } $last_empty = 0; - print O "$_"; + if (!exists $description{$branch}) { + $description{$branch} = []; + } + push @{$description{$branch}}, $_; + } + } + + open O, ">$tmp.template.blurb"; + for (@{$description{$blurb}}) { + print O $_; + } + close O; + + open TOC, ">$tmp.template.toc"; + for my $section (@section) { + for my $branch (@{$section{$section}}) { + my $serial = $branch{$branch}; + print TOC "$branch $serial $section\n"; + open O, ">$tmp.template.$serial"; + for (@{$description{$branch}}) { + print O $_; + } + close O; } } ' <"$template" "$tmp" "$incremental" @@ -289,12 +318,12 @@ then exec >"Meta/$lead/$issue.txt" fi -if test -s "$tmp.template.0" +if test -s "$tmp.template.blurb" then - sed -e '/^---------------*/q' <"$tmp.output.0" - sed -e '1,/^---------------*/d' <"$tmp.template.0" + sed -e '/^---------------*/q' <"$tmp.output.blurb" + sed -e '1,/^---------------*/d' <"$tmp.template.blurb" else - cat "$tmp.output.0" + cat "$tmp.output.blurb" fi | sed -e '$d' while read branch serial -- 2.11.4.GIT