Title: [102537] trunk/Tools
Revision
102537
Author
hara...@chromium.org
Date
2011-12-11 10:04:50 -0800 (Sun, 11 Dec 2011)

Log Message

[Refactoring] Move top-level code to generate a new ChangeLog into a method
https://bugs.webkit.org/show_bug.cgi?id=74253

Reviewed by David Kilzer.

The objective is to make prepare-ChangeLog a loadable Perl module for unit testing,
which requires to remove top-level code and global variables. This patch is one of
the incremental refactorings for that.

* Scripts/prepare-ChangeLog: Moved top-level code to generate a new ChangeLog into generateNewChangeLogs().
(generateFunctionLists):
(findChangeLogs):
(generateNewChangeLogs):
(generateFileList): Removed an unnecessary variable $didChangeRegressionTests.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (102536 => 102537)


--- trunk/Tools/ChangeLog	2011-12-11 06:32:04 UTC (rev 102536)
+++ trunk/Tools/ChangeLog	2011-12-11 18:04:50 UTC (rev 102537)
@@ -1,3 +1,20 @@
+2011-12-11  Kentaro Hara  <hara...@chromium.org>
+
+        [Refactoring] Move top-level code to generate a new ChangeLog into a method
+        https://bugs.webkit.org/show_bug.cgi?id=74253
+
+        Reviewed by David Kilzer.
+
+        The objective is to make prepare-ChangeLog a loadable Perl module for unit testing,
+        which requires to remove top-level code and global variables. This patch is one of
+        the incremental refactorings for that.
+
+        * Scripts/prepare-ChangeLog: Moved top-level code to generate a new ChangeLog into generateNewChangeLogs().
+        (generateFunctionLists):
+        (findChangeLogs):
+        (generateNewChangeLogs):
+        (generateFileList): Removed an unnecessary variable $didChangeRegressionTests.
+
 2011-12-10  Kentaro Hara  <hara...@chromium.org>
 
         [Refactoring] In prepare-ChangeLog, move top-level code to find ChangeLogs into a method

Modified: trunk/Tools/Scripts/prepare-ChangeLog (102536 => 102537)


--- trunk/Tools/Scripts/prepare-ChangeLog	2011-12-11 06:32:04 UTC (rev 102536)
+++ trunk/Tools/Scripts/prepare-ChangeLog	2011-12-11 18:04:50 UTC (rev 102537)
@@ -69,6 +69,7 @@
 sub changeLogNameFromArgs($);
 sub fetchBugDescriptionFromURL($);
 sub findChangeLogs(\%);
+sub generateNewChangeLogs($$$\%);
 sub firstDirectoryOrCwd();
 sub diffFromToString();
 sub diffCommand(@);
@@ -162,16 +163,14 @@
 
 # Find the list of modified files
 my @changed_files;
-my %function_lists;
+my %functionLists;
 my @conflict_files;
 
 my %supportedTestExtensions = map { $_ => 1 } qw(html shtml svg xml xhtml pl php);
-my @addedRegressionTests = ();
-my $didChangeRegressionTests = 0;
 
-generateFileList(@changed_files, @conflict_files, %function_lists);
+my $addedRegressionTests = generateFileList(@changed_files, @conflict_files, %functionLists);
 
-if (!@changed_files && !@conflict_files && !keys %function_lists) {
+if (!@changed_files && !@conflict_files && !keys %functionLists) {
     print STDERR "  No changes found.\n";
     exit 1;
 }
@@ -182,7 +181,7 @@
     exit 1;
 }
 
-generateFunctionLists(@changed_files, %function_lists);
+generateFunctionLists(@changed_files, %functionLists);
 
 # Get some parameters for the ChangeLog we are about to write.
 my $date = changeLogDate($changeLogTimeZone);
@@ -203,7 +202,7 @@
     $bugDescription = fetchBugDescriptionFromURL($bugURL);
 }
 
-my ($files_in_change_log, $prefixes) = findChangeLogs(%function_lists);
+my ($filesInChangeLog, $prefixes) = findChangeLogs(%functionLists);
 
 # Get the latest ChangeLog files from svn.
 my @logs = ();
@@ -232,66 +231,8 @@
     }
 }
 
-# Generate new ChangeLog entries and (optionally) write out new ChangeLog files.
-foreach my $prefix (@$prefixes) {
-    my $endl = "\n";
-    my @old_change_log;
+generateNewChangeLogs($prefixes, $filesInChangeLog, $addedRegressionTests, %functionLists);
 
-    if ($writeChangeLogs) {
-        my $changeLogPath = File::Spec->catfile($prefix || ".", "ChangeLog");
-        print STDERR "  Editing the ${changeLogPath} file.\n";
-        open OLD_CHANGE_LOG, ${changeLogPath} or die "Could not open ${changeLogPath} file: $!.\n";
-        # It's less efficient to read the whole thing into memory than it would be
-        # to read it while we prepend to it later, but I like doing this part first.
-        @old_change_log = <OLD_CHANGE_LOG>;
-        close OLD_CHANGE_LOG;
-        # We want to match the ChangeLog's line endings in case it doesn't match
-        # the native line endings for this version of perl.
-        if ($old_change_log[0] =~ /(\r?\n)$/g) {
-            $endl = "$1";
-        }
-        open CHANGE_LOG, "> ${changeLogPath}" or die "Could not write ${changeLogPath}\n.";
-    } else {
-        open CHANGE_LOG, ">-" or die "Could not write to STDOUT\n.";
-        print substr($prefix, 0, length($prefix) - 1) . ":\n\n" unless (scalar @$prefixes) == 1;
-    }
-
-    print CHANGE_LOG normalizeLineEndings("$date  $name  <$emailAddress>\n\n", $endl);
-
-    my ($reviewer, $description) = reviewerAndDescriptionForGitCommit($gitCommit) if $gitCommit;
-    $reviewer = "NOBODY (OO" . "PS!)" if !$reviewer;
-
-    print CHANGE_LOG normalizeLineEndings($description . "\n", $endl) if $description;
-
-    $bugDescription = "Need a short description and bug URL (OOPS!)" unless $bugDescription;
-    print CHANGE_LOG normalizeLineEndings("        $bugDescription\n", $endl) if $bugDescription;
-    print CHANGE_LOG normalizeLineEndings("        $bugURL\n", $endl) if $bugURL;
-    print CHANGE_LOG normalizeLineEndings("\n", $endl);
-
-    print CHANGE_LOG normalizeLineEndings("        Reviewed by $reviewer.\n\n", $endl);
-
-    if ($prefix =~ m/WebCore/ || `pwd` =~ m/WebCore/) {
-        if ($didChangeRegressionTests) {
-            print CHANGE_LOG normalizeLineEndings(testListForChangeLog(sort @addedRegressionTests), $endl);
-        } else {
-            print CHANGE_LOG normalizeLineEndings("        No new tests. (OOPS!)\n\n", $endl);
-        }
-    }
-
-    foreach my $file (sort @{$files_in_change_log->{$prefix}}) {
-        my $file_stem = substr $file, length $prefix;
-        print CHANGE_LOG normalizeLineEndings("        * $file_stem:$function_lists{$file}\n", $endl);
-    }
-
-    if ($writeChangeLogs) {
-        print CHANGE_LOG normalizeLineEndings("\n", $endl), @old_change_log;
-    } else {
-        print CHANGE_LOG "\n";
-    }
-
-    close CHANGE_LOG;
-}
-
 if ($writeChangeLogs) {
     print STDERR "-- Please remember to include a detailed description in your ChangeLog entry. --\n-- See <http://webkit.org/coding/contributing.html> for more info --\n";
 }
@@ -327,7 +268,7 @@
 
 sub generateFunctionLists(\@\%)
 {
-    my ($changed_files, $function_lists) = @_;
+    my ($changed_files, $functionLists) = @_;
 
     my %changed_line_ranges;
     if (@$changed_files) {
@@ -388,8 +329,8 @@
 
             # Format the list of functions now.
             if (@functions) {
-                $function_lists->{$file} = "" if !defined $function_lists->{$file};
-                $function_lists->{$file} .= "\n        (" . join("):\n        (", @functions) . "):";
+                $functionLists->{$file} = "" if !defined $functionLists->{$file};
+                $functionLists->{$file} .= "\n        (" . join("):\n        (", @functions) . "):";
             }
         }
     }
@@ -459,8 +400,8 @@
 {
     # Find the change logs.
     my %has_log;
-    my %files_in_change_log;
-    foreach my $file (sort keys %function_lists) {
+    my %filesInChangeLog;
+    foreach my $file (sort keys %functionLists) {
         my $prefix = $file;
         my $has_log = 0;
         while ($prefix) {
@@ -475,14 +416,14 @@
         if (!$has_log) {
             print STDERR "No ChangeLog found for $file.\n";
         } else {
-            push @{$files_in_change_log{$prefix}}, $file;
+            push @{$filesInChangeLog{$prefix}}, $file;
         }
     }
 
     # Build the list of ChangeLog prefixes in the correct project order
     my @prefixes;
     my %prefixesSort;
-    foreach my $prefix (keys %files_in_change_log) {
+    foreach my $prefix (keys %filesInChangeLog) {
         my $prefixDir = substr($prefix, 0, length($prefix) - 1); # strip trailing /
         my $sortKey = lc $prefix;
         $sortKey = "top level" unless length $sortKey;
@@ -504,9 +445,74 @@
     foreach my $prefixSort (sort keys %prefixesSort) {
         push @prefixes, $prefixesSort{$prefixSort};
     }
-    return (\%files_in_change_log, \@prefixes);
+    return (\%filesInChangeLog, \@prefixes);
 }
 
+sub generateNewChangeLogs($$$\%)
+{
+    my ($prefixes, $filesInChangeLog, $addedRegressionTests, $functionLists) = @_;
+
+    # Generate new ChangeLog entries and (optionally) write out new ChangeLog files.
+    foreach my $prefix (@$prefixes) {
+        my $endl = "\n";
+        my @old_change_log;
+
+        if ($writeChangeLogs) {
+            my $changeLogPath = File::Spec->catfile($prefix || ".", "ChangeLog");
+            print STDERR "  Editing the ${changeLogPath} file.\n";
+            open OLD_CHANGE_LOG, ${changeLogPath} or die "Could not open ${changeLogPath} file: $!.\n";
+            # It's less efficient to read the whole thing into memory than it would be
+            # to read it while we prepend to it later, but I like doing this part first.
+            @old_change_log = <OLD_CHANGE_LOG>;
+            close OLD_CHANGE_LOG;
+            # We want to match the ChangeLog's line endings in case it doesn't match
+            # the native line endings for this version of perl.
+            if ($old_change_log[0] =~ /(\r?\n)$/g) {
+                $endl = "$1";
+            }
+            open CHANGE_LOG, "> ${changeLogPath}" or die "Could not write ${changeLogPath}\n.";
+        } else {
+            open CHANGE_LOG, ">-" or die "Could not write to STDOUT\n.";
+            print substr($prefix, 0, length($prefix) - 1) . ":\n\n" unless (scalar @$prefixes) == 1;
+        }
+
+        print CHANGE_LOG normalizeLineEndings("$date  $name  <$emailAddress>\n\n", $endl);
+
+        my ($reviewer, $description) = reviewerAndDescriptionForGitCommit($gitCommit) if $gitCommit;
+        $reviewer = "NOBODY (OO" . "PS!)" if !$reviewer;
+
+        print CHANGE_LOG normalizeLineEndings($description . "\n", $endl) if $description;
+
+        $bugDescription = "Need a short description and bug URL (OOPS!)" unless $bugDescription;
+        print CHANGE_LOG normalizeLineEndings("        $bugDescription\n", $endl) if $bugDescription;
+        print CHANGE_LOG normalizeLineEndings("        $bugURL\n", $endl) if $bugURL;
+        print CHANGE_LOG normalizeLineEndings("\n", $endl);
+
+        print CHANGE_LOG normalizeLineEndings("        Reviewed by $reviewer.\n\n", $endl);
+
+        if ($prefix =~ m/WebCore/ || `pwd` =~ m/WebCore/) {
+            if (@$addedRegressionTests) {
+                print CHANGE_LOG normalizeLineEndings(testListForChangeLog(sort @$addedRegressionTests), $endl);
+            } else {
+                print CHANGE_LOG normalizeLineEndings("        No new tests. (OOPS!)\n\n", $endl);
+            }
+        }
+
+        foreach my $file (sort @{$filesInChangeLog->{$prefix}}) {
+            my $file_stem = substr $file, length $prefix;
+            print CHANGE_LOG normalizeLineEndings("        * $file_stem:$functionLists->{$file}\n", $endl);
+        }
+
+        if ($writeChangeLogs) {
+            print CHANGE_LOG normalizeLineEndings("\n", $endl), @old_change_log;
+        } else {
+            print CHANGE_LOG "\n";
+        }
+
+        close CHANGE_LOG;
+    }
+}
+
 sub get_function_line_ranges($$)
 {
     my ($file_handle, $file_name) = @_;
@@ -1551,6 +1557,8 @@
 sub generateFileList(\@\@\%)
 {
     my ($changedFiles, $conflictFiles, $functionLists) = @_;
+
+    my @addedRegressionTests;
     print STDERR "  Running status to find changed, added, or removed files.\n";
     open STAT, "-|", statusCommand(keys %paths) or die "The status failed: $!.\n";
     while (<STAT>) {
@@ -1603,7 +1611,6 @@
         if (isModifiedStatus($status) || isAddedStatus($status) || isModifiedStatus($propertyStatus)) {
             my @components = File::Spec->splitdir($file);
             if ($components[0] eq "LayoutTests") {
-                $didChangeRegressionTests = 1;
                 push @addedRegressionTests, $file
                     if isAddedStatus($status)
                        && $file =~ /\.([a-zA-Z]+)$/
@@ -1621,6 +1628,7 @@
         }
     }
     close STAT;
+    return \@addedRegressionTests;
 }
 
 sub isUnmodifiedStatus($)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to