Use self._filesystem in more places in the SCM classes
authoreric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Feb 2012 00:05:33 +0000 (00:05 +0000)
committereric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Feb 2012 00:05:33 +0000 (00:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=79415

Reviewed by Adam Barth.

* Scripts/webkitpy/common/checkout/scm/detection_unittest.py:
(SCMDetectorTest.test_detect_scm_system):
* Scripts/webkitpy/common/checkout/scm/git.py:
(Git.find_checkout_root):
(Git.to_object_name):
* Scripts/webkitpy/common/checkout/scm/scm.py:
(SCM.__init__):
(SCM.in_working_directory):
* Scripts/webkitpy/common/checkout/scm/svn.py:
(SVN.find_uuid):
(SVN.find_checkout_root):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@108693 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/common/checkout/scm/detection_unittest.py
Tools/Scripts/webkitpy/common/checkout/scm/git.py
Tools/Scripts/webkitpy/common/checkout/scm/scm.py
Tools/Scripts/webkitpy/common/checkout/scm/svn.py

index cb9ecac..ea7f1be 100644 (file)
@@ -1,3 +1,22 @@
+2012-02-23  Eric Seidel  <eric@webkit.org>
+
+        Use self._filesystem in more places in the SCM classes
+        https://bugs.webkit.org/show_bug.cgi?id=79415
+
+        Reviewed by Adam Barth.
+
+        * Scripts/webkitpy/common/checkout/scm/detection_unittest.py:
+        (SCMDetectorTest.test_detect_scm_system):
+        * Scripts/webkitpy/common/checkout/scm/git.py:
+        (Git.find_checkout_root):
+        (Git.to_object_name):
+        * Scripts/webkitpy/common/checkout/scm/scm.py:
+        (SCM.__init__):
+        (SCM.in_working_directory):
+        * Scripts/webkitpy/common/checkout/scm/svn.py:
+        (SVN.find_uuid):
+        (SVN.find_checkout_root):
+
 2012-02-23  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r108685.
index 1512ddc..7bee817 100644 (file)
@@ -36,7 +36,7 @@ from webkitpy.common.system.executive_mock import MockExecutive
 
 
 class SCMDetectorTest(unittest.TestCase):
-    def test_find_checkout_root(self):
+    def test_detect_scm_system(self):
         filesystem = MockFileSystem()
         executive = MockExecutive(should_log=True)
         detector = SCMDetector(filesystem, executive)
index ab96b8f..7c5d80c 100644 (file)
@@ -105,19 +105,18 @@ class Git(SCM, SVNRepository):
             # The Windows bots seem to through a WindowsError when git isn't installed.
             return False
 
-    @classmethod
-    def find_checkout_root(cls, path):
-        # FIXME: This should use a FileSystem object instead of os.path.
+    def find_checkout_root(self, path):
         # "git rev-parse --show-cdup" would be another way to get to the root
-        (checkout_root, dot_git) = os.path.split(run_command(['git', 'rev-parse', '--git-dir'], cwd=(path or "./")))
-        if not os.path.isabs(checkout_root):  # Sometimes git returns relative paths
-            checkout_root = os.path.join(path, checkout_root)
+        git_output = self._executive.run_command(['git', 'rev-parse', '--git-dir'], cwd=(path or "./"))
+        (checkout_root, dot_git) = self._filesystem.split(git_output)
+        if not self._filesystem.isabs(checkout_root):  # Sometimes git returns relative paths
+            checkout_root = self._filesystem.join(path, checkout_root)
         return checkout_root
 
-    @classmethod
-    def to_object_name(cls, filepath):
-        # FIXME: This should use a FileSystem object instead of os.path.
-        root_end_with_slash = os.path.join(cls.find_checkout_root(os.path.dirname(filepath)), '')
+    def to_object_name(self, filepath):
+        # FIXME: This can't be the right way to append a slash.
+        root_end_with_slash = self._filesystem.join(self.find_checkout_root(self._filesystem.dirname(filepath)), '')
+        # FIXME: This seems to want some sort of rel_path instead?
         return filepath.replace(root_end_with_slash, '')
 
     @classmethod
index 432d6ca..cbce361 100644 (file)
@@ -60,9 +60,9 @@ class AuthenticationError(Exception):
 class SCM:
     def __init__(self, cwd, executive=None, filesystem=None):
         self.cwd = cwd
-        self.checkout_root = self.find_checkout_root(self.cwd)
         self._executive = executive or Executive()
         self._filesystem = filesystem or FileSystem()
+        self.checkout_root = self.find_checkout_root(self.cwd)
 
     # A wrapper used by subclasses to create processes.
     def run(self, args, cwd=None, input=None, error_handler=None, return_exit_code=False, return_stderr=True, decode_output=True):
@@ -137,7 +137,6 @@ class SCM:
     def in_working_directory(path):
         SCM._subclass_must_implement()
 
-    @staticmethod
     def find_checkout_root(path):
         SCM._subclass_must_implement()
 
index edeee30..af03f8d 100644 (file)
@@ -86,11 +86,10 @@ class SVN(SCM, SVNRepository):
     def in_working_directory(path):
         return os.path.isdir(os.path.join(path, '.svn'))
 
-    @classmethod
-    def find_uuid(cls, path):
-        if not cls.in_working_directory(path):
+    def find_uuid(self, path):
+        if not self.in_working_directory(path):
             return None
-        return cls.value_from_svn_info(path, 'Repository UUID')
+        return self.value_from_svn_info(path, 'Repository UUID')
 
     @classmethod
     def value_from_svn_info(cls, path, field_name):
@@ -102,19 +101,18 @@ class SVN(SCM, SVNRepository):
             raise ScriptError(script_args=svn_info_args, message='svn info did not contain a %s.' % field_name)
         return match.group('value')
 
-    @staticmethod
-    def find_checkout_root(path):
-        uuid = SVN.find_uuid(path)
+    def find_checkout_root(self, path):
+        uuid = self.find_uuid(path)
         # If |path| is not in a working directory, we're supposed to return |path|.
         if not uuid:
             return path
         # Search up the directory hierarchy until we find a different UUID.
         last_path = None
         while True:
-            if uuid != SVN.find_uuid(path):
+            if uuid != self.find_uuid(path):
                 return last_path
             last_path = path
-            (path, last_component) = os.path.split(path)
+            (path, last_component) = self._filesystem.split(path)
             if last_path == path:
                 return None