Make svndiff.py work on Windows and with svn 1.7.

R=epoger@google.com

Review URL: https://codereview.chromium.org/25447003

git-svn-id: http://skia.googlecode.com/svn/trunk@11642 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tools/svn.py b/tools/svn.py
index 72d8ad8..aac8970 100644
--- a/tools/svn.py
+++ b/tools/svn.py
@@ -135,7 +135,7 @@
         if status & STATUS_NOT_UNDER_SVN_CONTROL:
             status_types_string += '\?'
         status_regex_string = '^[%s].....\s+(.+)$' % status_types_string
-        stdout = self._RunCommand([SVN, 'status'])
+        stdout = self._RunCommand([SVN, 'status']).replace('\r', '')
         status_regex = re.compile(status_regex_string, re.MULTILINE)
         files = status_regex.findall(stdout)
         return files
@@ -179,5 +179,5 @@
                version you wish to obtain
         @param dest_path destination to which to write the base content
         """
-        self._RunCommand([SVN, 'export', '--revision', 'BASE',
+        self._RunCommand([SVN, 'export', '--revision', 'BASE', '--force',
                           file_within_repo, dest_path])
diff --git a/tools/svndiff.py b/tools/svndiff.py
index 9e51eee..196eace 100755
--- a/tools/svndiff.py
+++ b/tools/svndiff.py
@@ -223,7 +223,12 @@
     dest_dir = os.path.abspath(dest_dir)
 
     os.chdir(source_dir)
-    using_svn = os.path.isdir('.svn')
+    svn_repo = svn.Svn('.')
+    using_svn = True
+    try:
+      svn_repo.GetInfo()
+    except:
+      using_svn = False
 
     # Prepare temporary directories.
     modified_flattened_dir = os.path.join(dest_dir, 'modified_flattened')
@@ -236,7 +241,6 @@
     # Get a list of all locally modified (including added/deleted) files,
     # descending subdirectories.
     if using_svn:
-        svn_repo = svn.Svn('.')
         modified_file_paths = svn_repo.GetFilesWithStatus(
             svn.STATUS_ADDED | svn.STATUS_DELETED | svn.STATUS_MODIFIED)
     else:
@@ -249,23 +253,26 @@
         if modified_file_path.endswith('.json'):
             # Special handling for JSON files, in the hopes that they
             # contain GM result summaries.
-            (_unused, original_file_path) = tempfile.mkstemp()
+            original_file = tempfile.NamedTemporaryFile(delete = False)
+            original_file.close()
             if using_svn:
                 svn_repo.ExportBaseVersionOfFile(
-                    modified_file_path, original_file_path)
+                    modified_file_path, original_file.name)
             else:
                 _GitExportBaseVersionOfFile(
-                    modified_file_path, original_file_path)
-            platform_prefix = re.sub(os.sep, '__',
-                                     os.path.dirname(modified_file_path)) + '__'
-            _CallJsonDiff(old_json_path=original_file_path,
+                    modified_file_path, original_file.name)
+            original_directory = os.path.dirname(original_file.name)
+            platform_prefix = (re.sub(re.escape(os.sep), '__',
+                                      os.path.splitdrive(original_directory)[1])
+                              + '__')
+            _CallJsonDiff(old_json_path=original_file.name,
                           new_json_path=modified_file_path,
                           old_flattened_dir=original_flattened_dir,
                           new_flattened_dir=modified_flattened_dir,
                           filename_prefix=platform_prefix)
-            os.remove(original_file_path)
+            os.remove(original_file.name)
         else:
-            dest_filename = re.sub(os.sep, '__', modified_file_path)
+            dest_filename = re.sub(re.escape(os.sep), '__', modified_file_path)
             # If the file had STATUS_DELETED, it won't exist anymore...
             if os.path.isfile(modified_file_path):
                 shutil.copyfile(modified_file_path,