Meta/cook: attempt to improve the source discovery
Junio C Hamano committed
Apr 10, 2026 at 09:59 UTC
7157113734713d4250d9c99258614e8eb8249cb2
1 file changed
+19
-4
cook
+19
-4
@@ -158,6 +158,7 @@ sub get_source {
158
my @id = ();
159
my %msgs = ();
160
my @msgs = ();
161
+ my %children = ();
162
my %source = ();
163
my %skip_me = ();
164
@@ -175,15 +176,19 @@ sub get_source {
176
177
# Collect parent messages that are not in the series,
178
# as they are likely to be the cover letters.
179
+ # but of course the patch could be a reply to an
180
+ # ordinary message.
181
for my $msg (@msgs) {
182
for my $parent (@{$msgs{$msg}}) {
183
if (!exists $msgs{$parent}) {
184
$source{$parent}++;
185
+ $children{$parent} ||= [];
186
+ push @{$children{$parent}}, $msg;
187
}
188
}
189
}
190
186
- reduce_sources(\@msgs, \%msgs, \%source);
191
+ reduce_sources(\@msgs, \%msgs, \%source, \%children);
192
193
map {
194
" source: <$_>";
@@ -193,10 +198,10 @@ sub get_source {
198
199
sub reduce_sources {
200
# Message-source specific hack
196
- my ($msgs_array, $msgs_map, $src_map) = @_;
201
+ my ($msgs_array, $msgs_map, $src_map, $child_map) = @_;
202
198
- # messages without parent, or a singleton patch
199
- if ((! %$src_map && @{$msgs_array}) || (@{$msgs_array} == 1)) {
203
+ # a singleton
204
+ if (@{$msgs_array} == 1) {
205
%{$src_map} = ($msgs_array->[0] => 1);
206
return;
207
}
@@ -213,6 +218,16 @@ sub reduce_sources {
218
return;
219
}
220
221
+ # replace a parent with its sole child
222
+ my %replace = ();
223
+ for my $src (keys %$src_map) {
224
+ if (@{$child_map->{$src}} == 1) {
225
+ $replace{$child_map->{$src}->[0]} = 1;
226
+ } else {
227
+ $replace{$src} = $src_map->{$src};
228
+ }
229
+ }
230
+ %$src_map = %replace;
231
}
232
233
=head1