What's cooking (2010/01 #03)
[git/dscho.git] / cook.sh
blob7c0d12778d7b7e2dc6b9381b8d84929f22135299
1 #!/bin/sh
3 LANG=C LC_ALL=C GIT_PAGER=cat
4 export LANG LC_ALL GIT_PAGER
6 tmpdir=/var/tmp/cook.$$
7 mkdir "$tmpdir" || exit
8 tmp="$tmpdir/t"
9 trap 'rm -fr "$tmpdir"' 0
11 git branch --merged "master" | sed -n -e 's/^..//' -e '/\//p' >"$tmp.in.master"
12 git branch --merged "pu" | sed -n -e 's/^..//' -e '/\//p' >"$tmp.in.pu"
14 comm -13 "$tmp.in.master" "$tmp.in.pu"
15 git branch --no-merged pu |
16 sed -n -e 's/^..//' -e '/\//p'
17 } >"$tmp.branches"
19 git log --first-parent --format="%H %ci" master..next |
20 sed -e 's/ [0-2][0-9]:[0-6][0-9]:[0-6][0-9] [-+][0-2][0-9][0-6][0-9]$//' >"$tmp.next"
21 git rev-list master..pu >"$tmp.commits.in.pu"
23 format_branch () {
24 # branch=$1 others=$2
25 git rev-list --no-merges --topo-order "master..$1" --not $2 >"$tmp.list"
26 count=$(wc -l <"$tmp.list" | tr -d ' ')
27 label="* $1 ($(git show -s --format="%ai" $1 | sed -e 's/ .*//')) $count commit"
28 test "$count" = 1 || label="${label}s"
30 echo "$label"
31 lasttimelabel=
32 lastfoundmerge=
33 while read commit
35 merged= merged_with=
36 while read merge at
38 if test -n "$lastfoundmerge"
39 then
40 if test "$lastfoundmerge" = "$merge"
41 then
42 lastfoundmerge=
43 else
44 continue
47 mb=$(git merge-base $merge $commit)
48 if test "$mb" = "$commit"
49 then
50 merged=$at merged_with=$merge
51 else
52 break
54 done <"$tmp.next"
56 lastfoundmerge=$merged_with
57 thistimelabel=
58 if test -n "$merged"
59 then
60 thistimelabel=$merged
61 commitlabel="+"
62 elif grep "$commit" "$tmp.commits.in.pu" >/dev/null
63 then
64 commitlabel="-"
65 else
66 commitlabel="."
68 if test "$lasttimelabel" != "$thistimelabel"
69 then
70 with=$(git rev-parse --short $merged_with)
71 echo " (merged to 'next' on $thistimelabel at $with)"
72 lasttimelabel=$thistimelabel
74 git show -s --format=" $commitlabel %s" $commit
75 done <"$tmp.list"
78 add_desc () {
79 kind=$1
80 shift
81 test -z "$description" || description="$description;"
82 others=
83 while :
85 other=$1
86 case "$other" in
87 "#EPO-"*) other="early parts of ${other#"#EPO-"}"
88 esac
89 shift
90 case "$#,$others" in
91 0,)
92 others="$other"
93 break ;;
94 0,?*)
95 others="$others and $other"
96 break ;;
97 *,)
98 others="$other"
100 *,?*)
101 others="$others, $other"
103 esac
104 done
105 description="$description $kind $others"
108 show_topic () {
109 old=$1 new=$2
111 sed -n -e '/^ ..*/p' -e '/^\* /p' "$old" >"$tmp.old.nc"
112 sed -n -e '/^ ..*/p' -e '/^\* /p' "$new" >"$tmp.new.nc"
113 if cmp "$tmp.old.nc" "$tmp.new.nc" >/dev/null
114 then
115 cat "$old"
116 else
117 cat "$new"
118 echo "<<"
119 cat "$old"
120 echo ">>"
124 # List commits that are shared between more than one topic branches
125 while read b
127 git rev-list --no-merges "master..$b"
128 done <"$tmp.branches" | sort | uniq -d >"$tmp.shared"
130 # Set of branches related to each other due to sharing the same commit
131 while read shared
133 b=$(git branch --contains "$shared" | sed -n -e 's/^..//' -e '/\//p')
134 echo "" $b ""
135 done <"$tmp.shared" | sort -u >"$tmp.related"
137 serial=1
138 while read b
140 related=$(grep " $b " "$tmp.related" | tr ' ' '\012' | sort -u | sed -e '/^$/d')
142 based_on= based_on_msg=
143 used_by=
144 forks=
145 same_as=
146 if test -n "$related"
147 then
148 for r in $related
150 test "$b" = "$r" && continue
151 based=$(git rev-list --no-merges $b..$r | wc -l | tr -d ' ')
152 bases=$(git rev-list --no-merges $r..$b | wc -l | tr -d ' ')
153 case "$based,$bases" in
154 0,0)
155 same_as="$same_as$r "
157 0,*)
158 based_on="$based_on$r "
159 based_on_msg="$based_on_msg$r "
161 *,0)
162 used_by="$used_by$r "
164 *,*)
165 if test $based -lt $bases
166 then
167 based_on="$based_on$r "
168 based_on_msg="${based_on_msg}#EPO-$r "
169 else
170 forks="$forks$r "
173 esac
174 done
178 format_branch "$b" "$based_on"
180 description=
181 test -z "$same_as" || add_desc 'is same as' $same_as
182 test -z "$based_on" || add_desc 'uses' $based_on_msg
183 test -z "$used_by" || add_desc 'is used by' $used_by
184 test -z "$forks" || add_desc 'shares commits with' $forks
186 test -z "$description" ||
187 echo " (this branch$description.)"
188 } >"$tmp.output.$serial"
189 echo "$b $serial"
190 serial=$(( $serial + 1 ))
191 done <"$tmp.branches" >"$tmp.output.toc"
193 eval $(date +"monthname=%b month=%m year=%Y date=%d dow=%a")
195 incremental=$(
196 cd Meta &&
197 if git diff --quiet --no-ext-diff HEAD -- whats-cooking.txt >/dev/null
198 then
199 echo no
200 else
201 echo yes
205 # Find the current issue
206 eval $(sed -ne '/^Subject: /{
207 s/^Subject: What.s cooking in git.git (\([A-Z][a-z][a-z]\) \([0-9][0-9][0-9][0-9]\), #\([0-9][0-9]*\); [A-Z][a-z][a-z], [0-9][0-9])$/lastmon=\1 lastyear=\2 lastissue=\3/p
209 }' Meta/whats-cooking.txt)
210 if test "$monthname $year" = "$lastmon $lastyear"
211 then
212 if test "$incremental" = no
213 then
214 issue=$(( $lastissue + 1 ))
215 else
216 issue=$(( lastissue + 0 ))
218 else
219 issue=1
222 issue=$( printf "%02d" $issue )
223 last=whats-cooking.txt
225 master_at=$(git rev-parse --verify refs/heads/master)
226 next_at=$(git rev-parse --verify refs/heads/next)
227 cat >"$tmp.output.blurb" <<EOF
228 To: git@vger.kernel.org
229 Subject: What's cooking in git.git ($monthname $year, #$issue; $dow, $date)
230 X-master-at: $master_at
231 X-next-at: $next_at
233 What's cooking in git.git ($monthname $year, #$issue; $dow, $date)
234 --------------------------------------------------
236 Here are the topics that have been cooking. Commits prefixed with '-' are
237 only in 'pu' while commits prefixed with '+' are in 'next'. The ones
238 marked with '.' do not appear in any of the branches, but I am still
239 holding onto them.
243 if test -z "$NO_TEMPLATE" && test -f "Meta/$last"
244 then
245 template="Meta/$last"
246 else
247 template=/dev/null
249 perl -w -e '
250 my $section = undef;
251 my $serial = 1;
252 my $blurb = "b..l..u..r..b";
253 my $branch = $blurb;
254 my $tmp = $ARGV[0];
255 my $incremental = $ARGV[1] eq "yes";
256 my $last_empty = undef;
257 my (@section, %section, @branch, %branch, %description, @leader);
258 my $in_unedited_olde = 0;
260 while (<STDIN>) {
261 if ($in_unedited_olde) {
262 if (/^>>$/) {
263 $in_unedited_olde = 0;
264 $_ = " | $_";
266 } elsif (/^<<$/) {
267 $in_unedited_olde = 1;
270 if ($in_unedited_olde) {
271 $_ = " | $_";
274 if (defined $section && /^-{20,}$/) {
275 $_ = "\n";
277 if (/^$/) {
278 $last_empty = 1;
279 next;
281 if (/^\[(.*)\]\s*$/) {
282 $section = $1;
283 $branch = undef;
284 if ($section eq "New Topics" && !$incremental) {
285 $section = "Old New Topics";
287 if (!exists $section{$section}) {
288 push @section, $section;
289 $section{$section} = [];
291 next;
293 if (defined $section && /^\* (\S+) /) {
294 $branch = $1;
295 $last_empty = 0;
296 if (!exists $branch{$branch}) {
297 push @branch, [$branch, $section];
298 $branch{$branch} = 1;
300 push @{$section{$section}}, $branch;
302 if (defined $branch) {
303 my $was_last_empty = $last_empty;
304 $last_empty = 0;
305 if (!exists $description{$branch}) {
306 $description{$branch} = [];
308 if ($was_last_empty) {
309 push @{$description{$branch}}, "\n";
311 push @{$description{$branch}}, $_;
315 if (open I, "<$tmp.output.toc") {
316 $section = "New Topics";
317 while (<I>) {
318 my ($branch, $oldserial) = /^(\S*) (\d+)$/;
319 next if (exists $branch{$branch});
320 if (!exists $section{$section}) {
321 # Have it at the beginning
322 unshift @section, $section;
323 $section{$section} = [];
325 push @{$section{$section}}, $branch;
326 push @branch, [$branch, $section];
327 $branch{$branch} = 1;
328 if (!exists $description{$branch}) {
329 $description{$branch} = [];
331 open II, "<$tmp.output.$oldserial";
332 while (<II>) {
333 push @{$description{$branch}}, $_;
335 close II;
337 close I;
340 while (0 <= @{$description{$blurb}}) {
341 my $last = pop @{$description{$blurb}};
342 if ($last =~ /^$/ || $last =~ /^-{20,}$/) {
343 next;
344 } else {
345 push @{$description{$blurb}}, $last;
346 last;
350 open O, ">$tmp.template.blurb";
351 for (@{$description{$blurb}}) {
352 print O $_;
354 close O;
356 open TOC, ">$tmp.template.toc";
357 $serial = 1;
358 for my $section (@section) {
359 for my $branch (@{$section{$section}}) {
360 print TOC "$branch $serial $section\n";
361 open O, ">$tmp.template.$serial";
362 for (@{$description{$branch}}) {
363 print O $_;
365 close O;
366 $serial++;
369 ' <"$template" "$tmp" "$incremental"
371 tmpserial=$(
372 tail -n 1 "$tmp.template.toc" |
373 read branch serial section &&
374 echo $serial
377 # Assemble them all
379 if test -z "$TO_STDOUT"
380 then
381 exec >"Meta/whats-cooking.txt"
384 if test -s "$tmp.template.blurb"
385 then
386 sed -e '/^---------------*$/q' <"$tmp.output.blurb"
387 sed -e '1,/^---------------*$/d' <"$tmp.template.blurb"
388 else
389 cat "$tmp.output.blurb"
392 current='
393 --------------------------------------------------
394 [Graduated to "master"]
396 while read branch oldserial section
398 test "$section" = 'Graduated to "master"' &&
399 test "$incremental" = no && continue
401 tip=$(git rev-parse --quiet --verify "refs/heads/$branch") || continue
402 mb=$(git merge-base master $tip)
403 test "$mb" = "$tip" || continue
404 if test -n "$current"
405 then
406 echo "$current"
407 current=
408 else
409 echo
411 cat "$tmp.template.$oldserial"
412 done <"$tmp.template.toc"
414 current=
415 while read branch oldserial section
417 found=$(grep "^$branch " "$tmp.output.toc") || continue
418 newserial=$(expr "$found" : '[^ ]* \(.*\)')
419 if test "$current" != "$section"
420 then
421 current=$section
422 echo "
423 --------------------------------------------------
424 [$section]
426 else
427 echo
430 show_topic "$tmp.template.$oldserial" "$tmp.output.$newserial"
431 done <"$tmp.template.toc"