Rev 1234: Add abstraction layer around working copy functions. in file:///data/jelmer/bzr-svn/0.4-wc/
Jelmer Vernooij
jelmer at samba.org
Tue Jun 17 21:17:56 BST 2008
At file:///data/jelmer/bzr-svn/0.4-wc/
------------------------------------------------------------
revno: 1234
revision-id: jelmer at samba.org-20080617201754-q2q3jak510dod9ac
parent: jelmer at samba.org-20080617195350-opqh4swky27h0ky7
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: 0.4-wc
timestamp: Tue 2008-06-17 22:17:54 +0200
message:
Add abstraction layer around working copy functions.
added:
wc.py wc.py-20080617201206-br2171i7qnc473mz-1
modified:
transport.py transport.py-20060406231150-b3472d06b3a0818d
tree.py tree.py-20060624222557-dudlwqcmkf22lt2s-1
workingtree.py workingtree.py-20060306120941-b083cb0fdd4a69de
=== modified file 'transport.py'
--- a/transport.py 2008-06-16 17:04:17 +0000
+++ b/transport.py 2008-06-17 20:17:54 +0000
@@ -22,8 +22,6 @@
from bzrlib.transport import Transport
from svn.core import Pool
-import svn.core
-import svn.client
from bzrlib.plugins.svn.core import SubversionException, get_config
from bzrlib.plugins.svn.errors import convert_svn_error, NoSvnRepositoryPresent, ERR_BAD_URL, ERR_RA_SVN_REPOS_NOT_FOUND, ERR_FS_ALREADY_EXISTS, ERR_FS_NOT_FOUND, ERR_FS_NOT_DIRECTORY
=== modified file 'tree.py'
--- a/tree.py 2008-06-15 02:11:24 +0000
+++ b/tree.py 2008-06-17 20:17:54 +0000
@@ -28,10 +28,10 @@
from cStringIO import StringIO
import urllib
-import svn.wc, svn.delta
+import svn.delta
from svn.core import Pool
-from bzrlib.plugins.svn import errors, properties, core
+from bzrlib.plugins.svn import errors, properties, core, wc
def parse_externals_description(base_url, val):
"""Parse an svn:externals property value.
@@ -277,10 +277,8 @@
self._inventory = Inventory(root_id=None)
self._repository = workingtree.branch.repository
- def add_file_to_inv(relpath, id, revid, wc):
- props = svn.wc.get_prop_diffs(self.workingtree.abspath(relpath).encode("utf-8"), wc)
- if isinstance(props, list): # Subversion 1.5
- props = props[1]
+ def add_file_to_inv(relpath, id, revid, adm):
+ props = adm.get_prop_diffs(self.workingtree.abspath(relpath).encode("utf-8"))
if props.has_key(properties.PROP_SPECIAL):
ie = self._inventory.add_path(relpath, 'symlink', id)
ie.symlink_target = open(self._abspath(relpath)).read()[len("link "):]
@@ -299,14 +297,14 @@
def find_ids(entry):
relpath = urllib.unquote(entry.url[len(entry.repos):].strip("/"))
- if entry.schedule in (svn.wc.schedule_normal,
- svn.wc.schedule_delete,
- svn.wc.schedule_replace):
+ if entry.schedule in (wc.SCHEDULE_NORMAL,
+ wc.SCHEDULE_DELETE,
+ wc.SCHEDULE_REPLACE):
return self.id_map[workingtree.branch.unprefix(relpath.decode("utf-8"))]
return (None, None)
- def add_dir_to_inv(relpath, wc, parent_id):
- entries = svn.wc.entries_read(wc, False)
+ def add_dir_to_inv(relpath, adm, parent_id):
+ entries = adm.entries_read(False)
entry = entries[""]
(id, revid) = find_ids(entry)
if id == None:
@@ -331,26 +329,25 @@
assert entry
if entry.kind == core.NODE_DIR:
- subwc = svn.wc.adm_open3(wc,
- self.workingtree.abspath(subrelpath),
- False, 0, None)
+ subwc = wc.WorkingCopy(adm,
+ self.workingtree.abspath(subrelpath))
try:
add_dir_to_inv(subrelpath, subwc, id)
finally:
- svn.wc.adm_close(subwc)
+ subwc.close()
else:
(subid, subrevid) = find_ids(entry)
if subid is not None:
- add_file_to_inv(subrelpath, subid, subrevid, wc)
+ add_file_to_inv(subrelpath, subid, subrevid, adm)
- wc = workingtree._get_wc()
+ adm = workingtree._get_wc()
try:
- add_dir_to_inv(u"", wc, None)
+ add_dir_to_inv(u"", adm, None)
finally:
- svn.wc.adm_close(wc)
+ adm.close()
def _abspath(self, relpath):
- return svn.wc.get_pristine_copy_path(self.workingtree.abspath(relpath).encode("utf-8"))
+ return wc.get_pristine_copy_path(self.workingtree.abspath(relpath).encode("utf-8"))
def get_file_lines(self, file_id):
base_copy = self._abspath(self.id2path(file_id))
=== added file 'wc.py'
--- a/wc.py 1970-01-01 00:00:00 +0000
+++ b/wc.py 2008-06-17 20:17:54 +0000
@@ -0,0 +1,68 @@
+# Copyright (C) 2005-2007 Jelmer Vernooij <jelmer at samba.org>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import svn.wc
+
+SCHEDULE_NORMAL = svn.wc.schedule_normal
+SCHEDULE_ADD = svn.wc.schedule_add
+SCHEDULE_DELETE = svn.wc.schedule_delete
+SCHEDULE_REPLACE = svn.wc.schedule_replace
+
+class WorkingCopy:
+ def __init__(self, associated, path, write_lock=False, depth=0, cancel_func=None):
+ self.wc = svn.wc.adm_open3(associated, path, write_lock, depth, cancel_func)
+
+ def prop_get(self, name, path):
+ return svn.wc.prop_get(name, path, self.wc)
+
+ def prop_set(self, name, value, path, skip_checks=False):
+ return svn.wc.prop_set2(name, value, path, self.wc)
+
+ def close(self):
+ return svn.wc.adm_close(self.wc)
+
+ def add(self, file_path, copyfrom_url=None, copyfrom_rev=-1, cancel_func=None, notify_func=None):
+ return svn.wc.add2(file_path, self.wc, copyfrom_url, copyfrom_rev, cancel_func, notify_func)
+
+ def delete(self, file_path, cancel_func=None, notify_func=None):
+ return svn.wc.delete2(file_path, self.wc, cancel_func, notify_func)
+
+ def copy(self, src, dst, cancel_func=None, notify_func=None):
+ return svn.wc.copy(src, self.wc, dst, cancel_func, notify_func)
+
+ def entries_read(self, show_hidden=False):
+ return svn.wc.entries_read(self.wc, show_hidden)
+
+ def entry(self, path, show_hidden=False):
+ return svn.wc.entry(path, self.wc, show_hidden)
+
+ def get_prop_diffs(self, relpath):
+ props = svn.wc.get_prop_diffs(relpath, self.wc)
+ if isinstance(props, list): # Subversion 1.5
+ props = props[1]
+ return props
+
+ def process_committed(self, path, recurse, new_revnum, timestamp, committer, wcprop_changes=None,
+ remove_lock=False):
+ return svn.wc.process_committed2(path, self.wc, recurse, new_revnum, timestamp, committer,
+ wcprop_changes, remove_lock)
+
+get_default_ignores = svn.wc.get_default_ignores
+get_adm_dir = svn.wc.get_adm_dir
+is_adm_dir = svn.wc.is_adm_dir
+get_pristine_copy_path = svn.wc.get_pristine_copy_path
+
+def revision_status(path, trail_url=None, committed=True, cancel_func=None):
+ return svn.wc.revision_status(path, trail_url, committed, cancel_func)
=== modified file 'workingtree.py'
--- a/workingtree.py 2008-06-17 19:53:50 +0000
+++ b/workingtree.py 2008-06-17 20:17:54 +0000
@@ -48,6 +48,7 @@
from bzrlib.plugins.svn.transport import (SvnRaTransport, bzr_to_svn_url,
svn_config)
from bzrlib.plugins.svn.tree import SvnBasisTree
+from bzrlib.plugins.svn.wc import *
import os
import urllib
@@ -84,14 +85,14 @@
svn.client.svn_swig_py_get_commit_log_func
self._get_wc()
- status = svn.wc.revision_status(self.basedir, None, True, None, None)
+ status = revision_status(self.basedir, None, True)
self.base_revnum = status.max_rev
self.base_tree = SvnBasisTree(self)
self.base_revid = branch.generate_revision_id(self.base_revnum)
self.read_working_inventory()
- self.controldir = os.path.join(self.basedir, svn.wc.get_adm_dir(),
+ self.controldir = os.path.join(self.basedir, get_adm_dir(),
'bzr')
try:
os.makedirs(self.controldir)
@@ -99,21 +100,21 @@
except OSError:
pass
control_transport = bzrdir.transport.clone(urlutils.join(
- svn.wc.get_adm_dir(), 'bzr'))
+ get_adm_dir(), 'bzr'))
self._control_files = LockableFiles(control_transport, 'lock', LockDir)
def get_ignore_list(self):
- ignores = set([svn.wc.get_adm_dir()])
- ignores.update(svn.wc.get_default_ignores(svn_config))
+ ignores = set([get_adm_dir()])
+ ignores.update(get_default_ignores(svn_config))
def dir_add(wc, prefix, patprefix):
- ignorestr = svn.wc.prop_get(properties.PROP_IGNORE,
- self.abspath(prefix).rstrip("/"), wc)
+ ignorestr = wc.prop_get(properties.PROP_IGNORE,
+ self.abspath(prefix).rstrip("/"))
if ignorestr is not None:
for pat in ignorestr.splitlines():
ignores.add(urlutils.joinpath(patprefix, pat))
- entries = svn.wc.entries_read(wc, False)
+ entries = wc.entries_read(False)
for entry in entries:
if entry == "":
continue
@@ -124,23 +125,22 @@
subprefix = os.path.join(prefix, entry)
- subwc = svn.wc.adm_open3(wc, self.abspath(subprefix), False,
- 0, None)
+ subwc = WorkingCopy(wc, self.abspath(subprefix))
try:
dir_add(subwc, subprefix, urlutils.joinpath(patprefix, entry))
finally:
- svn.wc.adm_close(subwc)
+ subwc.close()
wc = self._get_wc()
try:
dir_add(wc, "", ".")
finally:
- svn.wc.adm_close(wc)
+ wc.close()
return ignores
def is_control_filename(self, path):
- return svn.wc.is_adm_dir(path)
+ return is_adm_dir(path)
def apply_inventory_delta(self, changes):
raise NotImplementedError(self.apply_inventory_delta)
@@ -157,17 +157,17 @@
wc = self._get_wc(write_lock=True)
try:
for file in files:
- svn.wc.delete2(self.abspath(file), wc, None, None, None)
+ wc.delete(self.abspath(file))
finally:
- svn.wc.adm_close(wc)
+ wc.close()
for file in files:
self._change_fileid_mapping(None, file)
self.read_working_inventory()
def _get_wc(self, relpath="", write_lock=False):
- return svn.wc.adm_open3(None, self.abspath(relpath).rstrip("/"),
- write_lock, 0, None)
+ return WorkingCopy(None, self.abspath(relpath).rstrip("/"),
+ write_lock)
def _get_rel_wc(self, relpath, write_lock=False):
dir = os.path.dirname(relpath)
@@ -182,15 +182,14 @@
for entry in from_paths:
try:
to_wc = self._get_wc(to_dir, write_lock=True)
- svn.wc.copy(self.abspath(entry), to_wc,
- os.path.basename(entry), None, None)
+ to_wc.copy(self.abspath(entry), os.path.basename(entry))
finally:
- svn.wc.adm_close(to_wc)
+ to_wc.close()
try:
from_wc = self._get_wc(write_lock=True)
- svn.wc.delete2(self.abspath(entry), from_wc, None, None, None)
+ from_wc.delete(self.abspath(entry))
finally:
- svn.wc.adm_close(from_wc)
+ from_wc.close()
new_name = urlutils.join(to_dir, os.path.basename(entry))
self._change_fileid_mapping(self.inventory.path2id(entry), new_name)
self._change_fileid_mapping(None, entry)
@@ -210,10 +209,10 @@
(from_wc, _) = self._get_rel_wc(from_rel, write_lock=True)
from_id = self.inventory.path2id(from_rel)
try:
- svn.wc.copy(self.abspath(from_rel), to_wc, to_file, None, None)
- svn.wc.delete2(self.abspath(from_rel), from_wc, None, None, None)
+ to_wc.copy(self.abspath(from_rel), to_file)
+ from_wc.delete(self.abspath(from_rel))
finally:
- svn.wc.adm_close(to_wc)
+ to_wc.close()
self._change_fileid_mapping(None, from_rel)
self._change_fileid_mapping(from_id, to_rel)
self.read_working_inventory()
@@ -263,35 +262,35 @@
def find_copies(url, relpath=""):
wc = self._get_wc(relpath)
- entries = svn.wc.entries_read(wc, False)
+ entries = wc.entries_read(False)
for entry in entries.values():
subrelpath = os.path.join(relpath, entry.name)
if entry.name == "" or entry.kind != 'directory':
if ((entry.copyfrom_url == url or entry.url == url) and
- not (entry.schedule in (svn.wc.schedule_delete,
- svn.wc.schedule_replace))):
+ not (entry.schedule in (SCHEDULE_DELETE,
+ SCHEDULE_REPLACE))):
yield os.path.join(
self.branch.get_branch_path().strip("/"),
subrelpath)
else:
find_copies(subrelpath)
- svn.wc.adm_close(wc)
+ wc.close()
def find_ids(entry, rootwc):
relpath = urllib.unquote(entry.url[len(entry.repos):].strip("/"))
- assert entry.schedule in (svn.wc.schedule_normal,
- svn.wc.schedule_delete,
- svn.wc.schedule_add,
- svn.wc.schedule_replace)
- if entry.schedule == svn.wc.schedule_normal:
+ assert entry.schedule in (SCHEDULE_NORMAL,
+ SCHEDULE_DELETE,
+ SCHEDULE_ADD,
+ SCHEDULE_REPLACE)
+ if entry.schedule == SCHEDULE_NORMAL:
assert entry.revision >= 0
# Keep old id
return self.path_to_file_id(entry.cmt_rev, entry.revision,
relpath)
- elif entry.schedule == svn.wc.schedule_delete:
+ elif entry.schedule == SCHEDULE_DELETE:
return (None, None)
- elif (entry.schedule == svn.wc.schedule_add or
- entry.schedule == svn.wc.schedule_replace):
+ elif (entry.schedule == SCHEDULE_ADD or
+ entry.schedule == SCHEDULE_REPLACE):
# See if the file this file was copied from disappeared
# and has no other copies -> in that case, take id of other file
if (entry.copyfrom_url and
@@ -306,7 +305,7 @@
def add_dir_to_inv(relpath, wc, parent_id):
assert isinstance(relpath, unicode)
- entries = svn.wc.entries_read(wc, False)
+ entries = wc.entries_read(False)
entry = entries[""]
assert parent_id is None or isinstance(parent_id, str), \
"%r is not a string" % parent_id
@@ -332,12 +331,11 @@
assert entry
if entry.kind == core.NODE_DIR:
- subwc = svn.wc.adm_open3(wc, self.abspath(subrelpath),
- False, 0, None)
+ subwc = WorkingCopy(wc, self.abspath(subrelpath))
try:
add_dir_to_inv(subrelpath, subwc, id)
finally:
- svn.wc.adm_close(subwc)
+ subwc.close()
else:
(subid, subrevid) = find_ids(entry, rootwc)
if subid:
@@ -349,7 +347,7 @@
try:
add_dir_to_inv(u"", rootwc, None)
finally:
- svn.wc.adm_close(rootwc)
+ rootwc.close()
self._set_inventory(inv, dirty=False)
return inv
@@ -377,31 +375,31 @@
revnum = self.branch.lookup_revision_id(
newrevtree.inventory[id].revision)
- svn.wc.process_committed2(self.abspath(path).rstrip("/"), wc,
+ wc.process_committed(self.abspath(path).rstrip("/"),
False, revnum,
time_to_cstring(newrev.timestamp),
- newrev.committer, None, False)
+ newrev.committer)
if newrevtree.inventory[id].kind != 'directory':
return
- entries = svn.wc.entries_read(wc, True)
+ entries = wc.entries_read(True)
for entry in entries:
if entry == "":
continue
- subwc = svn.wc.adm_open3(wc, os.path.join(self.basedir, path, entry), False, 0, None)
+ subwc = WorkingCopy(wc, os.path.join(self.basedir, path, entry))
try:
update_settings(subwc, os.path.join(path, entry))
finally:
- svn.wc.adm_close(subwc)
+ subwc.close()
# Set proper version for all files in the wc
wc = self._get_wc(write_lock=True)
try:
update_settings(wc, "")
finally:
- svn.wc.adm_close(wc)
+ wc.close()
self.base_revid = revid
def commit(self, message=None, message_callback=None, revprops=None,
@@ -439,17 +437,17 @@
extra = ""
wc = self._get_wc(write_lock=True)
try:
- svn.wc.prop_set(SVN_PROP_BZR_REVISION_ID+str(self.branch.mapping.scheme),
+ wc.prop_set(SVN_PROP_BZR_REVISION_ID+str(self.branch.mapping.scheme),
self._get_bzr_revids(self._get_base_branch_props()) + extra,
- self.basedir, wc)
- svn.wc.prop_set(SVN_PROP_BZR_REVISION_INFO,
+ self.basedir)
+ wc.prop_set(SVN_PROP_BZR_REVISION_INFO,
generate_revision_metadata(timestamp,
timezone,
committer,
revprops),
- self.basedir, wc)
+ self.basedir)
finally:
- svn.wc.adm_close(wc)
+ wc.close()
try:
try:
@@ -464,12 +462,12 @@
# accidently set these properties.
wc = self._get_wc(write_lock=True)
base_branch_props = self._get_base_branch_props()
- svn.wc.prop_set(SVN_PROP_BZR_REVISION_ID+str(self.branch.mapping.scheme),
- self._get_bzr_revids(base_branch_props), self.basedir, wc)
- svn.wc.prop_set(SVN_PROP_BZR_REVISION_INFO,
+ wc.prop_set(SVN_PROP_BZR_REVISION_ID+str(self.branch.mapping.scheme),
+ self._get_bzr_revids(base_branch_props), self.basedir)
+ wc.prop_set(SVN_PROP_BZR_REVISION_INFO,
base_branch_props.get(SVN_PROP_BZR_REVISION_INFO, ""),
- self.basedir, wc)
- svn.wc.adm_close(wc)
+ self.basedir)
+ wc.close()
raise
self.client_ctx.log_msg_baton2 = None
@@ -502,7 +500,7 @@
if not self.inventory.has_filename(f):
if save:
mutter('adding %r', file_path)
- svn.wc.add2(file_path, wc, None, 0, None, None, None)
+ wc.add(file_path)
added.append(file_path)
if recurse and file_kind(file_path) == 'directory':
# Filter out ignored files and update ignored
@@ -515,7 +513,7 @@
ignored.setdefault(ignore_glob, []).append(c_path)
todo.append(c_path)
finally:
- svn.wc.adm_close(wc)
+ wc.close()
if todo != []:
cadded, cignored = self.smart_add(todo, recurse, action, save)
added.extend(cadded)
@@ -535,8 +533,7 @@
wc = self._get_wc(os.path.dirname(f), write_lock=True)
try:
try:
- svn.wc.add2(os.path.join(self.basedir, f), wc, None, 0,
- None, None, None)
+ wc.add(os.path.join(self.basedir, f))
if ids is not None:
self._change_fileid_mapping(ids.next(), f, wc)
except SubversionException, (_, num):
@@ -546,7 +543,7 @@
raise NoSuchFile(path=f)
raise
finally:
- svn.wc.adm_close(wc)
+ wc.close()
self.read_working_inventory()
def basis_tree(self):
@@ -594,9 +591,9 @@
new_entries[path] = id
existing = "".join(map(lambda (path, id): "%s\t%s\n" % (path, id), new_entries.items()))
if existing != "":
- svn.wc.prop_set(SVN_PROP_BZR_FILEIDS, existing.encode("utf-8"), self.basedir, subwc)
+ subwc.prop_set(SVN_PROP_BZR_FILEIDS, existing.encode("utf-8"), self.basedir)
if wc is None:
- svn.wc.adm_close(subwc)
+ subwc.close()
def _get_base_branch_props(self):
return self.branch.repository.branchprop_list.get_properties(
@@ -604,7 +601,7 @@
def _get_new_file_ids(self, wc):
committed = self._get_base_branch_props().get(SVN_PROP_BZR_FILEIDS, "")
- existing = svn.wc.prop_get(SVN_PROP_BZR_FILEIDS, self.basedir, wc)
+ existing = wc.prop_get(SVN_PROP_BZR_FILEIDS, self.basedir)
if existing is None or committed == existing:
return {}
return dict(map(lambda x: str(x).split("\t"),
@@ -629,9 +626,9 @@
else:
bzr_merge = ""
- svn.wc.prop_set(SVN_PROP_BZR_ANCESTRY+str(self.branch.mapping.scheme),
+ wc.prop_set(SVN_PROP_BZR_ANCESTRY+str(self.branch.mapping.scheme),
self._get_bzr_merges(self._get_base_branch_props()) + bzr_merge,
- self.basedir, wc)
+ self.basedir)
svk_merges = parse_svk_features(self._get_svk_merges(self._get_base_branch_props()))
@@ -642,11 +639,10 @@
except InvalidRevisionId:
pass
- svn.wc.prop_set2(SVN_PROP_SVK_MERGE,
- serialize_svk_features(svk_merges), self.basedir,
- wc, False)
+ wc.prop_set(SVN_PROP_SVK_MERGE,
+ serialize_svk_features(svk_merges), self.basedir)
finally:
- svn.wc.adm_close(wc)
+ wc.close()
def add_pending_merge(self, revid):
merges = self.pending_merges()
@@ -657,14 +653,14 @@
merged = self._get_bzr_merges(self._get_base_branch_props()).splitlines()
wc = self._get_wc()
try:
- merged_data = svn.wc.prop_get(
- SVN_PROP_BZR_ANCESTRY+str(self.branch.mapping.scheme), self.basedir, wc)
+ merged_data = wc.prop_get(
+ SVN_PROP_BZR_ANCESTRY+str(self.branch.mapping.scheme), self.basedir)
if merged_data is None:
set_merged = []
else:
set_merged = merged_data.splitlines()
finally:
- svn.wc.adm_close(wc)
+ wc.close()
assert (len(merged) == len(set_merged) or
len(merged)+1 == len(set_merged))
@@ -724,11 +720,11 @@
self.local_path = transport.local_abspath(".")
# Open related remote repository + branch
- wc = svn.wc.adm_open3(None, self.local_path, False, 0, None)
+ wc = WorkingCopy(None, self.local_path)
try:
- self.svn_url = svn.wc.entry(self.local_path, wc, True).url
+ self.svn_url = wc.entry(self.local_path, True).url
finally:
- svn.wc.adm_close(wc)
+ wc.close()
self.remote_transport = SvnRaTransport(self.svn_url)
self.remote_bzrdir = SvnRemoteAccess(self.remote_transport)
More information about the bazaar-commits
mailing list