Mercurial > hgsubversion
changeset 405:a98b8d424221
editor: simplify HgChangeReceiver constructor signature
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Wed, 10 Jun 2009 13:32:10 +0200 |
parents | 28e4b47b2179 |
children | e360558ba65f |
files | hgsubversion/hg_delta_editor.py hgsubversion/utility_commands.py hgsubversion/wrappers.py tests/test_rebuildmeta.py |
diffstat | 4 files changed, 35 insertions(+), 67 deletions(-) [+] |
line wrap: on
line diff
--- a/hgsubversion/hg_delta_editor.py +++ b/hgsubversion/hg_delta_editor.py @@ -85,30 +85,34 @@ class HgChangeReceiver(delta.Editor): except ValueError: return 0 - def __init__(self, repo=None, path=None, ui_=None, - subdir='', author_host='', - tag_locations=[], - authors=None, filemap=None, uuid=None): + def __init__(self, repo, uuid=None, subdir=''): """path is the path to the target hg repo. subdir is the subdirectory of the edits *on the svn server*. It is needed for stripping paths off in certain cases. """ - if repo and repo.ui and not ui_: - ui_ = repo.ui - if not ui_: - ui_ = ui.ui() - self.ui = ui_ - self.__setup_repo(uuid, repo, path, subdir) - - if not author_host: - author_host = self.ui.config('hgsubversion', 'defaulthost', uuid) - if not authors: - authors = self.ui.config('hgsubversion', 'authormap') - if not filemap: - filemap = self.ui.config('hgsubversion', 'filemap') - if not tag_locations: - tag_locations = self.ui.configlist('hgsubversion', 'tagpaths', ['tags']) + self.ui = repo.ui + self.repo = repo + self.path = os.path.normpath(repo.join('..')) + + if not os.path.isdir(self.meta_data_dir): + os.makedirs(self.meta_data_dir) + self._set_uuid(uuid) + # TODO: validate subdir too + + if os.path.isfile(self.revmap_file): + self.revmap = util.parse_revmap(self.revmap_file) + else: + self.revmap = {} + f = open(self.revmap_file, 'w') + f.write('%s\n' % util.REVMAP_FILE_VERSION) + f.flush() + f.close() + + author_host = self.ui.config('hgsubversion', 'defaulthost', uuid) + authors = self.ui.config('hgsubversion', 'authormap') + filemap = self.ui.config('hgsubversion', 'filemap') + tag_locations = self.ui.configlist('hgsubversion', 'tagpaths', ['tags']) self.usebranchnames = self.ui.configbool('hgsubversion', 'usebranchnames', True) @@ -154,37 +158,6 @@ class HgChangeReceiver(delta.Editor): date = self.lastdate return date - def __setup_repo(self, uuid, repo, path, subdir): - """Verify the repo is going to work out for us. - - This method will fail an assertion if the repo exists but doesn't have - the Subversion metadata. - """ - if repo: - self.repo = repo - self.path = os.path.normpath(self.repo.join('..')) - elif path: - self.repo = hg.repository(self.ui, path, - create=(not os.path.exists(path))) - self.path = os.path.normpath(os.path.join(path, '..')) - else: #pragma: no cover - raise TypeError("editor requires either a path or a repository " - "specified") - - if not os.path.isdir(self.meta_data_dir): - os.makedirs(self.meta_data_dir) - self._set_uuid(uuid) - # TODO: validate subdir too - - if os.path.isfile(self.revmap_file): - self.revmap = util.parse_revmap(self.revmap_file) - else: - self.revmap = {} - f = open(self.revmap_file, 'w') - f.write('%s\n' % util.REVMAP_FILE_VERSION) - f.flush() - f.close() - def clear_current_info(self): '''Clear the info relevant to a replayed revision so that the next revision can be replayed.
--- a/hgsubversion/utility_commands.py +++ b/hgsubversion/utility_commands.py @@ -18,8 +18,7 @@ def genignore(ui, repo, hg_repo_path, fo url = util.normalize_url(repo.ui.config('paths', 'default')) user, passwd = util.getuserpass(opts) svn = svnwrap.SubversionRepo(url, user, passwd) - hge = hg_delta_editor.HgChangeReceiver(path=hg_repo_path, repo=repo, - ui_=ui, uuid=svn.uuid) + hge = hg_delta_editor.HgChangeReceiver(repo, svn.uuid) svn_commit_hashes = dict(zip(hge.revmap.itervalues(), hge.revmap.iterkeys())) parent = cmdutil.parentrev(ui, repo, hge, svn_commit_hashes) @@ -48,8 +47,7 @@ def info(ui, repo, hg_repo_path, **opts) url = util.normalize_url(repo.ui.config('paths', 'default')) user, passwd = util.getuserpass(opts) svn = svnwrap.SubversionRepo(url, user, passwd) - hge = hg_delta_editor.HgChangeReceiver(path=hg_repo_path, repo=repo, - ui_=ui, uuid=svn.uuid) + hge = hg_delta_editor.HgChangeReceiver(repo, svn.uuid) svn_commit_hashes = dict(zip(hge.revmap.itervalues(), hge.revmap.iterkeys())) parent = cmdutil.parentrev(ui, repo, hge, svn_commit_hashes)
--- a/hgsubversion/wrappers.py +++ b/hgsubversion/wrappers.py @@ -36,7 +36,7 @@ def parents(orig, ui, repo, *args, **opt """ if not opts.get('svn', False): return orig(ui, repo, *args, **opts) - hge = hg_delta_editor.HgChangeReceiver(repo=repo) + hge = hg_delta_editor.HgChangeReceiver(repo) svn_commit_hashes = dict(zip(hge.revmap.itervalues(), hge.revmap.iterkeys())) ha = cmdutil.parentrev(ui, repo, hge, svn_commit_hashes) @@ -58,7 +58,7 @@ def incoming(orig, ui, repo, source='def user, passwd = util.getuserpass(opts) svn = svnwrap.SubversionRepo(other.svnurl, user, passwd) - hg_editor = hg_delta_editor.HgChangeReceiver(repo=repo) + hg_editor = hg_delta_editor.HgChangeReceiver(repo) start = hg_editor.last_known_revision() ui.status('incoming changes from %s\n' % other.svnurl) @@ -79,7 +79,7 @@ def outgoing(repo, dest=None, heads=None # split off #rev; TODO implement --revision/#rev support svnurl, revs, checkout = hg.parseurl(dest.svnurl, heads) - hge = hg_delta_editor.HgChangeReceiver(repo=repo) + hge = hg_delta_editor.HgChangeReceiver(repo) svn_commit_hashes = dict(zip(hge.revmap.itervalues(), hge.revmap.iterkeys())) return util.outgoing_revisions(repo.ui, repo, hge, svn_commit_hashes, @@ -92,7 +92,7 @@ def diff(orig, ui, repo, *args, **opts): if not opts.get('svn', False) or opts.get('change', None): return orig(ui, repo, *args, **opts) svn_commit_hashes = {} - hge = hg_delta_editor.HgChangeReceiver(repo=repo) + hge = hg_delta_editor.HgChangeReceiver(repo) svn_commit_hashes = dict(zip(hge.revmap.itervalues(), hge.revmap.iterkeys())) if not opts.get('rev', None): @@ -129,7 +129,7 @@ def push(repo, dest, force, revs): user = repo.ui.config('hgsubversion', 'username') passwd = repo.ui.config('hgsubversion', 'password') svn = svnwrap.SubversionRepo(svnurl, user, passwd) - hge = hg_delta_editor.HgChangeReceiver(repo=repo, uuid=svn.uuid) + hge = hg_delta_editor.HgChangeReceiver(repo, svn.uuid) # Strategy: # 1. Find all outgoing commits from this head @@ -203,7 +203,7 @@ def push(repo, dest, force, revs): child = children[0] rebasesrc = node.bin(child.extra().get('rebase_source', node.hex(node.nullid))) # TODO: stop constantly creating the HgChangeReceiver instances. - hge = hg_delta_editor.HgChangeReceiver(hge.repo, ui_=ui, uuid=svn.uuid) + hge = hg_delta_editor.HgChangeReceiver(hge.repo, svn.uuid) svn_commit_hashes = dict(zip(hge.revmap.itervalues(), hge.revmap.iterkeys())) util.swap_out_encoding(old_encoding) return 0 @@ -242,8 +242,7 @@ def pull(repo, source, heads=[], force=F user = repo.ui.config('hgsubversion', 'username') passwd = repo.ui.config('hgsubversion', 'password') svn = svnwrap.SubversionRepo(svn_url, user, passwd) - hg_editor = hg_delta_editor.HgChangeReceiver(repo=repo, subdir=svn.subdir, - uuid=svn.uuid) + hg_editor = hg_delta_editor.HgChangeReceiver(repo, svn.uuid, svn.subdir) start = max(hg_editor.last_known_revision(), skipto_rev) initializing_repo = (hg_editor.last_known_revision() <= 0) @@ -312,7 +311,7 @@ def rebase(orig, ui, repo, **opts): extra['branch'] = ctx.branch() extrafn = opts.get('svnextrafn', extrafn2) sourcerev = opts.get('svnsourcerev', repo.parents()[0].node()) - hge = hg_delta_editor.HgChangeReceiver(repo=repo) + hge = hg_delta_editor.HgChangeReceiver(repo) svn_commit_hashes = dict(zip(hge.revmap.itervalues(), hge.revmap.iterkeys())) o_r = util.outgoing_revisions(ui, repo, hge, svn_commit_hashes, sourcerev=sourcerev)
--- a/tests/test_rebuildmeta.py +++ b/tests/test_rebuildmeta.py @@ -38,18 +38,16 @@ def _do_case(self, name, stupid): srcbi = pickle.load(open(os.path.join(src.path, 'svn', 'branch_info'))) destbi = pickle.load(open(os.path.join(dest.path, 'svn', 'branch_info'))) self.assertEqual(sorted(srcbi.keys()), sorted(destbi.keys())) + revkeys = hg_delta_editor.HgChangeReceiver(dest).revmap.keys() for branch in destbi: srcinfo = srcbi[branch] destinfo = destbi[branch] - hge = hg_delta_editor.HgChangeReceiver(path=os.path.dirname(dest.path), - repo=dest, - ui_=u) if destinfo[:2] == (None, 0): self.assert_(srcinfo[2] <= destinfo[2]) self.assertEqual(srcinfo[0], destinfo[0]) else: pr = sorted(filter(lambda x: x[1] == srcinfo[0] and x[0] <= srcinfo[1], - hge.revmap.keys()), reverse=True)[0][0] + revkeys), reverse=True)[0][0] self.assertEqual(pr, destinfo[1]) self.assertEqual(srcinfo[2], destinfo[2])