Title: [213986] trunk/Tools
Revision
213986
Author
[email protected]
Date
2017-03-15 10:21:00 -0700 (Wed, 15 Mar 2017)

Log Message

Use git's -C flag when possible in VCSUtils.pm
https://bugs.webkit.org/show_bug.cgi?id=169003

Patch by Kocsen Chung <[email protected]> on 2017-03-15
Reviewed by Sam Weinig.

Use the git -C flag where appropriate to perform the
operation on a target directory and avoid unnecessary logic
to `cd` in and out of the target directory.

* Scripts/VCSUtils.pm:
(isGitDirectory):
(isGitSVNDirectory):
(svnRevisionForDirectory):
(svnInfoForPath):
For all four subroutines, use git's -C flag and strip `cd` logic.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (213985 => 213986)


--- trunk/Tools/ChangeLog	2017-03-15 17:06:55 UTC (rev 213985)
+++ trunk/Tools/ChangeLog	2017-03-15 17:21:00 UTC (rev 213986)
@@ -1,3 +1,21 @@
+2017-03-15  Kocsen Chung  <[email protected]>
+
+        Use git's -C flag when possible in VCSUtils.pm
+        https://bugs.webkit.org/show_bug.cgi?id=169003
+
+        Reviewed by Sam Weinig.
+
+        Use the git -C flag where appropriate to perform the
+        operation on a target directory and avoid unnecessary logic
+        to `cd` in and out of the target directory.
+
+        * Scripts/VCSUtils.pm:
+        (isGitDirectory):
+        (isGitSVNDirectory):
+        (svnRevisionForDirectory):
+        (svnInfoForPath):
+        For all four subroutines, use git's -C flag and strip `cd` logic.
+
 2017-03-14  Aakash Jain  <[email protected]>
 
         start-queue-mac.sh should create logs directory if it doesn't exist

Modified: trunk/Tools/Scripts/VCSUtils.pm (213985 => 213986)


--- trunk/Tools/Scripts/VCSUtils.pm	2017-03-15 17:06:55 UTC (rev 213985)
+++ trunk/Tools/Scripts/VCSUtils.pm	2017-03-15 17:21:00 UTC (rev 213986)
@@ -222,8 +222,8 @@
 
 sub isGitDirectory($)
 {
-    my ($dir) = @_;
-    return system("cd $dir && git rev-parse > " . File::Spec->devnull() . " 2>&1") == 0;
+    my ($directory) = @_;
+    return system("git -C '$directory' rev-parse > " . File::Spec->devnull() . " 2>&1") == 0;
 }
 
 sub isGit()
@@ -238,15 +238,11 @@
 {
     my ($directory) = @_;
 
-    my $savedWorkingDirectory = Cwd::getcwd();
-    chdir($directory);
-
     # There doesn't seem to be an officially documented way to determine
     # if you're in a git-svn checkout. The best suggestions seen so far
     # all use something like the following:
-    my $output = `git config --get svn-remote.svn.fetch 2>& 1`;
+    my $output = `git -C '$directory' config --get svn-remote.svn.fetch 2>&1`;
     $isGitSVN = exitStatus($?) == 0 && $output ne "";
-    chdir($savedWorkingDirectory);
     return $isGitSVN;
 }
 
@@ -426,25 +422,24 @@
 
 sub svnRevisionForDirectory($)
 {
-    my ($dir) = @_;
+    my ($directory) = @_;
     my $revision;
 
-    if (isSVNDirectory($dir)) {
-        my $escapedDir = escapeSubversionPath($dir);
+    if (isSVNDirectory($directory)) {
+        my $escapedDir = escapeSubversionPath($directory);
         my $command = "svn info $escapedDir | grep Revision:";
         $command = "LC_ALL=C $command" if !isWindows();
         my $svnInfo = `$command`;
         ($revision) = ($svnInfo =~ m/Revision: (\d+).*/g);
-    } elsif (isGitDirectory($dir)) {
-        my $command = "git log --grep=\"git-svn-id: \" -n 1 | grep git-svn-id:";
+    } elsif (isGitDirectory($directory)) {
+        my $command = "git -C '$directory' log --grep=\"git-svn-id: \" -n 1 | grep git-svn-id:";
         $command = "LC_ALL=C $command" if !isWindows();
-        $command = "cd $dir && $command";
         my $gitLog = `$command`;
         ($revision) = ($gitLog =~ m/ +git-svn-id: .+@(\d+) /g);
     }
     if (!defined($revision)) {
         $revision = "unknown";
-        warn "Unable to determine current SVN revision in $dir";
+        warn "Unable to determine current SVN revision in $directory";
     }
     return $revision;
 }
@@ -461,9 +456,9 @@
         $command = "LC_ALL=C $command" if !isWindows();
         $svnInfo = `$command`;
     } elsif (isGitDirectory($file)) {
-        my $command = "git svn info";
+        my $command = "git -C '$file' svn info";
         $command = "LC_ALL=C $command" if !isWindows();
-        $svnInfo = `cd $relativePath && $command`;
+        $svnInfo = `$command`;
     }
 
     return $svnInfo;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to