[oe-commits] org.oe.dev contrib/mtn2git/mtn2git.py: Built a fifo to avoid parsing the manifests all over again

freyther commit openembedded-commits at lists.openembedded.org
Tue Jan 8 10:08:17 UTC 2008


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.

Author: freyther at openembedded.org
Branch: org.openembedded.dev
Revision: d6527bc02f6e5590c50e502688c29a7855e5153f
ViewMTN: http://monotone.openembedded.org/revision/info/d6527bc02f6e5590c50e502688c29a7855e5153f
Files:
1
contrib/mtn2git/mtn2git.py
Diffs:

#
# mt diff -rfa391525a71f0856e02abea3c8d3bd9ecb0800c6 -rd6527bc02f6e5590c50e502688c29a7855e5153f
#
# 
# 
# patch "contrib/mtn2git/mtn2git.py"
#  from [57aae7241136ce92c5751d23f2780f0ef7f41776]
#    to [f819d5be7ee1a3ebec96020f0297404080758e0b]
# 
============================================================
--- contrib/mtn2git/mtn2git.py	57aae7241136ce92c5751d23f2780f0ef7f41776
+++ contrib/mtn2git/mtn2git.py	f819d5be7ee1a3ebec96020f0297404080758e0b
@@ -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,7 +140,25 @@ 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()






More information about the Openembedded-commits mailing list