Skip to content

Commit 29caac4

Browse files
committed
remove unmodified templated sections from the master
1 parent e019f99 commit 29caac4

File tree

1 file changed

+41
-7
lines changed

1 file changed

+41
-7
lines changed

Porting/merge-deltas.pl

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,12 @@ ( $tree )
9494
return join '', $handler->{$name}->( $directive, $attr, @nodes );
9595
}
9696

97+
sub pod_excerpt ( $tree, $begin, $end ) {
98+
return as_pod( [ Document => {}, $tree->@[ $begin .. $end ] ] );
99+
}
100+
97101
# CONTENT MANIPULATION SUBROUTINES
98102

99-
# copy the whole section content
100103
sub copy_section ( $master, $title, $delta ) {
101104
my ( $master_pos, $delta_pos ) = find_pos_in( $master, $delta, $title );
102105

@@ -108,6 +111,23 @@ ( $master, $title, $delta )
108111
0, $delta->@[ $delta_pos + 1 .. $end_pos ];
109112
}
110113

114+
sub remove_identical ( $master, $title, $template ) {
115+
my ( $master_pos, $template_pos ) =
116+
find_pos_in( $master, $template, $title );
117+
118+
# find the end of the section in both
119+
my $master_end_pos = next_header_pos( $master, 1, $master_pos ) - 1;
120+
my $template_end_pos = next_header_pos( $template, 1, $template_pos ) - 1;
121+
122+
# drop the section from the master if it's identical
123+
# to that in the template
124+
if ( pod_excerpt( $master, $master_pos, $master_end_pos ) eq
125+
pod_excerpt( $template, $template_pos, $template_end_pos ) )
126+
{
127+
splice @$master, $master_pos, $master_end_pos - $master_pos + 1;
128+
}
129+
}
130+
111131
# map each section to an action
112132
my %ACTION_FOR = (
113133
'NAME' => 'skip',
@@ -148,19 +168,17 @@ ($string)
148168
$parser->parse_string_document($string)->root;
149169
}
150170

151-
sub merge_into ( $master, $delta, $file ) {
152-
153-
# loop over the =head1 sections
171+
sub loop_head1 ( $master, $tree, $file, $cb ) {
154172
for my $title (
155173
map $_->[2], # grab the title
156174
grep ref eq 'ARRAY' && $_->[0] eq 'head1', # of the =head1
157-
@$delta # of the delta
175+
@$tree # of the tree
158176
)
159177
{
160178
die "Unexpected section '=head1 $title' in $file\n"
161179
unless exists $ACTION_FOR{$title};
162180
next if $ACTION_FOR{$title} eq 'skip';
163-
copy_section( $master, $title, $delta );
181+
$cb->( $master, $title, $tree );
164182
}
165183
}
166184

@@ -194,9 +212,25 @@ (@argv)
194212
)
195213
{
196214
my ( $file, $delta ) = @$file_tree;
197-
merge_into( $master, $delta, $file );
215+
loop_head1(
216+
$master, $delta, $file,
217+
sub ( $master, $title, $delta ) {
218+
copy_section( $master, $title, $delta );
219+
}
220+
);
198221
}
199222

223+
# find all sections in the template identical to those
224+
# in the master and remove them (from the master)
225+
my $template_file = 'Porting/perldelta_template.pod';
226+
my $template = tree_for( slurp($template_file) );
227+
loop_head1(
228+
$master, $template, $template_file,
229+
sub ( $master, $title, $template ) {
230+
remove_identical( $master, $title, $template );
231+
}
232+
);
233+
200234
# save the result
201235
open my $fh, '>:utf8', $final_delta
202236
or die "Can't open $final_delta for writing: $!";

0 commit comments

Comments
 (0)