incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [1/2] git commit: [#4691] Work-around for old, incorrectly computed DiffInfoDocs
Date Wed, 06 Feb 2013 17:26:12 GMT
[#4691] Work-around for old, incorrectly computed DiffInfoDocs

Signed-off-by: Cory Johns <johnsca@geek.net>


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

Branch: refs/heads/cj/4691
Commit: 0a93358e93aaf8d2204bfc1f26a0b4c41a11b9e1
Parents: a7ba577
Author: Cory Johns <johnsca@geek.net>
Authored: Wed Feb 6 16:06:46 2013 +0000
Committer: Cory Johns <johnsca@geek.net>
Committed: Wed Feb 6 17:24:46 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/repo.py                      |    7 +++++++
 Allura/allura/model/repository.py                |   12 ++++++++++++
 Allura/allura/tests/model/test_repo.py           |   13 +++++++++++++
 ForgeGit/forgegit/model/git_repo.py              |   14 +++++++++++++-
 ForgeGit/forgegit/tests/model/test_repository.py |   10 ++++++++++
 5 files changed, 55 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/0a93358e/Allura/allura/model/repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo.py b/Allura/allura/model/repo.py
index c97f408..3c48e5e 100644
--- a/Allura/allura/model/repo.py
+++ b/Allura/allura/model/repo.py
@@ -347,6 +347,13 @@ class Commit(RepoObject):
                 cur = cur[part]
         return cur
 
+    def has_path(self, path):
+        try:
+            self.get_path(path)
+            return True
+        except KeyError:
+            return False
+
     @LazyProperty
     def changed_paths(self):
         '''

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/0a93358e/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index fbdb14d..05dc771 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -123,6 +123,18 @@ class RepositoryImplementation(object):
             changed = paths & set(commit.changed_paths)
             result.update({path: commit._id for path in changed})
             paths = paths - changed
+
+            # Hacky work-around for DiffInfoDocs previously having been
+            # computed wrong (not including children of added trees).
+            # Can be removed once all projects have had diffs / LCDs refreshed.
+            parent = commit.get_parent()
+            if parent:
+                changed = set([path for path in paths if not parent.has_path(path)])
+                result.update({path: commit._id for path in changed})
+                paths = paths - changed
+            else:
+                result.update({path: commit._id for path in paths})
+
             commit = commit.get_parent()
         return result
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/0a93358e/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 6ce0364..81637a0 100644
--- a/Allura/allura/tests/model/test_repo.py
+++ b/Allura/allura/tests/model/test_repo.py
@@ -284,6 +284,19 @@ class TestLastCommit(unittest.TestCase):
         self.assertEqual(lcd.by_name['file3'], commit3._id)
         self.assertEqual(lcd.by_name['file4'], commit4._id)
 
+    def test_missing_add_record(self):
+        commit1 = self._add_commit('Commit 1', ['file1'])
+        commit2 = self._add_commit('Commit 2', ['file2'])
+        commit2.changed_paths = []
+        result = self.repo.last_commit_ids(commit2, ['file2'])
+        assert_equal(result, {'file2': commit2._id})
+
+    def test_missing_add_record_first_commit(self):
+        commit1 = self._add_commit('Commit 1', ['file1'])
+        commit1.changed_paths = []
+        result = self.repo.last_commit_ids(commit1, ['file1'])
+        assert_equal(result, {'file1': commit1._id})
+
 
 class TestModelCache(unittest.TestCase):
     def setUp(self):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/0a93358e/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 3b20706..67a1906 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -243,10 +243,22 @@ class GitImplementation(M.RepositoryImplementation):
             rev = 'HEAD'
         start = skip or 0
         stop = start + limit if limit is not None else None
+
+        def _pred(c):
+            '''
+            Work-around for potentially b0rked changed_paths.
+            This could be replaced with lambda c: path in c.changed_paths
+            once all projects have had their DiffInfoDocs refreshed.'''
+            if path in c.changed_paths:
+                return True
+            parent = c.get_parent()
+            if c.has_path(path) and not (parent and parent.has_path(path)):
+                return True  # added in this commit, inspite of changed_paths
+            return False
         predicate = None
         if path is not None:
             path = path.strip('/')
-            predicate = lambda c: path in c.changed_paths
+            predicate = _pred
 
         iter_tree = self.commit(rev).climb_commit_tree(predicate)
         for commit in itertools.islice(iter_tree, start, stop):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/0a93358e/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index 75ff504..b1a16f5 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -283,6 +283,16 @@ class TestGitCommit(unittest.TestCase):
         assert commits == ['6a45885ae7347f1cac5103b0050cc1be6a1496c8']
         commits = list(self.repo.commits('not/exist/'))
         assert commits == []
+        # with missing add record
+        commit = M.repo.Commit.query.get(_id='df30427c488aeab84b2352bdf88a3b19223f9d7a')
+        commit.changed_paths = []
+        commits = list(self.repo.commits('README', 'df30427c488aeab84b2352bdf88a3b19223f9d7a'))
+        assert_equal(commits, ['df30427c488aeab84b2352bdf88a3b19223f9d7a'])
+        # with missing add record & no parent
+        commit = M.repo.Commit.query.get(_id='9a7df788cf800241e3bb5a849c8870f2f8259d98')
+        commit.changed_paths = ['a']
+        commits = list(self.repo.commits('a/b/c/hello.txt', '9a7df788cf800241e3bb5a849c8870f2f8259d98'))
+        assert_equal(commits, ['9a7df788cf800241e3bb5a849c8870f2f8259d98'])
 
     def test_commits_count(self):
         commits = self.repo.commits_count()


Mime
View raw message