Title: [102487] trunk/Tools
Revision
102487
Author
hara...@chromium.org
Date
2011-12-09 15:50:58 -0800 (Fri, 09 Dec 2011)

Log Message

[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):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (102486 => 102487)


--- trunk/Tools/ChangeLog	2011-12-09 23:50:16 UTC (rev 102486)
+++ trunk/Tools/ChangeLog	2011-12-09 23:50:58 UTC (rev 102487)
@@ -1,3 +1,17 @@
+2011-12-09  Kentaro Hara  <hara...@chromium.org>
+
+        [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):
+
 2011-12-09  Sam Weinig  <s...@webkit.org>
 
         Expose a WKConnectionRef which represents the connection to/from the WebProcess/UIProcess

Modified: trunk/Tools/Scripts/prepare-ChangeLog (102486 => 102487)


--- trunk/Tools/Scripts/prepare-ChangeLog	2011-12-09 23:50:16 UTC (rev 102486)
+++ trunk/Tools/Scripts/prepare-ChangeLog	2011-12-09 23:50:58 UTC (rev 102487)
@@ -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,73 +181,8 @@
     exit 1;
 }
 
-if (@changed_files) {
-    $changed_files_string = "'" . join ("' '", @changed_files) . "'";
+generateFunctionLists(@changed_files, %function_lists);
 
-    # 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) . "):";
-        }
-    }
-}
-
 # Get some parameters for the ChangeLog we are about to write.
 my $date = changeLogDate($changeLogTimeZone);
 $name = changeLogNameFromArgs($name);
@@ -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) = @_;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to