diff hgsubversion/svnwrap/subvertpy_wrapper.py @ 935:1de83496df4e

subvertpy_wrapper: fix files and directories batons handling The subvertpy wrapper was not recording and passing back the batons returned by calls such as open_file() or open_directory(). Instead, it was relying on knowledge about the HgEditor class and was passing the path argument. Its behaviour was therefore not exactly the same as the swig one because HgEditor sometimes tests the input baton and skips None ones, usually generated for ignored entries. Also, AbstractEditor was translating open_root() into open_directory(''), while the former, not implemented by HgEditor, was supplied as a default implementation by the swig bindings. The behaviour was different again. This patch was not motivated by any known bug but batons are interesting as they help control edited entries lifetime. We may use them to reduce replay mode memory consumption.
author Patrick Mezard <patrick@mezard.eu>
date Sun, 23 Sep 2012 19:42:34 +0200
parents e1dbd9646d6a
children bb599a47a9d0
line wrap: on
line diff
--- a/hgsubversion/svnwrap/subvertpy_wrapper.py
+++ b/hgsubversion/svnwrap/subvertpy_wrapper.py
@@ -87,35 +87,39 @@ class PathAdapter(object):
             self.copyfrom_path = intern(self.copyfrom_path)
 
 class AbstractEditor(object):
-    __slots__ = ('editor',)
+    __slots__ = ('editor', 'baton')
 
-    def __init__(self, editor):
+    def __init__(self, editor, baton=None):
         self.editor = editor
+        self.baton = baton
 
     def set_target_revision(self, rev):
         pass
 
     def open_root(self, base_revnum):
-        return self.open_directory('', base_revnum)
+        baton = self.editor.open_root(None, base_revnum)
+        return DirectoryEditor(self.editor, baton)
 
     def open_directory(self, path, base_revnum):
-        self.editor.open_directory(path, None, base_revnum)
-        return DirectoryEditor(self.editor, path)
+        baton = self.editor.open_directory(path, self.baton, base_revnum)
+        return DirectoryEditor(self.editor, baton)
 
     def open_file(self, path, base_revnum):
-        self.editor.open_file(path, None, base_revnum)
-        return FileEditor(self.editor, path)
+        baton = self.editor.open_file(path, self.baton, base_revnum)
+        return FileEditor(self.editor, baton)
 
     def add_directory(self, path, copyfrom_path=None, copyfrom_rev=-1):
-        self.editor.add_directory(path, None, copyfrom_path, copyfrom_rev)
-        return DirectoryEditor(self.editor, path)
+        baton = self.editor.add_directory(
+            path, self.baton, copyfrom_path, copyfrom_rev)
+        return DirectoryEditor(self.editor, baton)
 
     def add_file(self, path, copyfrom_path=None, copyfrom_rev=-1):
-        self.editor.add_file(path, None, copyfrom_path, copyfrom_rev)
-        return FileEditor(self.editor, path)
+        baton = self.editor.add_file(
+            path, self.baton, copyfrom_path, copyfrom_rev)
+        return FileEditor(self.editor, baton)
 
     def apply_textdelta(self, base_checksum):
-        return self.editor.apply_textdelta(self, None, base_checksum)
+        return self.editor.apply_textdelta(self.baton, base_checksum)
 
     def change_prop(self, name, value):
         raise NotImplementedError()
@@ -128,36 +132,28 @@ class AbstractEditor(object):
         del self.editor
 
     def delete_entry(self, path, revnum):
-        self.editor.delete_entry(path, revnum, None)
+        self.editor.delete_entry(path, revnum, self.baton)
 
 class FileEditor(AbstractEditor):
-    __slots__ = ('path',)
-
-    def __init__(self, editor, path):
-        super(FileEditor, self).__init__(editor)
-        self.path = path
+    def __init__(self, editor, baton):
+        super(FileEditor, self).__init__(editor, baton)
 
     def change_prop(self, name, value):
-        self.editor.change_file_prop(self.path, name, value, pool=None)
+        self.editor.change_file_prop(self.baton, name, value, pool=None)
 
     def close(self, checksum=None):
         super(FileEditor, self).close()
-        del self.path
 
 class DirectoryEditor(AbstractEditor):
-    __slots__ = ('path',)
-
-    def __init__(self, editor, path):
-        super(DirectoryEditor, self).__init__(editor)
-        self.path = path
+    def __init__(self, editor, baton):
+        super(DirectoryEditor, self).__init__(editor, baton)
 
     def change_prop(self, name, value):
-        self.editor.change_dir_prop(self.path, name, value, pool=None)
+        self.editor.change_dir_prop(self.baton, name, value, pool=None)
 
     def close(self):
-        self.editor.close_directory(self.path)
+        self.editor.close_directory(self.baton)
         super(DirectoryEditor, self).close()
-        del self.path
 
 class SubversionRepo(object):
     """Wrapper for a Subversion repository.