2011-01-11 Maciej Stachowiak <mjs@apple.com>
[WebKit-https.git] / Tools / Scripts / webkitpy / common / checkout / scm.py
index 3f77043..823438c 100644 (file)
@@ -52,7 +52,7 @@ def find_checkout_root():
     return None
 
 
-def default_scm():
+def default_scm(patch_directories=None):
     """Return the default SCM object as determined by the CWD and running code.
 
     Returns the default SCM object for the current working directory; if the
@@ -62,10 +62,10 @@ def default_scm():
 
     """
     cwd = os.getcwd()
-    scm_system = detect_scm_system(cwd)
+    scm_system = detect_scm_system(cwd, patch_directories)
     if not scm_system:
         script_directory = os.path.dirname(os.path.abspath(__file__))
-        scm_system = detect_scm_system(script_directory)
+        scm_system = detect_scm_system(script_directory, patch_directories)
         if scm_system:
             log("The current directory (%s) is not a WebKit checkout, using %s" % (cwd, scm_system.checkout_root))
         else:
@@ -73,11 +73,14 @@ def default_scm():
     return scm_system
 
 
-def detect_scm_system(path):
+def detect_scm_system(path, patch_directories=None):
     absolute_path = os.path.abspath(path)
 
+    if patch_directories == []:
+        patch_directories = None
+
     if SVN.in_working_directory(absolute_path):
-        return SVN(cwd=absolute_path)
+        return SVN(cwd=absolute_path, patch_directories=patch_directories)
     
     if Git.in_working_directory(absolute_path):
         return Git(cwd=absolute_path)
@@ -319,9 +322,15 @@ class SVN(SCM):
     svn_server_host = "svn.webkit.org"
     svn_server_realm = "<http://svn.webkit.org:80> Mac OS Forge"
 
-    def __init__(self, cwd):
+    def __init__(self, cwd, patch_directories):
         SCM.__init__(self, cwd)
         self._bogus_dir = None
+        if patch_directories == []:
+            raise ScriptError(script_args=svn_info_args, message='Empty list of patch directories passed to SCM.__init__')
+        elif patch_directories == None:
+            self._patch_directories = [os.path.relpath(cwd, self.checkout_root)]
+        else:
+            self._patch_directories = patch_directories
 
     @staticmethod
     def in_working_directory(path):
@@ -427,7 +436,9 @@ class SVN(SCM):
         return self.run(["svn", "delete", "--force", base], cwd=parent)
 
     def changed_files(self, git_commit=None):
-        return self.run_status_and_extract_filenames(self.status_command(), self._status_regexp("ACDMR"))
+        status_command = ["svn", "status"]
+        status_command.extend(self._patch_directories)
+        return self.run_status_and_extract_filenames(status_command, self._status_regexp("ACDMR"))
 
     def changed_files_for_revision(self, revision):
         # As far as I can tell svn diff --summarize output looks just like svn status output.
@@ -463,10 +474,14 @@ class SVN(SCM):
         return "svn"
 
     # FIXME: This method should be on Checkout.
-    def create_patch(self, git_commit=None, changed_files=[]):
+    def create_patch(self, git_commit=None, changed_files=None):
         """Returns a byte array (str()) representing the patch file.
         Patch files are effectively binary since they may contain
         files of multiple different encodings."""
+        if changed_files == []:
+            return ""
+        elif changed_files == None:
+            changed_files = []
         return self.run([self.script_path("svn-create-patch")] + changed_files,
             cwd=self.checkout_root, return_stderr=False,
             decode_output=False)