[Refactoring] Reduce top-level code in prepare-ChangeLog
https://bugs.webkit.org/show_bug.cgi?id=74172
Reviewed by Ryosuke Niwa.
The objective is to make prepare-ChangeLog a loadable Perl module for unit testing.
This requires to remove top-level code. This patch is one of the incremental refactorings
for that.
* Scripts/prepare-ChangeLog: Moved some top-level code into generateFunctionLists().
(generateFunctionLists):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@102487 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Tools/Scripts/prepare-ChangeLog b/Tools/Scripts/prepare-ChangeLog
index 288eaa0..aded6c0 100755
--- a/Tools/Scripts/prepare-ChangeLog
+++ b/Tools/Scripts/prepare-ChangeLog
@@ -78,6 +78,7 @@
sub determinePropertyChanges($$$);
sub pluralizeAndList($$@);
sub generateFileList(\@\@\%);
+sub generateFunctionLists(\@\%);
sub isUnmodifiedStatus($);
sub isModifiedStatus($);
sub isAddedStatus($);
@@ -160,12 +161,9 @@
# Find the list of modified files
my @changed_files;
-my $changed_files_string;
-my %changed_line_ranges;
my %function_lists;
my @conflict_files;
-
my %supportedTestExtensions = map { $_ => 1 } qw(html shtml svg xml xhtml pl php);
my @addedRegressionTests = ();
my $didChangeRegressionTests = 0;
@@ -183,72 +181,7 @@
exit 1;
}
-if (@changed_files) {
- $changed_files_string = "'" . join ("' '", @changed_files) . "'";
-
- # For each file, build a list of modified lines.
- # Use line numbers from the "after" side of each diff.
- print STDERR " Reviewing diff to determine which lines changed.\n";
- my $file;
- open DIFF, "-|", diffCommand(@changed_files) or die "The diff failed: $!.\n";
- while (<DIFF>) {
- $file = makeFilePathRelative($1) if $_ =~ diffHeaderFormat();
- if (defined $file) {
- my ($start, $end) = extractLineRange($_);
- if ($start >= 0 && $end >= 0) {
- push @{$changed_line_ranges{$file}}, [ $start, $end ];
- } elsif (/DO_NOT_COMMIT/) {
- print STDERR "WARNING: file $file contains the string DO_NOT_COMMIT, line $.\n";
- }
- }
- }
- close DIFF;
-}
-
-# For each source file, convert line range to function list.
-if (%changed_line_ranges) {
- print STDERR " Extracting affected function names from source files.\n";
- foreach my $file (keys %changed_line_ranges) {
- # Find all the functions in the file.
- open SOURCE, $file or next;
- my @function_ranges = get_function_line_ranges(\*SOURCE, $file);
- close SOURCE;
-
- # Find all the modified functions.
- my @functions;
- my %saw_function;
- my @change_ranges = (@{$changed_line_ranges{$file}}, []);
- my @change_range = (0, 0);
- FUNCTION: foreach my $function_range_ref (@function_ranges) {
- my @function_range = @$function_range_ref;
-
- # Advance to successive change ranges.
- for (;; @change_range = @{shift @change_ranges}) {
- last FUNCTION unless @change_range;
-
- # If past this function, move on to the next one.
- next FUNCTION if $change_range[0] > $function_range[1];
-
- # If an overlap with this function range, record the function name.
- if ($change_range[1] >= $function_range[0]
- and $change_range[0] <= $function_range[1]) {
- if (!$saw_function{$function_range[2]}) {
- $saw_function{$function_range[2]} = 1;
- push @functions, $function_range[2];
- }
- next FUNCTION;
- }
- }
- }
-
- # Format the list of functions now.
-
- if (@functions) {
- $function_lists{$file} = "" if !defined $function_lists{$file};
- $function_lists{$file} .= "\n (" . join("):\n (", @functions) . "):";
- }
- }
-}
+generateFunctionLists(@changed_files, %function_lists);
# Get some parameters for the ChangeLog we are about to write.
my $date = changeLogDate($changeLogTimeZone);
@@ -412,7 +345,7 @@
if ($spewDiff && @changed_files) {
print STDERR " Running diff to help you write the ChangeLog entries.\n";
local $/ = undef; # local slurp mode
- open DIFF, "-|", createPatchCommand($changed_files_string) or die "The diff failed: $!.\n";
+ open DIFF, "-|", createPatchCommand("'" . join ("' '", @changed_files) . "'") or die "The diff failed: $!.\n";
print <DIFF>;
close DIFF;
}
@@ -437,6 +370,76 @@
exit;
+sub generateFunctionLists(\@\%)
+{
+ my ($changed_files, $function_lists) = @_;
+
+ my %changed_line_ranges;
+ if (@$changed_files) {
+ # For each file, build a list of modified lines.
+ # Use line numbers from the "after" side of each diff.
+ print STDERR " Reviewing diff to determine which lines changed.\n";
+ my $file;
+ open DIFF, "-|", diffCommand(@$changed_files) or die "The diff failed: $!.\n";
+ while (<DIFF>) {
+ $file = makeFilePathRelative($1) if $_ =~ diffHeaderFormat();
+ if (defined $file) {
+ my ($start, $end) = extractLineRange($_);
+ if ($start >= 0 && $end >= 0) {
+ push @{$changed_line_ranges{$file}}, [ $start, $end ];
+ } elsif (/DO_NOT_COMMIT/) {
+ print STDERR "WARNING: file $file contains the string DO_NOT_COMMIT, line $.\n";
+ }
+ }
+ }
+ close DIFF;
+ }
+
+ # For each source file, convert line range to function list.
+ if (%changed_line_ranges) {
+ print STDERR " Extracting affected function names from source files.\n";
+ foreach my $file (keys %changed_line_ranges) {
+ # Find all the functions in the file.
+ open SOURCE, $file or next;
+ my @function_ranges = get_function_line_ranges(\*SOURCE, $file);
+ close SOURCE;
+
+ # Find all the modified functions.
+ my @functions;
+ my %saw_function;
+ my @change_ranges = (@{$changed_line_ranges{$file}}, []);
+ my @change_range = (0, 0);
+ FUNCTION: foreach my $function_range_ref (@function_ranges) {
+ my @function_range = @$function_range_ref;
+
+ # Advance to successive change ranges.
+ for (;; @change_range = @{shift @change_ranges}) {
+ last FUNCTION unless @change_range;
+
+ # If past this function, move on to the next one.
+ next FUNCTION if $change_range[0] > $function_range[1];
+
+ # If an overlap with this function range, record the function name.
+ if ($change_range[1] >= $function_range[0]
+ and $change_range[0] <= $function_range[1]) {
+ if (!$saw_function{$function_range[2]}) {
+ $saw_function{$function_range[2]} = 1;
+ push @functions, $function_range[2];
+ }
+ next FUNCTION;
+ }
+ }
+ }
+
+ # Format the list of functions now.
+ if (@functions) {
+ $function_lists->{$file} = "" if !defined $function_lists->{$file};
+ $function_lists->{$file} .= "\n (" . join("):\n (", @functions) . "):";
+ }
+ }
+ }
+}
+
sub changeLogDate($)
{
my ($timeZone) = @_;