Rev 1237: More object oriented editor interface. in http://people.samba.org/bzr/jelmer/bzr-svn/0.4/
Jelmer Vernooij
jelmer at samba.org
Tue Jun 17 23:21:32 BST 2008
At http://people.samba.org/bzr/jelmer/bzr-svn/0.4/
------------------------------------------------------------
revno: 1237
revision-id: jelmer at samba.org-20080617222130-x7hg1cok27gp6qme
parent: jelmer at samba.org-20080617210310-x1uzjw4hry0x252d
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: 0.4
timestamp: Wed 2008-06-18 00:21:30 +0200
message:
More object oriented editor interface.
modified:
commit.py commit.py-20060607190346-qvq128wgfubhhgm2-1
mapping3/__init__.py __init__.py-20080502174630-9324zh25kka98vlw-1
ra.py ra.py-20080615005305-t5221niknu8rm6bt-1
tests/__init__.py __init__.py-20060508151940-e9f4d914801a2535
tests/test_fetch.py test_fetch.py-20070624210302-luvgwjmlfysk5qeq-1
=== modified file 'commit.py'
--- a/commit.py 2008-06-17 20:55:23 +0000
+++ b/commit.py 2008-06-17 22:21:30 +0000
@@ -193,7 +193,7 @@
:param baton: Baton under which the file is known to the editor.
"""
assert baton is not None
- (txdelta, txbaton) = self.editor.apply_textdelta(baton, None)
+ (txdelta, txbaton) = baton.apply_textdelta(None)
digest = txdelta_send_stream(StringIO(contents), txdelta, txbaton)
if 'validate' in debug.debug_flags:
from fetch import md5_strings
@@ -222,9 +222,9 @@
# ... name changed
self.new_inventory[child_ie.file_id].name != child_name):
self.mutter('removing %r(%r)', (child_name, child_ie.file_id))
- self.editor.delete_entry(
+ baton.delete_entry(
urlutils.join(self.branch.get_branch_path(), path, child_name),
- self.base_revnum, baton)
+ self.base_revnum)
# Loop over file children of file_id in self.new_inventory
for child_name in self.new_inventory[file_id].children:
@@ -240,8 +240,8 @@
# add them if they didn't exist in old_inv
if not child_ie.file_id in self.old_inv:
self.mutter('adding %s %r', child_ie.kind, new_child_path)
- child_baton = self.editor.add_file(
- full_new_child_path, baton, None, -1)
+ child_baton = baton.add_file(
+ full_new_child_path, None, -1)
# copy if they existed at different location
@@ -250,8 +250,8 @@
self.mutter('copy %s %r -> %r', child_ie.kind,
self.old_inv.id2path(child_ie.file_id),
new_child_path)
- child_baton = self.editor.add_file(
- full_new_child_path, baton,
+ child_baton = baton.add_file(
+ full_new_child_path,
urlutils.join(self.repository.transport.svn_url, self.base_path, self.old_inv.id2path(child_ie.file_id)),
self.base_revnum)
@@ -259,8 +259,8 @@
elif child_ie.revision is None:
self.mutter('open %s %r', child_ie.kind, new_child_path)
- child_baton = self.editor.open_file(
- full_new_child_path, baton, self.base_revnum)
+ child_baton = baton.open_file(
+ full_new_child_path, self.base_revnum)
else:
# Old copy of the file was retained. No need to send changes
@@ -280,7 +280,7 @@
value = properties.PROP_EXECUTABLE_VALUE
else:
value = None
- self.editor.change_file_prop(child_baton,
+ child_baton.change_prop(
properties.PROP_EXECUTABLE, value)
if old_special != (child_ie.kind == 'symlink'):
@@ -289,7 +289,7 @@
else:
value = None
- self.editor.change_file_prop(child_baton,
+ child_baton.change_prop(
properties.PROP_SPECIAL, value)
# handle the file
@@ -298,7 +298,7 @@
self.modified_files[child_ie.file_id], child_baton)
if child_baton is not None:
- self.editor.close_file(child_baton, None)
+ child_baton.close(None)
# Loop over subdirectories of file_id in self.new_inventory
for child_name in self.new_inventory[file_id].children:
@@ -310,17 +310,16 @@
# add them if they didn't exist in old_inv
if not child_ie.file_id in self.old_inv:
self.mutter('adding dir %r', child_ie.name)
- child_baton = self.editor.add_directory(
+ child_baton = baton.add_directory(
urlutils.join(self.branch.get_branch_path(),
- new_child_path), baton, None, -1)
+ new_child_path), None, -1)
# copy if they existed at different location
elif self.old_inv.id2path(child_ie.file_id) != new_child_path:
old_child_path = self.old_inv.id2path(child_ie.file_id)
self.mutter('copy dir %r -> %r', old_child_path, new_child_path)
- child_baton = self.editor.add_directory(
+ child_baton = baton.add_directory(
urlutils.join(self.branch.get_branch_path(), new_child_path),
- baton,
urlutils.join(self.repository.transport.svn_url, self.base_path, old_child_path), self.base_revnum)
# open if they existed at the same location and
@@ -328,9 +327,9 @@
elif self.new_inventory[child_ie.file_id].revision is None:
self.mutter('open dir %r', new_child_path)
- child_baton = self.editor.open_directory(
+ child_baton = baton.open_directory(
urlutils.join(self.branch.get_branch_path(), new_child_path),
- baton, self.base_revnum)
+ self.base_revnum)
else:
assert child_ie.file_id not in self.modified_dirs
continue
@@ -339,7 +338,7 @@
if child_ie.file_id in self.modified_dirs:
self._dir_process(new_child_path, child_ie.file_id, child_baton)
- self.editor.close_directory(child_baton)
+ child_baton.close()
def open_branch_batons(self, root, elements, existing_elements,
base_path, base_rev, replace_existing):
@@ -360,8 +359,8 @@
# Open paths leading up to branch
for i in range(0, len(elements)-1):
# Does directory already exist?
- ret.append(self.editor.open_directory(
- "/".join(existing_elements[0:i+1]), ret[-1], -1))
+ ret.append(ret[-1].open_directory(
+ "/".join(existing_elements[0:i+1]), -1))
if (len(existing_elements) != len(elements) and
len(existing_elements)+1 != len(elements)):
@@ -374,8 +373,8 @@
# branch_path.
if (len(existing_elements) == len(elements) and
not replace_existing):
- ret.append(self.editor.open_directory(
- "/".join(elements), ret[-1], base_rev))
+ ret.append(ret[-1].open_directory(
+ "/".join(elements), base_rev))
else: # Branch has to be created
# Already exists, old copy needs to be removed
name = "/".join(elements)
@@ -383,14 +382,14 @@
if name == "":
raise ChangesRootLHSHistory()
self.mutter("removing branch dir %r", name)
- self.editor.delete_entry(name, -1, ret[-1])
+ ret[-1].delete_entry(name, -1)
if base_path is not None:
base_url = urlutils.join(self.repository.transport.svn_url, base_path)
else:
base_url = None
self.mutter("adding branch dir %r", name)
- ret.append(self.editor.add_directory(
- name, ret[-1], base_url, base_rev))
+ ret.append(ret[-1].add_directory(
+ name, base_url, base_rev))
return ret
@@ -493,11 +492,11 @@
warning("Setting property %r with invalid characters in name", prop)
if value is not None:
value = value.encode('utf-8')
- self.editor.change_dir_prop(branch_batons[-1], prop, value)
+ branch_batons[-1].change_prop(prop, value)
self.mutter("Setting root file property %r -> %r", prop, value)
for baton in reversed(branch_batons):
- self.editor.close_directory(baton)
+ baton.close()
self.editor.close()
finally:
=== modified file 'mapping3/__init__.py'
--- a/mapping3/__init__.py 2008-06-15 02:11:24 +0000
+++ b/mapping3/__init__.py 2008-06-17 22:21:30 +0000
@@ -122,10 +122,10 @@
editor = repository.transport.get_commit_editor(
{properties.PROP_REVISION_LOG: "Updating branching scheme for Bazaar."},
done, None, False)
- root = editor.open_root(-1)
- editor.change_dir_prop(root, SVN_PROP_BZR_BRANCHING_SCHEME,
+ root = editor.open_root()
+ root.change_prop(SVN_PROP_BZR_BRANCHING_SCHEME,
"".join(map(lambda x: x+"\n", scheme.branch_list)).encode("utf-8"))
- editor.close_directory(root)
+ root.close()
editor.close()
=== modified file 'ra.py'
--- a/ra.py 2008-06-17 21:03:10 +0000
+++ b/ra.py 2008-06-17 22:21:30 +0000
@@ -38,6 +38,74 @@
DIRENT_KIND = 0x0001
+class FileEditor(object):
+ def __init__(self, base_editor, baton):
+ self.base_editor = base_editor
+ self.baton = baton
+
+ def apply_textdelta(self, base_checksum=None):
+ assert self.base_editor.recent_baton[-1] == self.baton
+ return svn.delta.editor_invoke_apply_textdelta(self.base_editor.editor, self.baton,
+ base_checksum)
+
+ def change_prop(self, name, value):
+ assert self.base_editor.recent_baton[-1] == self.baton
+ svn.delta.editor_invoke_change_file_prop(self.base_editor.editor, self.baton, name,
+ value, None)
+
+ def close(self, checksum=None):
+ assert self.base_editor.recent_baton.pop() == self.baton
+ svn.delta.editor_invoke_close_file(self.base_editor.editor, self.baton, checksum)
+
+
+class DirEditor(object):
+ def __init__(self, base_editor, baton):
+ self.base_editor = base_editor
+ self.baton = baton
+
+ def close(self):
+ assert self.base_editor.recent_baton.pop() == self.baton, \
+ "only most recently opened baton can be closed"
+ svn.delta.editor_invoke_close_directory(self.base_editor.editor, self.baton)
+
+ def change_prop(self, name, value):
+ assert self.base_editor.recent_baton[-1] == self.baton
+ return svn.delta.editor_invoke_change_dir_prop(self.base_editor.editor, self.baton,
+ name, value, None)
+
+ def delete_entry(self, path, revnum):
+ assert self.base_editor.recent_baton[-1] == self.baton
+ return svn.delta.editor_invoke_delete_entry(self.base_editor.editor, path, revnum, self.baton, None)
+
+ def add_file(self, path, copy_path=None, copy_revision=-1):
+ assert self.base_editor.recent_baton[-1] == self.baton
+ baton = svn.delta.editor_invoke_add_file(self.base_editor.editor, path,
+ self.baton, copy_path, copy_revision)
+ self.base_editor.recent_baton.append(baton)
+ return FileEditor(self.base_editor, baton)
+
+ def open_file(self, path, base_revision=-1):
+ assert self.base_editor.recent_baton[-1] == self.baton
+ baton = svn.delta.editor_invoke_open_file(self.base_editor.editor, path, self.baton,
+ base_revision)
+ self.base_editor.recent_baton.append(baton)
+ return FileEditor(self.base_editor, baton)
+
+ def add_directory(self, path, copy_path=None, copy_revision=-1):
+ assert self.base_editor.recent_baton[-1] == self.baton
+ baton = svn.delta.editor_invoke_add_directory(self.base_editor.editor, path,
+ self.baton, copy_path, copy_revision)
+ self.base_editor.recent_baton.append(baton)
+ return DirEditor(self.base_editor, baton)
+
+ def open_directory(self, path, base_revision=-1):
+ assert self.base_editor.recent_baton[-1] == self.baton
+ baton = svn.delta.editor_invoke_open_directory(self.base_editor.editor, path,
+ self.baton, base_revision)
+ self.base_editor.recent_baton.append(baton)
+ return DirEditor(self.base_editor, baton)
+
+
class Editor(object):
"""Simple object wrapper around the Subversion delta editor interface."""
def __init__(self, connection, (editor, editor_baton)):
@@ -51,68 +119,13 @@
baton = svn.delta.editor_invoke_open_root(self.editor,
self.editor_baton, base_revnum)
self.recent_baton.append(baton)
- return baton
-
- def close_directory(self, baton, *args, **kwargs):
- assert self.recent_baton.pop() == baton, \
- "only most recently opened baton can be closed"
- svn.delta.editor_invoke_close_directory(self.editor, baton, *args, **kwargs)
+ return DirEditor(self, baton)
def close(self):
assert self.recent_baton == []
svn.delta.editor_invoke_close_edit(self.editor, self.editor_baton)
self._connection._unmark_busy()
- def apply_textdelta(self, baton, *args, **kwargs):
- assert self.recent_baton[-1] == baton
- return svn.delta.editor_invoke_apply_textdelta(self.editor, baton,
- *args, **kwargs)
-
- def change_dir_prop(self, baton, name, value):
- assert self.recent_baton[-1] == baton
- return svn.delta.editor_invoke_change_dir_prop(self.editor, baton,
- name, value, None)
-
- def delete_entry(self, *args, **kwargs):
- return svn.delta.editor_invoke_delete_entry(self.editor, *args, **kwargs)
-
- def add_file(self, path, parent_baton, *args, **kwargs):
- assert self.recent_baton[-1] == parent_baton
- baton = svn.delta.editor_invoke_add_file(self.editor, path,
- parent_baton, *args, **kwargs)
- self.recent_baton.append(baton)
- return baton
-
- def open_file(self, path, parent_baton, *args, **kwargs):
- assert self.recent_baton[-1] == parent_baton
- baton = svn.delta.editor_invoke_open_file(self.editor, path,
- parent_baton, *args, **kwargs)
- self.recent_baton.append(baton)
- return baton
-
- def change_file_prop(self, baton, name, value):
- assert self.recent_baton[-1] == baton
- svn.delta.editor_invoke_change_file_prop(self.editor, baton, name,
- value, None)
-
- def close_file(self, baton, *args, **kwargs):
- assert self.recent_baton.pop() == baton
- svn.delta.editor_invoke_close_file(self.editor, baton, *args, **kwargs)
-
- def add_directory(self, path, parent_baton, *args, **kwargs):
- assert self.recent_baton[-1] == parent_baton
- baton = svn.delta.editor_invoke_add_directory(self.editor, path,
- parent_baton, *args, **kwargs)
- self.recent_baton.append(baton)
- return baton
-
- def open_directory(self, path, parent_baton, *args, **kwargs):
- assert self.recent_baton[-1] == parent_baton
- baton = svn.delta.editor_invoke_open_directory(self.editor, path,
- parent_baton, *args, **kwargs)
- self.recent_baton.append(baton)
- return baton
-
class Auth:
def __init__(self, providers=[]):
@@ -310,7 +323,7 @@
svn.ra.replay(self._ra, revision, low_water_mark, send_deltas,
edit, edit_baton, None)
- def do_update(self, revnum, recurse, path, editor):
+ def do_update(self, revnum, path, recurse, editor):
self.mutter('svn update -r %r', revnum)
self._mark_busy()
edit, edit_baton = self._make_editor(editor)
@@ -324,7 +337,7 @@
self.mutter('svn revprop-list -r %r', revnum)
return svn.ra.rev_proplist(self._ra, revnum, None)
- def get_commit_editor(self, revprops, done_cb, lock_token, keep_locks):
+ def get_commit_editor(self, revprops, done_cb=None, lock_token=None, keep_locks=False):
self._mark_busy()
try:
if hasattr(svn.ra, 'get_commit_editor3'):
=== modified file 'tests/__init__.py'
--- a/tests/__init__.py 2008-06-15 02:11:24 +0000
+++ b/tests/__init__.py 2008-06-17 22:21:30 +0000
@@ -31,6 +31,7 @@
import svn.core, svn.repos, svn.wc
from bzrlib.plugins.svn.errors import NoCheckoutSupport
+from bzrlib.plugins.svn.ra import RemoteAccess
class TestCaseWithSubversionRepository(TestCaseInTempDir):
"""A test case that provides the ability to build Subversion
@@ -281,15 +282,13 @@
return svn.repos.fs(repos)
def commit_editor(self, url, message="Test commit"):
- ra = svn.client.open_ra_session(url.encode('utf8'),
- self.client_ctx)
+ ra = RemoteAccess(url.encode('utf8'))
class CommitEditor:
- def __init__(self, ra, editor, edit_baton, base_revnum, base_url):
+ def __init__(self, ra, editor, base_revnum, base_url):
self._used = False
self.ra = ra
self.base_revnum = base_revnum
self.editor = editor
- self.edit_baton = edit_baton
self.data = {}
self.create = set()
self.props = {}
@@ -350,49 +349,48 @@
for name, contents in dir_dict.items():
subpath = urlutils.join(path, name).strip("/")
if contents is None:
- svn.delta.editor_invoke_delete_entry(self.editor, subpath, -1, dir_baton)
+ dir_baton.delete_entry(subpath, -1)
elif isinstance(contents, dict):
if subpath in self.create:
- child_baton = svn.delta.editor_invoke_add_directory(self.editor, subpath, dir_baton, self.copyfrom[subpath][0], self.copyfrom[subpath][1])
+ child_baton = dir_baton.add_directory(subpath, self.copyfrom[subpath][0], self.copyfrom[subpath][1])
else:
- child_baton = svn.delta.editor_invoke_open_directory(self.editor, subpath, dir_baton, -1)
+ child_baton = dir_baton.open_directory(subpath, -1)
if subpath in self.props:
for k, v in self.props[subpath].items():
- svn.delta.editor_invoke_change_dir_prop(self.editor, child_baton, k, v)
+ child_baton.change_prop(k, v)
self._process_dir(child_baton, dir_dict[name], subpath)
- svn.delta.editor_invoke_close_directory(self.editor, child_baton)
+ child_baton.close()
else:
if subpath in self.create:
- child_baton = svn.delta.editor_invoke_add_file(self.editor, subpath, dir_baton, None, -1)
+ child_baton = dir_baton.add_file(subpath, None, -1)
else:
- child_baton = svn.delta.editor_invoke_open_file(self.editor, subpath, dir_baton, -1)
+ child_baton = dir_baton.open_file(subpath)
if isinstance(contents, str):
- (txdelta, txbaton) = svn.delta.editor_invoke_apply_textdelta(self.editor, child_baton, None)
+ (txdelta, txbaton) = child_baton.apply_textdelta()
svn.delta.svn_txdelta_send_stream(StringIO(contents), txdelta, txbaton)
if subpath in self.props:
for k, v in self.props[subpath].items():
- svn.delta.editor_invoke_change_file_prop(self.editor, child_baton, k, v)
- svn.delta.editor_invoke_close_file(self.editor, child_baton, None)
+ child_baton.change_prop(k, v)
+ child_baton.close()
def done(self):
assert self._used == False
self._used = True
- root_baton = svn.delta.editor_invoke_open_root(self.editor, self.edit_baton,
- self.base_revnum)
+ root_baton = self.editor.open_root(self.base_revnum)
self._process_dir(root_baton, self.data, "")
- svn.delta.editor_invoke_close_directory(self.editor, root_baton)
- svn.delta.editor_invoke_close_edit(self.editor, self.edit_baton)
+ root_baton.close()
+ self.editor.close()
- my_revnum = svn.ra.get_latest_revnum(ra)
+ my_revnum = ra.get_latest_revnum()
assert my_revnum > self.base_revnum
return my_revnum
- base_revnum = svn.ra.get_latest_revnum(ra)
- editor, edit_baton = svn.ra.get_commit_editor(ra, message, None, None, True)
- return CommitEditor(ra, editor, edit_baton, base_revnum, url)
+ base_revnum = ra.get_latest_revnum()
+ editor = ra.get_commit_editor({"svn:log": message})
+ return CommitEditor(ra, editor, base_revnum, url)
def test_suite():
=== modified file 'tests/test_fetch.py'
--- a/tests/test_fetch.py 2008-06-15 02:48:51 +0000
+++ b/tests/test_fetch.py 2008-06-17 22:21:30 +0000
@@ -1553,10 +1553,10 @@
pass
editor = ra.get_commit_editor({"svn:log": "msg"}, done, None, False)
root_baton = editor.open_root(1)
- baton = editor.open_file("mylink", root_baton, 1)
- editor.change_file_prop(baton, "svn:special", "*")
- editor.close_file(baton, None)
- editor.close_directory(root_baton)
+ baton = root_baton.open_file("mylink", 1)
+ baton.change_prop("svn:special", "*")
+ baton.close()
+ root_baton.close()
editor.close()
oldrepos = Repository.open("svn+"+repos_url)
dir = BzrDir.create("f", format.get_rich_root_format())
More information about the bazaar-commits
mailing list