Meta/cook: (experimental) record source material
Junio C Hamano committed
Dec 4, 2021 at 22:10 UTC
bb35080538b578c1852fd73e93381dc469d589b5
1 file changed
+108
-5
cook
+108
-5
@@ -93,6 +93,73 @@ sub topic_relation {
93
}
94
}
95
96
+sub get_message_parent {
97
+ my ($mid) = @_;
98
+ my @line = ();
99
+ my %irt = ();
100
+
101
+ open(my $fh, "-|", qw(curl -s),
102
+ "https://lore.kernel.org/git/" . "$mid" . "/raw");
103
+ while (<$fh>) {
104
+ last if (/^$/);
105
+ chomp;
106
+ if (/^\s/) {
107
+ $line[-1] .= $_;
108
+ } else {
109
+ push @line, $_;
110
+ }
111
+ }
112
+ while (<$fh>) { # slurp
113
+ }
114
+ close($fh);
115
+ for (@line) {
116
+ if (s/^in-reply-to:\s*//i) {
117
+ while (/\s*<([^<]*)>\s*(.*)/) {
118
+ $irt{$1} = $1;
119
+ $_ = $2;
120
+ }
121
+ }
122
+ }
123
+ keys %irt;
124
+}
125
+
126
+sub get_source {
127
+ my ($branch) = @_;
128
+ my @id = ();
129
+ my %msgs = ();
130
+ my %source = ();
131
+ my %skip_me = ();
132
+
133
+ open(my $fh, "-|",
134
+ qw(git log --notes=amlog --first-parent --format=%N ^master),
135
+ $branch);
136
+ while (<$fh>) {
137
+ if (s/^message-id:\s*<(.*)>\s*$/$1/i) {
138
+ my $msg = $_;
139
+ $msgs{$msg} = [get_message_parent($msg)];
140
+ if (!%source) {
141
+ $source{$msg} = $msg;
142
+ }
143
+ }
144
+ }
145
+ close($fh);
146
+
147
+ # Collect parent messages that are not in the series,
148
+ # as they are likely to be the cover letters.
149
+ for my $msg (keys %msgs) {
150
+ for my $parent (@{$msgs{$msg}}) {
151
+ if (!exists $msgs{$parent}) {
152
+ $source{$parent} = 1;
153
+ }
154
+ }
155
+ }
156
+
157
+ map {
158
+ " source: <$_>";
159
+ }
160
+ (keys %source);
161
+}
162
+
163
=head1
164
Inspect the current set of topics
165
@@ -446,22 +513,28 @@ sub read_previous {
513
text => join("\n", @{$ary}),
514
};
515
} else {
449
- my @desc = ();
516
+ my (@desc, @src, @txt) = ();
517
+
518
while (@{$ary}) {
519
my $elem = shift @{$ary};
520
last if ($elem eq '');
521
push @desc, $elem;
522
}
455
- my @txt = map {
523
+ for (@{$ary}) {
524
s/^\s+//;
525
$_ = "$lead$_";
526
s/\s+$//;
459
- $_;
460
- } @{$ary};
527
+ if (/^${lead}source:/) {
528
+ push @src, $_;
529
+ } else {
530
+ push @txt, $_;
531
+ }
532
+ }
533
534
$description{$branch} = +{
535
desc => join("\n", @desc),
536
text => join("\n", @txt),
537
+ src => join("\n", @src),
538
};
539
}
540
}
@@ -502,6 +575,12 @@ sub write_cooking {
575
}
576
print $fh "\n", $d->{'text'}, "\n";
577
}
578
+ if ($d->{'src'}) {
579
+ if (!$d->{'text'}) {
580
+ print $fh "\n";
581
+ }
582
+ print $fh $d->{'src'}, "\n";
583
+ }
584
$lead = "\n\n";
585
}
586
}
@@ -658,16 +737,39 @@ sub merge_cooking {
737
# Ignore new topics without anything merged
738
if (topic_in_seen($current->{$topic}{'desc'})) {
739
push @new_topic, $topic;
740
+ # lazily find the source for a new topic.
741
+ $current->{$topic}{'src'} = join("\n", get_source($topic));
742
}
743
next;
744
}
745
+
746
# Annotate if the contents of the topic changed
747
+ my $topic_changed = 0;
748
my $n = $current->{$topic}{'desc'};
749
my $o = $td->{$topic}{'desc'};
750
if ($n ne $o) {
751
+ $topic_changed = 1;
752
$td->{$topic}{'desc'} = $n . "\n<<\n" . $o ."\n>>";
753
tweak_willdo($td->{$topic});
754
}
755
+
756
+ # Keep the original source for unchanged topic
757
+ if ($topic_changed) {
758
+ # lazily find out the source for the latest round.
759
+ $current->{$topic}{'src'} = join("\n", get_source($topic));
760
+
761
+ $n = $current->{$topic}{'src'};
762
+ $o = $td->{$topic}{'src'};
763
+ if ($n ne $o) {
764
+ $o = join("\n",
765
+ map { s/^\s*//; "-$_"; }
766
+ split(/\n/, $o));
767
+ $n = join("\n",
768
+ map { s/^\s*//; "+$_"; }
769
+ split(/\n/, $n));
770
+ $td->{$topic}{'src'} = join("\n", "<<", $o, $n, ">>");
771
+ }
772
+ }
773
}
774
775
for my $topic (sort keys %{$td}) {
@@ -683,6 +785,7 @@ sub merge_cooking {
785
for (@new_topic) {
786
push @{$sd->{$new_topics}}, $_;
787
$td->{$_}{'desc'} = $current->{$_}{'desc'};
788
+ $td->{$_}{'src'} = $current->{$_}{'src'};
789
}
790
791
if (!$incremental) {
@@ -944,8 +1047,8 @@ sub havedone {
1047
# WhatsCooking
1048
1049
sub doit {
947
- my $topic = get_commit();
1050
my $cooking = read_previous('Meta/whats-cooking.txt');
1051
+ my $topic = get_commit($cooking);
1052
merge_cooking($cooking, $topic);
1053
write_cooking('Meta/whats-cooking.txt', $cooking);
1054
}