# HG changeset patch # User Dan Villiom Podlaski Christiansen # Date 1270050669 -7200 # Node ID 0fe490ce2fbb82bbda0ff0f3603a087e8d8d0a5e # Parent a42e9c9bbb8af8f5a6040bc43c801a243ae79601 isolate all imports of Subversion modules in svnwrap. editor: move dependancy on Subversion bindings to svnwrap package. In the editor, this involves importing the superclass of `HgEditor' as `svnwrap.Editor'. Additionally, the `delta.svn_txdelta_apply()' function has been abstracted away into a simpler interface, stored in `svnwrap.apply_txdelta()'. diff --git a/hgsubversion/editor.py b/hgsubversion/editor.py --- a/hgsubversion/editor.py +++ b/hgsubversion/editor.py @@ -4,12 +4,10 @@ import sys from mercurial import util as hgutil from mercurial import revlog from mercurial import node -from svn import delta -from svn import core +import svnwrap import util - def ieditor(fn): """Helps identify methods used by the SVN editor interface. @@ -113,7 +111,7 @@ class RevisionData(object): self.ui.note('\n') -class HgEditor(delta.Editor): +class HgEditor(svnwrap.Editor): def __init__(self, meta): self.meta = meta @@ -339,11 +337,10 @@ class HgEditor(delta.Editor): if self.current.file in self.current.missing: return lambda x: None base = self.current.files[self.current.file] - source = cStringIO.StringIO(base) target = cStringIO.StringIO() self.stream = target - handler, baton = delta.svn_txdelta_apply(source, target, None) + handler = svnwrap.apply_txdelta(base, target) if not callable(handler): #pragma: no cover raise hgutil.Abort('Error in Subversion bindings: ' 'cannot call handler!') @@ -351,12 +348,12 @@ class HgEditor(delta.Editor): try: if not self.meta.is_path_valid(self.current.file): return - handler(window, baton) + handler(window) # window being None means commit this file if not window: self.current.files[self.current.file] = target.getvalue() - except core.SubversionException, e: #pragma: no cover - if e.apr_err == core.SVN_ERR_INCOMPLETE_DATA: + except svnwrap.SubversionException, e: #pragma: no cover + if e.args[1] == svnwrap.ERR_INCOMPLETE_DATA: self.current.missing.add(self.current.file) else: #pragma: no cover raise hgutil.Abort(*e.args) diff --git a/hgsubversion/pushmod.py b/hgsubversion/pushmod.py --- a/hgsubversion/pushmod.py +++ b/hgsubversion/pushmod.py @@ -1,7 +1,5 @@ from mercurial import util as hgutil -from svn import core - import svnwrap import svnexternals @@ -18,7 +16,7 @@ def _isdir(svn, branchpath, svndir): path = branchpath + '/' svn.list_dir('%s%s' % (path, svndir)) return True - except core.SubversionException: + except svnwrap.SubversionException: return False @@ -201,9 +199,9 @@ def commit(ui, repo, rev_ctx, meta, base svn.commit(new_target_files, rev_ctx.description(), file_data, base_revision, set(addeddirs), set(deleteddirs), props, newcopies) - except core.SubversionException, e: - if hasattr(e, 'apr_err') and (e.apr_err == core.SVN_ERR_FS_TXN_OUT_OF_DATE - or e.apr_err == core.SVN_ERR_FS_CONFLICT): + except svnwrap.SubversionException, e: + if len(e.args) > 0 and e.args[1] in (svnwrap.ERR_FS_TXN_OUT_OF_DATE, + svnwrap.ERR_FS_CONFLICT): raise hgutil.Abort('Outgoing changesets parent is not at ' 'subversion HEAD\n' '(pull again and rebase on a newer revision)') diff --git a/hgsubversion/stupid.py b/hgsubversion/stupid.py --- a/hgsubversion/stupid.py +++ b/hgsubversion/stupid.py @@ -6,7 +6,6 @@ from mercurial import patch from mercurial import node from mercurial import context from mercurial import revlog -from svn import core import svnwrap import svnexternals @@ -125,8 +124,8 @@ def diff_branchrev(ui, svn, meta, branch raise BadPatchApply('branch creation with mods') except svnwrap.SubversionRepoCanNotDiff: raise BadPatchApply('subversion diffing code is not supported') - except core.SubversionException, e: - if (hasattr(e, 'apr_err') and e.apr_err != core.SVN_ERR_FS_NOT_FOUND): + except svnwrap.SubversionException, e: + if len(e.args) > 1 and e.args[1] != svnwrap.ERR_FS_NOT_FOUND: raise raise BadPatchApply('previous revision does not exist') if '\0' in d: diff --git a/hgsubversion/svnwrap/svn_swig_wrapper.py b/hgsubversion/svnwrap/svn_swig_wrapper.py --- a/hgsubversion/svnwrap/svn_swig_wrapper.py +++ b/hgsubversion/svnwrap/svn_swig_wrapper.py @@ -42,6 +42,20 @@ class SubversionRepoCanNotDiff(Exception '''Default chunk size used in fetch_history_at_paths() and revisions().''' _chunk_size = 1000 +# exported values +ERR_FS_CONFLICT = core.SVN_ERR_FS_CONFLICT +ERR_FS_NOT_FOUND = core.SVN_ERR_FS_NOT_FOUND +ERR_FS_TXN_OUT_OF_DATE = core.SVN_ERR_FS_TXN_OUT_OF_DATE +ERR_INCOMPLETE_DATA = core.SVN_ERR_INCOMPLETE_DATA +ERR_RA_DAV_REQUEST_FAILED = core.SVN_ERR_RA_DAV_REQUEST_FAILED +SubversionException = core.SubversionException +Editor = delta.Editor + +def apply_txdelta(base, target): + handler, baton = delta.svn_txdelta_apply(cStringIO.StringIO(base), + target, None) + return (lambda window: handler(window, baton)) + def optrev(revnum): optrev = core.svn_opt_revision_t() optrev.kind = core.svn_opt_revision_number diff --git a/hgsubversion/wrappers.py b/hgsubversion/wrappers.py --- a/hgsubversion/wrappers.py +++ b/hgsubversion/wrappers.py @@ -7,8 +7,6 @@ from mercurial import util as hgutil from mercurial import node from mercurial import i18n -from svn import core - import replay import pushmod import stupid as stupidmod @@ -294,8 +292,8 @@ def pull(repo, source, heads=[], force=F ui.status('%s\n' % e.message) stupidmod.print_your_svn_is_old_message(ui) have_replay = False - except core.SubversionException, e: #pragma: no cover - if (e.apr_err == core.SVN_ERR_RA_DAV_REQUEST_FAILED + except svnwrap.SubversionException, e: #pragma: no cover + if (e.args[1] == svnwrap.ERR_RA_DAV_REQUEST_FAILED and '502' in str(e) and tries < 3): tries += 1