Modified: trunk/Tools/ChangeLog (102535 => 102536)
--- trunk/Tools/ChangeLog 2011-12-11 06:20:32 UTC (rev 102535)
+++ trunk/Tools/ChangeLog 2011-12-11 06:32:04 UTC (rev 102536)
@@ -1,3 +1,17 @@
+2011-12-10 Kentaro Hara <hara...@chromium.org>
+
+ [Refactoring] In prepare-ChangeLog, move top-level code to find ChangeLogs into a method
+ https://bugs.webkit.org/show_bug.cgi?id=74175
+
+ 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 top-level code to find ChangeLogs into findChangeLogs().
+ (findChangeLogs):
+
2011-12-10 Andreas Kling <kl...@webkit.org>
Add my Apple e-mail to committers.py.
Modified: trunk/Tools/Scripts/prepare-ChangeLog (102535 => 102536)
--- trunk/Tools/Scripts/prepare-ChangeLog 2011-12-11 06:20:32 UTC (rev 102535)
+++ trunk/Tools/Scripts/prepare-ChangeLog 2011-12-11 06:32:04 UTC (rev 102536)
@@ -68,6 +68,7 @@
sub changeLogEmailAddressFromArgs($);
sub changeLogNameFromArgs($);
sub fetchBugDescriptionFromURL($);
+sub findChangeLogs(\%);
sub firstDirectoryOrCwd();
sub diffFromToString();
sub diffCommand(@);
@@ -202,57 +203,11 @@
$bugDescription = fetchBugDescriptionFromURL($bugURL);
}
-# Find the change logs.
-my %has_log;
-my %files;
-foreach my $file (sort keys %function_lists) {
- my $prefix = $file;
- my $has_log = 0;
- while ($prefix) {
- $prefix =~ s-/[^/]+/?$-/- or $prefix = "";
- $has_log = $has_log{$prefix};
- if (!defined $has_log) {
- $has_log = -f "${prefix}ChangeLog";
- $has_log{$prefix} = $has_log;
- }
- last if $has_log;
- }
- if (!$has_log) {
- print STDERR "No ChangeLog found for $file.\n";
- } else {
- push @{$files{$prefix}}, $file;
- }
-}
+my ($files_in_change_log, $prefixes) = findChangeLogs(%function_lists);
-# Build the list of ChangeLog prefixes in the correct project order
-my @prefixes;
-my %prefixesSort;
-foreach my $prefix (keys %files) {
- my $prefixDir = substr($prefix, 0, length($prefix) - 1); # strip trailing /
- my $sortKey = lc $prefix;
- $sortKey = "top level" unless length $sortKey;
-
- if ($prefixDir eq "top level") {
- $sortKey = "";
- } elsif ($prefixDir eq "Tools") {
- $sortKey = "-, just after top level";
- } elsif ($prefixDir eq "WebBrowser") {
- $sortKey = lc "WebKit, WebBrowser after";
- } elsif ($prefixDir eq "Source/WebCore") {
- $sortKey = lc "WebFoundation, WebCore after";
- } elsif ($prefixDir eq "LayoutTests") {
- $sortKey = lc "~, LayoutTests last";
- }
-
- $prefixesSort{$sortKey} = $prefix;
-}
-foreach my $prefixSort (sort keys %prefixesSort) {
- push @prefixes, $prefixesSort{$prefixSort};
-}
-
# Get the latest ChangeLog files from svn.
my @logs = ();
-foreach my $prefix (@prefixes) {
+foreach my $prefix (@$prefixes) {
push @logs, File::Spec->catfile($prefix || ".", "ChangeLog");
}
@@ -278,7 +233,7 @@
}
# Generate new ChangeLog entries and (optionally) write out new ChangeLog files.
-foreach my $prefix (@prefixes) {
+foreach my $prefix (@$prefixes) {
my $endl = "\n";
my @old_change_log;
@@ -298,7 +253,7 @@
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 substr($prefix, 0, length($prefix) - 1) . ":\n\n" unless (scalar @$prefixes) == 1;
}
print CHANGE_LOG normalizeLineEndings("$date $name <$emailAddress>\n\n", $endl);
@@ -323,7 +278,7 @@
}
}
- foreach my $file (sort @{$files{$prefix}}) {
+ 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);
}
@@ -500,6 +455,58 @@
return $bugDescription;
}
+sub findChangeLogs(\%)
+{
+ # Find the change logs.
+ my %has_log;
+ my %files_in_change_log;
+ foreach my $file (sort keys %function_lists) {
+ my $prefix = $file;
+ my $has_log = 0;
+ while ($prefix) {
+ $prefix =~ s-/[^/]+/?$-/- or $prefix = "";
+ $has_log = $has_log{$prefix};
+ if (!defined $has_log) {
+ $has_log = -f "${prefix}ChangeLog";
+ $has_log{$prefix} = $has_log;
+ }
+ last if $has_log;
+ }
+ if (!$has_log) {
+ print STDERR "No ChangeLog found for $file.\n";
+ } else {
+ push @{$files_in_change_log{$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) {
+ my $prefixDir = substr($prefix, 0, length($prefix) - 1); # strip trailing /
+ my $sortKey = lc $prefix;
+ $sortKey = "top level" unless length $sortKey;
+
+ if ($prefixDir eq "top level") {
+ $sortKey = "";
+ } elsif ($prefixDir eq "Tools") {
+ $sortKey = "-, just after top level";
+ } elsif ($prefixDir eq "WebBrowser") {
+ $sortKey = lc "WebKit, WebBrowser after";
+ } elsif ($prefixDir eq "Source/WebCore") {
+ $sortKey = lc "WebFoundation, WebCore after";
+ } elsif ($prefixDir eq "LayoutTests") {
+ $sortKey = lc "~, LayoutTests last";
+ }
+
+ $prefixesSort{$sortKey} = $prefix;
+ }
+ foreach my $prefixSort (sort keys %prefixesSort) {
+ push @prefixes, $prefixesSort{$prefixSort};
+ }
+ return (\%files_in_change_log, \@prefixes);
+}
+
sub get_function_line_ranges($$)
{
my ($file_handle, $file_name) = @_;