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 959BDD33F for ; Wed, 14 Nov 2012 17:51:32 +0000 (UTC) Received: (qmail 94379 invoked by uid 500); 14 Nov 2012 17:51:32 -0000 Delivered-To: apmail-incubator-allura-commits-archive@incubator.apache.org Received: (qmail 94362 invoked by uid 500); 14 Nov 2012 17:51:32 -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 94348 invoked by uid 99); 14 Nov 2012 17:51:32 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Nov 2012 17:51:32 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id F17CB313389; Wed, 14 Nov 2012 17:51:31 +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: git commit: [#5171] Changes to SVN TreeDoc creation to prevent empty TreeDoc nodes Message-Id: <20121114175131.F17CB313389@tyr.zones.apache.org> Date: Wed, 14 Nov 2012 17:51:31 +0000 (UTC) Updated Branches: refs/heads/cj/5171 [created] aba1e840d [#5171] Changes to SVN TreeDoc creation to prevent empty TreeDoc nodes 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/aba1e840 Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/aba1e840 Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/aba1e840 Branch: refs/heads/cj/5171 Commit: aba1e840d24333c4b419619c569a258ebe54eb0b Parents: 9375a14 Author: Cory Johns Authored: Wed Nov 14 15:21:06 2012 +0000 Committer: Cory Johns Committed: Wed Nov 14 15:21:06 2012 +0000 ---------------------------------------------------------------------- Allura/allura/model/repo.py | 4 ++-- ForgeSVN/forgesvn/model/svn.py | 33 ++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/aba1e840/Allura/allura/model/repo.py ---------------------------------------------------------------------- diff --git a/Allura/allura/model/repo.py b/Allura/allura/model/repo.py index b82610c..b46f3fa 100644 --- a/Allura/allura/model/repo.py +++ b/Allura/allura/model/repo.py @@ -123,12 +123,12 @@ class RepoObject(object): return id.replace('.', '/') @classmethod - def upsert(cls, id): + def upsert(cls, id, **kwargs): isnew = False r = cls.query.get(_id=id) if r is not None: return r, isnew try: - r = cls(_id=id) + r = cls(_id=id, **kwargs) session(r).flush(r) isnew = True except pymongo.errors.DuplicateKeyError: # pragma no cover http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/aba1e840/ForgeSVN/forgesvn/model/svn.py ---------------------------------------------------------------------- diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py index eca7229..2bf6b14 100644 --- a/ForgeSVN/forgesvn/model/svn.py +++ b/ForgeSVN/forgesvn/model/svn.py @@ -333,8 +333,9 @@ class SVNImplementation(M.RepositoryImplementation): from allura.model import repo as RM tree_path = tree_path[:-1] tree_id = self._tree_oid(commit._id, tree_path) - tree, isnew = RM.Tree.upsert(tree_id) - if not isnew: return tree_id + tree = RM.Tree.query.get(_id=tree_id) + if tree: + return tree_id log.debug('Computing tree for %s: %s', self._revno(commit._id), tree_path) rev = self._revision(commit._id) @@ -346,9 +347,10 @@ class SVNImplementation(M.RepositoryImplementation): except pysvn.ClientError: log.exception('Error computing tree for %s: %s(%s)', self._repo, commit, tree_path) - tree.delete() return None log.debug('Compute tree for %d paths', len(infos)) + tree_ids = [] + blob_ids = [] for path, info in infos[1:]: last_commit_id = self._oid(info['last_changed_rev'].number) last_commit = M.repo.Commit.query.get(_id=last_commit_id) @@ -359,23 +361,28 @@ class SVNImplementation(M.RepositoryImplementation): self._tree_oid(commit._id, path), M.repo_refresh.get_commit_info(last_commit)) if info.kind == pysvn.node_kind.dir: - tree.tree_ids.append(Object( + tree_ids.append(Object( id=self._tree_oid(commit._id, path), name=path)) elif info.kind == pysvn.node_kind.file: - tree.blob_ids.append(Object( + blob_ids.append(Object( id=self._tree_oid(commit._id, path), name=path)) else: assert False - session(tree).flush(tree) - trees_doc = RM.TreesDoc.m.get(_id=commit._id) - if not trees_doc: - trees_doc = RM.TreesDoc(dict( - _id=commit._id, - tree_ids=[])) - trees_doc.tree_ids.append(tree_id) - trees_doc.m.save(safe=False) + tree, is_new = RM.Tree.upsert(tree_id, + tree_ids=tree_ids, + blob_ids=blob_ids, + other_ids=[], + ) + if is_new: + trees_doc = RM.TreesDoc.m.get(_id=commit._id) + if not trees_doc: + trees_doc = RM.TreesDoc(dict( + _id=commit._id, + tree_ids=[])) + trees_doc.tree_ids.append(tree_id) + trees_doc.m.save(safe=False) return tree_id def _tree_oid(self, commit_id, path):