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/09/21 00:28:15 UTC

[2/2] git commit: [#6695] Added sanity check in LCD for loops in commit data

[#6695] Added sanity check in LCD for loops in commit data

Signed-off-by: Cory Johns <cj...@slashdotmedia.com>


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

Branch: refs/heads/cj/6695
Commit: f777236027fb3e7fde28a854c33d16373de59447
Parents: 98cf88d
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Fri Sep 20 22:27:25 2013 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Fri Sep 20 22:27:34 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/repository.py      |  4 ++++
 Allura/allura/tests/model/test_repo.py | 14 ++++++++++++++
 2 files changed, 18 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f7772360/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 32b9bf1..b371295 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -149,9 +149,13 @@ class RepositoryImplementation(object):
         start_time = time()
         paths = set(paths)
         result = {}
+        seen_commits = set()
         while paths and commit:
             if time() - start_time > timeout:
                 return result
+            if commit._id in seen_commits:
+                return result  # sanity check for bad data (loops)
+            seen_commits.add(commit._id)
             changed = paths & set(commit.changed_paths)
             result.update({path: commit._id for path in changed})
             paths = paths - changed

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f7772360/Allura/allura/tests/model/test_repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_repo.py b/Allura/allura/tests/model/test_repo.py
index b67be9f..ef39e4b 100644
--- a/Allura/allura/tests/model/test_repo.py
+++ b/Allura/allura/tests/model/test_repo.py
@@ -334,6 +334,20 @@ class TestLastCommit(unittest.TestCase):
         self.assertEqual(len(lcd.entries), 1)
         self.assertEqual(lcd.by_name['file2'], commit3._id)
 
+    def test_loop(self):
+        commit1 = self._add_commit('Commit 1', ['file1'])
+        commit2 = self._add_commit('Commit 2', ['file1', 'dir1/file1'], ['dir1/file1'], [commit1])
+        commit3 = self._add_commit('Commit 3', ['file1', 'dir1/file1', 'file2'], ['file2'], [commit2])
+        commit2.parent_ids = [commit3._id]
+        session(commit2).flush(commit2)
+        lcd = M.repo.LastCommit.get(commit3.tree)
+        self.assertEqual(self.repo._commits[lcd.commit_id].message, commit3.message)
+        self.assertEqual(lcd.commit_id, commit3._id)
+        self.assertEqual(lcd.path, '')
+        self.assertEqual(len(lcd.entries), 2)
+        self.assertEqual(lcd.by_name['dir1'], commit2._id)
+        self.assertEqual(lcd.by_name['file2'], commit3._id)
+
 
 class TestModelCache(unittest.TestCase):
     def setUp(self):