You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/01/23 00:23:18 UTC

[28/50] 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/ca9243ac
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/ca9243ac
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/ca9243ac

Branch: refs/heads/cj/4691
Commit: ca9243acf582fea018acce24c5b7d4cdf0179b1b
Parents: 0ebe944
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Fri Dec 7 16:19:40 2012 +0000
Committer: Cory Johns <jo...@geek.net>
Committed: Tue Jan 22 23:22:43 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/ca9243ac/Allura/allura/model/repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo.py b/Allura/allura/model/repo.py
index 11e78b7..9e7eb44 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