Return-Path: X-Original-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 27DC2EAC7 for ; Thu, 10 Jan 2013 18:08:22 +0000 (UTC) Received: (qmail 43486 invoked by uid 500); 10 Jan 2013 18:08:22 -0000 Delivered-To: apmail-incubator-allura-commits-archive@incubator.apache.org Received: (qmail 43424 invoked by uid 500); 10 Jan 2013 18:08:22 -0000 Mailing-List: contact allura-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: allura-dev@incubator.apache.org Delivered-To: mailing list allura-commits@incubator.apache.org Received: (qmail 43194 invoked by uid 99); 10 Jan 2013 18:08:21 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Jan 2013 18:08:21 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 5459617768; Thu, 10 Jan 2013 18:08:21 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: johnsca@apache.org To: allura-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [38/50] git commit: [#4691] Refactored compute_lcds to be easier to follow / trace Message-Id: <20130110180821.5459617768@tyr.zones.apache.org> Date: Thu, 10 Jan 2013 18:08:21 +0000 (UTC) [#4691] Refactored compute_lcds to be easier to follow / trace Signed-off-by: Cory Johns 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 Authored: Tue Dec 11 19:01:42 2012 +0000 Committer: Cory Johns 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)