incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [38/50] git commit: [#4691] Refactored compute_lcds to be easier to follow / trace
Date Thu, 10 Jan 2013 18:08:21 GMT
[#4691] Refactored compute_lcds to be easier to follow / trace

Signed-off-by: Cory Johns <johnsca@geek.net>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/17fac266
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/17fac266
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/17fac266

Branch: refs/heads/cj/4691
Commit: 17fac2667f26baa59e8da5060613898ae5598dd7
Parents: e95a167
Author: Cory Johns <johnsca@geek.net>
Authored: Tue Dec 11 19:01:42 2012 +0000
Committer: Cory Johns <johnsca@geek.net>
Committed: Thu Jan 10 16:27:20 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/repo_refresh.py |   58 ++++++++++++++----------------
 1 files changed, 27 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/17fac266/Allura/allura/model/repo_refresh.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo_refresh.py b/Allura/allura/model/repo_refresh.py
index 34e55cb..4b6a5a4 100644
--- a/Allura/allura/model/repo_refresh.py
+++ b/Allura/allura/model/repo_refresh.py
@@ -497,38 +497,34 @@ def compute_lcds(commit, cache):
     if not trees:
         log.error('Missing TreesDoc for %s; skipping compute_lcd' % commit)
         return
-    _update_tree_cache(trees.tree_ids, cache)
     c.model_cache = cache
-    for tree in _walk_commit_tree(commit, cache):
-        lcd = LastCommit.get(tree)  # auto-vivify LCD
-
-def _walk_commit_tree(commit, cache):
-    def _clone_tree(tree):
-        '''
-        Since the Tree instances stick around in our cache,
-        subsequent calls to set_context are overwriting our
-        in-use copies and confusing the walk.  So, make an
-        memory-only copy for our use.
-        '''
-        new_tree = Tree(
-                _id=tree._id,
-                tree_ids=tree.tree_ids,
-                blob_ids=tree.blob_ids,
-                other_ids=tree.other_ids,
-            )
-        session(new_tree).expunge(new_tree)
-        return new_tree
-
-    def _walk_tree(tree):
-        yield tree
-        for x in tree.tree_ids:
-            sub_tree = _clone_tree(cache.get(Tree, dict(_id=x.id)))
-            sub_tree.set_context(tree, x.name)
-            for xx in _walk_tree(sub_tree):
-                yield xx
-    top_tree = _clone_tree(cache.get(Tree, dict(_id=commit.tree_id)))
-    top_tree.set_context(commit)
-    return _walk_tree(top_tree)
+    _update_tree_cache(trees.tree_ids, cache)
+    tree = _pull_tree(cache, commit.tree_id, commit)
+    _compute_lcds(tree, cache)
+
+def _compute_lcds(tree, cache):
+    lcd = LastCommit.get(tree)  # auto-vivify LCD
+    for x in tree.tree_ids:
+        sub_tree = _pull_tree(cache, x.id, tree, x.name)
+        _compute_lcds(sub_tree, cache)
+
+def _pull_tree(cache, tree_id, *context):
+    '''
+    Since the Tree instances stick around in our cache,
+    subsequent calls to set_context are overwriting our
+    in-use copies and confusing the walk.  So, make an
+    memory-only copy for our use.
+    '''
+    cache_tree = cache.get(Tree, dict(_id=tree_id))
+    new_tree = Tree(
+            _id=cache_tree._id,
+            tree_ids=cache_tree.tree_ids,
+            blob_ids=cache_tree.blob_ids,
+            other_ids=cache_tree.other_ids,
+        )
+    session(new_tree).expunge(new_tree)
+    new_tree.set_context(*context)
+    return new_tree
 
 def _update_tree_cache(tree_ids, cache):
     current_ids = set(tree_ids)


Mime
View raw message