# HG changeset patch # User Dan Villiom Podlaski Christiansen # Date 1289586140 -3600 # Node ID e1e2af66953d72307eb49c6b2acae13316944efe # Parent 34b25f6bc4ef58f3991ced438c2369b50c6a7223 svnmeta: store subdir in a file, and verify it when loading. diff --git a/hgsubversion/svncommands.py b/hgsubversion/svncommands.py --- a/hgsubversion/svncommands.py +++ b/hgsubversion/svncommands.py @@ -113,6 +113,10 @@ def rebuildmeta(ui, repo, args, **opts): numrevs = len(repo) + subdirfile = open(os.path.join(svnmetadir, 'subdir'), 'w') + subdirfile.write(subdir.strip('/')) + subdirfile.close() + # ctx.children() visits all revisions in the repository after ctx. Calling # it would make us use O(revisions^2) time, so we perform an extra traversal # of the repository instead. During this traversal, we find all converted diff --git a/hgsubversion/svnmeta.py b/hgsubversion/svnmeta.py --- a/hgsubversion/svnmeta.py +++ b/hgsubversion/svnmeta.py @@ -32,7 +32,7 @@ def pickle_atomic(data, file_path, dir=N class SVNMeta(object): - def __init__(self, repo, uuid=None, subdir=''): + def __init__(self, repo, uuid=None, subdir=None): """path is the path to the target hg repo. subdir is the subdirectory of the edits *on the svn server*. @@ -45,7 +45,7 @@ class SVNMeta(object): if not os.path.isdir(self.meta_data_dir): os.makedirs(self.meta_data_dir) self.uuid = uuid - # TODO: validate subdir too + self.subdir = subdir self.revmap = maps.RevMap(repo) author_host = self.ui.config('hgsubversion', 'defaulthost', uuid) @@ -56,12 +56,6 @@ class SVNMeta(object): branchmap = self.ui.config('hgsubversion', 'branchmap') tagmap = self.ui.config('hgsubversion', 'tagmap') - # FIXME: test that this hasn't changed! defer & compare? - if subdir: - # strip leading and trailing slashes - # collapse all repeated slashes to a single one - subdir = '/'.join(p for p in subdir.split('/') if p) - self.subdir = subdir self.branches = {} if os.path.exists(self.branch_info_file): f = open(self.branch_info_file) @@ -126,6 +120,38 @@ class SVNMeta(object): self._editor = editor.HgEditor(self) return self._editor + def _get_subdir(self): + return self.__subdir + + def _set_subdir(self, subdir): + if subdir: + subdir = '/'.join(p for p in subdir.split('/') if p) + + subdirfile = os.path.join(self.meta_data_dir, 'subdir') + + if os.path.isfile(subdirfile): + stored_subdir = open(subdirfile).read() + assert stored_subdir is not None + if subdir is None: + self.__subdir = stored_subdir + elif subdir != stored_subdir: + raise hgutil.Abort('unable to work on a different path in the ' + 'repository') + else: + self.__subdir = subdir + elif subdir is not None: + f = open(subdirfile, 'w') + f.write(subdir) + f.close() + self.__subdir = subdir + else: + raise hgutil.Abort("hgsubversion metadata unavailable; " + "please run 'hg svn rebuildmeta'") + + subdir = property(_get_subdir, _set_subdir, None, + 'Error-checked sub-directory of source Subversion ' + 'repository.') + def _get_uuid(self): return self.__uuid diff --git a/hgsubversion/svnrepo.py b/hgsubversion/svnrepo.py --- a/hgsubversion/svnrepo.py +++ b/hgsubversion/svnrepo.py @@ -66,7 +66,7 @@ def generate_repo_class(ui, repo): def findoutgoing(self, remote, base=None, heads=None, force=False): return wrappers.outgoing(repo, remote, heads, force) - def svnmeta(self, uuid=None, subdir=''): + def svnmeta(self, uuid=None, subdir=None): return svnmeta.SVNMeta(self, uuid, subdir) repo.__class__ = svnlocalrepo diff --git a/hgsubversion/wrappers.py b/hgsubversion/wrappers.py --- a/hgsubversion/wrappers.py +++ b/hgsubversion/wrappers.py @@ -127,7 +127,7 @@ def push(repo, dest, force, revs): # TODO: do credentials specified in the URL still work? svnurl = repo.ui.expandpath(dest.svnurl) svn = dest.svn - meta = repo.svnmeta(svn.uuid) + meta = repo.svnmeta(svn.uuid, svn.subdir) # Strategy: # 1. Find all outgoing commits from this head diff --git a/tests/test_rebuildmeta.py b/tests/test_rebuildmeta.py --- a/tests/test_rebuildmeta.py +++ b/tests/test_rebuildmeta.py @@ -44,7 +44,7 @@ def _do_case(self, name, stupid, single) self.assertTrue(os.path.isdir(os.path.join(src.path, 'svn')), 'no .hg/svn directory in the destination!') dest = hg.repository(u, os.path.dirname(dest.path)) - for tf in ('rev_map', 'uuid', 'tagmap', 'layout', ): + for tf in ('rev_map', 'uuid', 'tagmap', 'layout', 'subdir', ): stf = os.path.join(src.path, 'svn', tf) self.assertTrue(os.path.isfile(stf), '%r is missing!' % stf) dtf = os.path.join(dest.path, 'svn', tf)