diff options
author | Holger Freyther <zecke@selfish.org> | 2008-01-08 03:04:08 +0000 |
---|---|---|
committer | Holger Freyther <zecke@selfish.org> | 2008-01-08 03:04:08 +0000 |
commit | b785c51d79d2fc8e11f9ebe0e7f61cae6ad57323 (patch) | |
tree | 5f15d6f0c2286c16ab81766fe38671c9416672e7 /contrib | |
parent | d705f2e604fa72fde95417307feb01b24fa6920f (diff) |
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.
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/mtn2git/mtn2git.py | 24 |
1 files changed, 23 insertions, 1 deletions
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() |