From b785c51d79d2fc8e11f9ebe0e7f61cae6ad57323 Mon Sep 17 00:00:00 2001 From: Holger Freyther Date: Tue, 8 Jan 2008 03:04:08 +0000 Subject: contrib/mtn2git/mtn2git.py: Built a fifo to avoid parsing the manifests all over again I decided to use a FIFO for two reasons: -Simplicity in the implementation -Parent and Childs are normally close (<= 100 revisions) to each other. So having the fifo should avoid parsing the parent manifest over and over again. Also with "merge early and merge often" the 100 revs should be enough to catch merges as well. --- contrib/mtn2git/mtn2git.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/contrib/mtn2git/mtn2git.py b/contrib/mtn2git/mtn2git.py index 859b86fb11..f6f488ccc5 100755 --- a/contrib/mtn2git/mtn2git.py +++ b/contrib/mtn2git/mtn2git.py @@ -44,6 +44,10 @@ import status # # +# Our manifest/tree fifo construct +cached_tree = {} +cached_fifo = [] + def get_mark(revision): """ Get a mark for a specific revision. If the revision is known the former @@ -136,6 +140,24 @@ def build_tree(manifest, rev): return tree +def get_and_cache_tree(ops, revision): + """Simple FIFO to cache a number of trees""" + global cached_tree, cached_fifo + + if revision in cached_tree: + return cached_tree[revision] + + tree = build_tree([line for line in ops.get_manifest_of(revision)], revision) + cached_tree[revision] = tree + cached_fifo.append(revision) + + # Shrink + if len(cached_fifo) > 100: + old_name = cached_fifo[0] + cached_fifo = cached_fifo[1:] + del cached_tree[old_name] + + def fast_import(ops, revision): """Import a revision into git using git-fast-import. @@ -172,7 +194,7 @@ def fast_import(ops, revision): return # Use the manifest to find dirs and files - current_tree = build_tree([line for line in ops.get_manifest_of(revision["revision"])], revision["revision"]) + current_tree = get_and_cache_tree(ops, revision["revision"]) all_added = set() all_modifications = set() -- cgit v1.2.3