# HG changeset patch # User Dan Villiom Podlaski Christiansen # Date 1238112576 -3600 # Node ID 9be04de434ed3ee0a18c95143e27eb44dbf8a2dd # Parent aacc8cf83e138259d1aca7226a16303783f8ca48 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'], @@ -134,7 +146,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)) @@ -766,10 +777,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)