# HG changeset patch # User Patrick Mezard # Date 1348416416 -7200 # Node ID bb599a47a9d0c6ff45f697c6bc06d97e908004da # Parent 1de83496df4e9a1519407c590701fa784aaa9274 subvertpy_wrapper: move methods in the relevant editors Files and directories can only be opened/deleted/closed from a DirectoryEditor, and deltas can only be applied on a FileEditor. Invariants could be made stronger by adding a third RevisionEditor class containing set_target_revision() and open_root() but this will probably not give interesting results. diff --git a/hgsubversion/svnwrap/subvertpy_wrapper.py b/hgsubversion/svnwrap/subvertpy_wrapper.py --- a/hgsubversion/svnwrap/subvertpy_wrapper.py +++ b/hgsubversion/svnwrap/subvertpy_wrapper.py @@ -100,30 +100,6 @@ class AbstractEditor(object): baton = self.editor.open_root(None, base_revnum) return DirectoryEditor(self.editor, baton) - def open_directory(self, path, base_revnum): - baton = self.editor.open_directory(path, self.baton, base_revnum) - return DirectoryEditor(self.editor, baton) - - def open_file(self, path, base_revnum): - 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): - 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): - 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.baton, base_checksum) - - def change_prop(self, name, value): - raise NotImplementedError() - def abort(self): # TODO: should we do something special here? self.close() @@ -131,9 +107,6 @@ class AbstractEditor(object): def close(self): del self.editor - def delete_entry(self, path, revnum): - self.editor.delete_entry(path, revnum, self.baton) - class FileEditor(AbstractEditor): def __init__(self, editor, baton): super(FileEditor, self).__init__(editor, baton) @@ -141,6 +114,9 @@ class FileEditor(AbstractEditor): def change_prop(self, name, value): self.editor.change_file_prop(self.baton, name, value, pool=None) + def apply_textdelta(self, base_checksum): + return self.editor.apply_textdelta(self.baton, base_checksum) + def close(self, checksum=None): super(FileEditor, self).close() @@ -148,6 +124,27 @@ class DirectoryEditor(AbstractEditor): def __init__(self, editor, baton): super(DirectoryEditor, self).__init__(editor, baton) + def delete_entry(self, path, revnum): + self.editor.delete_entry(path, revnum, self.baton) + + def open_directory(self, path, base_revnum): + baton = self.editor.open_directory(path, self.baton, base_revnum) + return DirectoryEditor(self.editor, baton) + + def add_directory(self, path, copyfrom_path=None, copyfrom_rev=-1): + baton = self.editor.add_directory( + path, self.baton, copyfrom_path, copyfrom_rev) + return DirectoryEditor(self.editor, baton) + + def open_file(self, path, base_revnum): + baton = self.editor.open_file(path, self.baton, base_revnum) + return FileEditor(self.editor, baton) + + def add_file(self, path, copyfrom_path=None, copyfrom_rev=-1): + baton = self.editor.add_file( + path, self.baton, copyfrom_path, copyfrom_rev) + return FileEditor(self.editor, baton) + def change_prop(self, name, value): self.editor.change_dir_prop(self.baton, name, value, pool=None)