You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2013/02/05 21:23:35 UTC

[15/42] git commit: [#4691] Fail gracefully if objects don't exist

[#4691] Fail gracefully if objects don't exist


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

Branch: refs/heads/master
Commit: f95b09411c415b18cde1409075eec6c85a60b7ab
Parents: 9d48b05
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Fri Dec 7 16:19:40 2012 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Tue Feb 5 20:22:50 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/repo.py |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f95b0941/Allura/allura/model/repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo.py b/Allura/allura/model/repo.py
index 8eb23d9..85e44ad 100644
--- a/Allura/allura/model/repo.py
+++ b/Allura/allura/model/repo.py
@@ -209,6 +209,8 @@ class Commit(RepoObject):
         try:
             cache = getattr(c, 'model_cache', '') or ModelCache()
             ci = cache.get(Commit, dict(_id=self.parent_ids[index]))
+            if not ci:
+                return None
             ci.set_context(self.repo)
             return ci
         except IndexError as e:
@@ -366,13 +368,14 @@ class Commit(RepoObject):
         '''
         diff_info = DiffInfoDoc.m.get(_id=self._id)
         diffs = set()
-        for d in diff_info.differences:
-            diffs.add(d.name.strip('/'))
-            node_path = os.path.dirname(d.name)
-            while node_path:
-                diffs.add(node_path)
-                node_path = os.path.dirname(node_path)
-            diffs.add('')  # include '/' if there are any changes
+        if diff_info:
+            for d in diff_info.differences:
+                diffs.add(d.name.strip('/'))
+                node_path = os.path.dirname(d.name)
+                while node_path:
+                    diffs.add(node_path)
+                    node_path = os.path.dirname(node_path)
+                diffs.add('')  # include '/' if there are any changes
         return diffs
 
     @LazyProperty
@@ -481,6 +484,8 @@ class Tree(RepoObject):
             return old_style_results
         # finally, use the new implentation that auto-vivifies
         last_commit = LastCommit.get(self)
+        if not last_commit:
+            return []
         sorted_entries = sorted(last_commit.entries, cmp=lambda a,b: cmp(b.type,a.type) or cmp(a.name,b.name))
         mapped_entries = [self._dirent_map(e) for e in sorted_entries]
         return mapped_entries