Title: [102890] trunk/Tools
Revision
102890
Author
hara...@chromium.org
Date
2011-12-14 22:32:27 -0800 (Wed, 14 Dec 2011)

Log Message

[Refactoring] In prepare-ChangeLog, replace $isGit and $isSVN with
VCSUtils::isGit() and VCSUtils::isSVN().
https://bugs.webkit.org/show_bug.cgi?id=74485

Reviewed by David Kilzer.

We are planning to write unit-tests for prepare-ChangeLog in a run-leaks_unittest
manner. This bug is one of the incremental refactorings to remove all top-level
code and global variables from prepare-ChangeLog. This patch replaces $isGit and $isSVN
with VCSUtils::isGit() and VCSUtils::isSVN(). This patch also removes firstDirectoryOrCwd(),
assuming that no user will mix Git/SVN checkouts and thus we can judge SVN or Git
just by looking at the current working directory.

* Scripts/prepare-ChangeLog: Removed firstDirectoryOrCwd().
(diffFromToString):
(diffCommand):
(statusCommand):
(createPatchCommand):
(diffHeaderFormat):
(generateFileList):
(isAddedStatus):
(isConflictStatus):
(statusDescription):
(extractLineRange):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (102889 => 102890)


--- trunk/Tools/ChangeLog	2011-12-15 06:25:05 UTC (rev 102889)
+++ trunk/Tools/ChangeLog	2011-12-15 06:32:27 UTC (rev 102890)
@@ -1,3 +1,30 @@
+2011-12-14  Kentaro Hara  <hara...@chromium.org>
+
+        [Refactoring] In prepare-ChangeLog, replace $isGit and $isSVN with
+        VCSUtils::isGit() and VCSUtils::isSVN().
+        https://bugs.webkit.org/show_bug.cgi?id=74485
+
+        Reviewed by David Kilzer.
+
+        We are planning to write unit-tests for prepare-ChangeLog in a run-leaks_unittest
+        manner. This bug is one of the incremental refactorings to remove all top-level
+        code and global variables from prepare-ChangeLog. This patch replaces $isGit and $isSVN
+        with VCSUtils::isGit() and VCSUtils::isSVN(). This patch also removes firstDirectoryOrCwd(),
+        assuming that no user will mix Git/SVN checkouts and thus we can judge SVN or Git
+        just by looking at the current working directory.
+
+        * Scripts/prepare-ChangeLog: Removed firstDirectoryOrCwd().
+        (diffFromToString):
+        (diffCommand):
+        (statusCommand):
+        (createPatchCommand):
+        (diffHeaderFormat):
+        (generateFileList):
+        (isAddedStatus):
+        (isConflictStatus):
+        (statusDescription):
+        (extractLineRange):
+
 2011-12-14  Sam Weinig  <wei...@apple.com>
 
         Remove whitespace from InheritedPropertySheets attributes in

Modified: trunk/Tools/Scripts/prepare-ChangeLog (102889 => 102890)


--- trunk/Tools/Scripts/prepare-ChangeLog	2011-12-15 06:25:05 UTC (rev 102889)
+++ trunk/Tools/Scripts/prepare-ChangeLog	2011-12-15 06:32:27 UTC (rev 102890)
@@ -74,7 +74,6 @@
 sub generateNewChangeLogs($$$$$);
 sub printDiff($);
 sub openChangeLogs($);
-sub firstDirectoryOrCwd(\%);
 sub diffFromToString();
 sub diffCommand(@);
 sub statusCommand(@);
@@ -166,12 +165,11 @@
 
 
 ### Main routine.
-my %paths = processPaths(@ARGV);
 
-my $isGit = isGitDirectory(firstDirectoryOrCwd(%paths));
-my $isSVN = isSVNDirectory(firstDirectoryOrCwd(%paths));
-$isSVN || $isGit || die "Couldn't determine your version control system.";
+isSVN() || isGit() || die "Couldn't determine your version control system.";
 
+my %paths = processPaths(@ARGV);
+
 # Find the list of modified files
 my ($changedFiles, $conflictFiles, $functionLists, $addedRegressionTests) = generateFileList(%paths);
 
@@ -211,7 +209,7 @@
 # Get the latest ChangeLog files from svn.
 my $changeLogs = getLatestChangeLogs($prefixes);
 
-if (@$changeLogs && $updateChangeLogs && $isSVN) {
+if (@$changeLogs && $updateChangeLogs && isSVN()) {
     resolveConflictedChangeLogs($changeLogs);
 }
 
@@ -1436,12 +1434,12 @@
 
 sub diffFromToString()
 {
-    return "" if $isSVN;
+    return "" if isSVN();
     return $gitCommit if $gitCommit =~ m/.+\.\..+/;
     return "\"$gitCommit^\" \"$gitCommit\"" if $gitCommit;
     return "--cached" if $gitIndex;
     return $mergeBase if $mergeBase;
-    return "HEAD" if $isGit;
+    return "HEAD" if isGit();
 }
 
 sub diffCommand(@)
@@ -1451,9 +1449,9 @@
     my $pathsString = "'" . join("' '", @paths) . "'"; 
 
     my $command;
-    if ($isSVN) {
+    if (isSVN()) {
         $command = "$SVN diff --diff-cmd diff -x -N $pathsString";
-    } elsif ($isGit) {
+    } elsif (isGit()) {
         $command = "$GIT diff --no-ext-diff -U0 " . diffFromToString();
         $command .= " -- $pathsString" unless $gitCommit or $mergeBase;
     }
@@ -1467,9 +1465,9 @@
 
     my $filesString = "\"" . join ("\" \"", @files) . "\"";
     my $command;
-    if ($isSVN) {
+    if (isSVN()) {
         $command = "$SVN stat $filesString";
-    } elsif ($isGit) {
+    } elsif (isGit()) {
         $command = "$GIT diff -r --name-status -M -C " . diffFromToString();
         $command .= " -- $filesString" unless $gitCommit;
     }
@@ -1482,9 +1480,9 @@
     my ($changedFilesString) = @_;
 
     my $command;
-    if ($isSVN) {
+    if (isSVN()) {
         $command = "'$FindBin::Bin/svn-create-patch' $changedFilesString";
-    } elsif ($isGit) {
+    } elsif (isGit()) {
         $command = "$GIT diff -M -C " . diffFromToString();
         $command .= " -- $changedFilesString" unless $gitCommit;
     }
@@ -1494,8 +1492,8 @@
 
 sub diffHeaderFormat()
 {
-    return qr/^Index: (\S+)[\r\n]*$/ if $isSVN;
-    return qr/^diff --git a\/.+ b\/(.+)$/ if $isGit;
+    return qr/^Index: (\S+)[\r\n]*$/ if isSVN();
+    return qr/^diff --git a\/.+ b\/(.+)$/ if isGit();
 }
 
 sub findOriginalFileFromSvn($)
@@ -1607,7 +1605,7 @@
         my $original;
         my $file;
 
-        if ($isSVN) {
+        if (isSVN()) {
             my $matches;
             if (isSVNVersion16OrNewer()) {
                 $matches = /^([ ACDMR])([ CM]).{5} (.+?)[\r\n]*$/;
@@ -1628,7 +1626,7 @@
             } else {
                 print;  # error output from svn stat
             }
-        } elsif ($isGit) {
+        } elsif (isGit()) {
             if (/^([ADM])\t(.+)$/) {
                 $status = $1;
                 $propertyStatus = " ";  # git doesn't have properties
@@ -1698,7 +1696,7 @@
 
     my %statusCodes = (
         "A" => 1,
-        "C" => $isGit,
+        "C" => isGit(),
         "R" => 1,
     );
 
@@ -1718,8 +1716,8 @@
     );
 
     return 0 if ($gitCommit || $gitIndex); # an existing commit or staged change cannot have conflicts
-    return $svn{$status} if $isSVN;
-    return $git{$status} if $isGit;
+    return $svn{$status} if isSVN();
+    return $git{$status} if isGit();
 }
 
 sub statusDescription($$$$)
@@ -1742,8 +1740,8 @@
     $git{"R"} = " Renamed from \%s.";
 
     my $description;
-    $description = sprintf($svn{$status}, $original) if $isSVN && exists $svn{$status};
-    $description = sprintf($git{$status}, $original) if $isGit && exists $git{$status};
+    $description = sprintf($svn{$status}, $original) if isSVN() && exists $svn{$status};
+    $description = sprintf($git{$status}, $original) if isGit() && exists $git{$status};
     return unless defined $description;
 
     $description .= $propertyDescription unless isAddedStatus($status);
@@ -1776,10 +1774,10 @@
 
     my ($start, $end) = (-1, -1);
 
-    if ($isSVN && $string =~ /^\d+(,\d+)?[acd](\d+)(,(\d+))?/) {
+    if (isSVN() && $string =~ /^\d+(,\d+)?[acd](\d+)(,(\d+))?/) {
         $start = $2;
         $end = $4 || $2;
-    } elsif ($isGit && $string =~ /^@@ -\d+(,\d+)? \+(\d+)(,(\d+))? @@/) {
+    } elsif (isGit() && $string =~ /^@@ -\d+(,\d+)? \+(\d+)(,(\d+))? @@/) {
         $start = $2;
         $end = defined($4) ? $4 + $2 - 1 : $2;
     }
@@ -1787,18 +1785,6 @@
     return ($start, $end);
 }
 
-sub firstDirectoryOrCwd(\%)
-{
-    my ($paths) = @_;
-
-    my $dir = ".";
-    my @dirs = keys(%$paths);
-
-    $dir = -d $dirs[0] ? $dirs[0] : dirname($dirs[0]) if @dirs;
-
-    return $dir;
-}
-
 sub testListForChangeLog(@)
 {
     my (@tests) = @_;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to