changeset 76:6c62bd201785

SubversionRepo: make get_file() return the file mode It is cheap to get it, and it will be useful to fetch revisions.
author Patrick Mezard <pmezard@gmail.com>
date Sun, 09 Nov 2008 18:08:35 -0600
parents cca31b6b1318
children ed3dd5bf45da
files fetch_command.py svnwrap/svn_swig_wrapper.py
diffstat 2 files changed, 19 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/fetch_command.py
+++ b/fetch_command.py
@@ -119,23 +119,9 @@ def replay_convert_rev(hg_editor, svn, r
                             len(hg_editor.missing_plaintexts))
         files_to_grab = set()
         dirs_to_list = []
-        props = {}
-        hg_editor.ui.status('Getting properties...\n')
         for p in hg_editor.missing_plaintexts:
             hg_editor.ui.status('.')
             hg_editor.ui.flush()
-            p2 = p
-            if svn.subdir:
-                p2 = p2[len(svn.subdir)-1:]
-            # this *sometimes* raises on me, and I have
-            # no idea why. TODO(augie) figure out the why.
-            try:
-                pl = svn.proplist(p2, r.revnum, recurse=True)
-                cleanup_file_handles(svn, i)
-                i += 1
-            except core.SubversionException, e: #pragma: no cover
-                pass
-            props.update(pl)
             if p[-1] == '/':
                 dirs_to_list.append(p)
             else:
@@ -154,7 +140,6 @@ def replay_convert_rev(hg_editor, svn, r
                 p2 = p2[len(svn.subdir)-1:]
             l = svn.list_dir(p2, r.revnum)
             for f in l:
-
                 if l[f].kind == core.svn_node_dir:
                     dirs_to_list.append(p+f+'/')
                 elif l[f].kind == core.svn_node_file:
@@ -168,13 +153,10 @@ def replay_convert_rev(hg_editor, svn, r
                 p2 = p2[len(svn.subdir)-1:]
             cleanup_file_handles(svn, i)
             i += 1
-            hg_editor.current_files[p] = svn.get_file(p2, r.revnum)
-            hg_editor.current_files_exec[p] = False
-            if p in props:
-                if 'svn:executable' in props[p]:
-                    hg_editor.current_files_exec[p] = True
-                if 'svn:special' in props[p]:
-                    hg_editor.current_files_symlink[p] = True
+            data, mode = svn.get_file(p2, r.revnum)
+            hg_editor.current_files[p] = data
+            hg_editor.current_files_exec[p] = 'x' in mode
+            hg_editor.current_files_symlink[p] = 'l' in mode
         hg_editor.missing_plaintexts = set()
         hg_editor.ui.status('\n')
     hg_editor.commit_current_delta()
@@ -347,7 +329,7 @@ def stupid_svn_server_pull_rev(ui, svn, 
                     except OSError, e:
                         pass
                     f = open(file_path, 'w')
-                    f.write(svn.get_file(diff_path+'/'+m, r.revnum))
+                    f.write(svn.get_file(diff_path+'/'+m, r.revnum)[0])
                     f.close()
                 except IOError:
                     pass
--- a/svnwrap/svn_swig_wrapper.py
+++ b/svnwrap/svn_swig_wrapper.py
@@ -390,9 +390,21 @@ class SubversionRepo(object):
             shutil.rmtree(tmpdir)
 
     def get_file(self, path, revision):
+        """Return content and mode of file at given path and revision.
+
+        Content is raw svn content, symlinks content is still prefixed
+        by 'link '. Mode is 'x' if file is executable, 'l' if a symlink,
+        the empty string otherwise. If the file does not exist at this
+        revision, raise IOError.
+        """
+        mode = ''
         out = cStringIO.StringIO()
         try:
-            ra.get_file(self.ra, path, revision, out)
+            info = ra.get_file(self.ra, path, revision, out)
+            if isinstance(info, list):
+                info = info[-1]
+            mode = ("svn:executable" in info) and 'x' or ''
+            mode = ("svn:special" in info) and 'l' or mode
         except core.SubversionException, e:
             notfound = (core.SVN_ERR_FS_NOT_FOUND,
                         core.SVN_ERR_RA_DAV_PATH_NOT_FOUND)
@@ -400,7 +412,7 @@ class SubversionRepo(object):
                 raise IOError()
             raise
         data = out.getvalue()
-        return data
+        return data, mode
 
     def proplist(self, path, revision, recurse=False):
         if path[-1] == '/':