# HG changeset patch # User Dan Villiom Podlaski Christiansen # Date 1238112576 -3600 # Node ID 2117cb0118fe72f3aaa0da35bfe8598dda28fc1b # Parent 2165461d2dd8c1f4b95e8e02c49630f3b3b42f74 Get rid of .hg/svn/last_rev: We now calculate the last known revision by iterating over all known revisions and finding the highest number. Theoretically, we might be able to simply read the latest entry, but in practice, that's a bug waiting to happen. For instance, we might want to achieve compatibility with '.hg/shamap' as generated by the ConvertExtension, and it not only cannot offer a guarantee of linearity, but it also allows more than one conversion to source exists. I'd say we have other problems to care about until this turns up as a hotspot in profiling. Such as why we leak circa 100MB of memory per 1000 revisions converted ;) diff --git a/fetch_command.py b/fetch_command.py --- a/fetch_command.py +++ b/fetch_command.py @@ -55,11 +55,10 @@ def fetch_revisions(ui, svn_url, hg_repo if os.path.exists(hg_editor.uuid_file): uuid = open(hg_editor.uuid_file).read() assert uuid == svn.uuid - start = int(open(hg_editor.last_revision_handled_file, 'r').read()) + start = hg_editor.last_known_revision() else: open(hg_editor.uuid_file, 'w').write(svn.uuid) open(hg_editor.svn_url_file, 'w').write(svn_url) - open(hg_editor.last_revision_handled_file, 'w').write(str(0)) initializing_repo = True start = skipto_rev @@ -93,12 +92,6 @@ def fetch_revisions(ui, svn_url, hg_repo else: stupid_svn_server_pull_rev(ui, svn, hg_editor, r) converted = True - tmpfile = '%s_tmp' % hg_editor.last_revision_handled_file - fp = open(tmpfile, 'w') - fp.write(str(r.revnum)) - fp.close() - merc_util.rename(tmpfile, - hg_editor.last_revision_handled_file) except core.SubversionException, e: #pragma: no cover if e.apr_err == core.SVN_ERR_RA_DAV_REQUEST_FAILED: tries += 1 diff --git a/hg_delta_editor.py b/hg_delta_editor.py --- a/hg_delta_editor.py +++ b/hg_delta_editor.py @@ -59,6 +59,18 @@ class HgChangeReceiver(delta.Editor): f.close() self.revmap[revnum, branch] = node_hash + def last_known_revision(self): + ''' Obtain the highest numbered -- i.e. latest -- revision known. + + Currently, this function just iterates over the entire revision map + using the max() builtin. This may be slow for extremely large + repositories, but for now, it's fast enough. + ''' + try: + return max(k[0] for k in self.revmap.iterkeys()) + except ValueError: + return 0 + def __init__(self, path=None, repo=None, ui_=None, subdir='', author_host='', tag_locations=['tags'], @@ -131,7 +143,6 @@ class HgChangeReceiver(delta.Editor): assert os.path.isfile(self.revmap_file) assert os.path.isfile(self.svn_url_file) assert os.path.isfile(self.uuid_file) - assert os.path.isfile(self.last_revision_handled_file) else: self.repo = hg.repository(self.ui, repo_path, create=True) os.makedirs(os.path.dirname(self.uuid_file)) @@ -763,10 +774,6 @@ class HgChangeReceiver(delta.Editor): return self.meta_file_named('uuid') uuid_file = property(uuid_file) - def last_revision_handled_file(self): - return self.meta_file_named('last_rev') - last_revision_handled_file = property(last_revision_handled_file) - def branch_info_file(self): return self.meta_file_named('branch_info') branch_info_file = property(branch_info_file) diff --git a/rebuildmeta.py b/rebuildmeta.py --- a/rebuildmeta.py +++ b/rebuildmeta.py @@ -79,9 +79,6 @@ def rebuildmeta(ui, repo, hg_repo_path, if c.branch() == 'closed-branches': if branch in branchinfo: del branchinfo[branch] - lastrevfile = open(os.path.join(svnmetadir, 'last_rev'), 'w') - lastrevfile.write(str(last_rev)) - lastrevfile.close() branchinfofile = open(os.path.join(svnmetadir, 'branch_info'), 'w') pickle.dump(branchinfo, branchinfofile) branchinfofile.close() diff --git a/tests/test_rebuildmeta.py b/tests/test_rebuildmeta.py --- a/tests/test_rebuildmeta.py +++ b/tests/test_rebuildmeta.py @@ -22,8 +22,6 @@ def _do_case(self, name, stupid): args=[test_util.fileurl(self.repo_path + subdir), ]) dest = hg.repository(u, os.path.dirname(dest.path)) - self.assert_(open(os.path.join(src.path, 'svn', 'last_rev')).read() >= - open(os.path.join(dest.path, 'svn', 'last_rev')).read()) for tf in ('rev_map', 'uuid', 'url'): self.assertEqual(open(os.path.join(src.path, 'svn', tf)).read(), open(os.path.join(dest.path, 'svn', tf)).read())