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/18 22:01:58 UTC
git commit: [#5783] Only compute diffs for current page
Updated Branches:
refs/heads/tv/5783 [created] 2c5550519
[#5783] Only compute diffs for current page
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/2c555051
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/2c555051
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/2c555051
Branch: refs/heads/tv/5783
Commit: 2c5550519a811bdadb0c74f683a40cf27bbfdc14
Parents: 0435184
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Mon Feb 18 15:58:22 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Mon Feb 18 21:00:58 2013 +0000
----------------------------------------------------------------------
Allura/allura/controllers/repository.py | 6 ++--
Allura/allura/model/repo.py | 8 +++++-
ForgeSVN/forgesvn/tests/model/test_repository.py | 19 ++++++++++++----
3 files changed, 23 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2c555051/Allura/allura/controllers/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index 40a9bc3..14a523c 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -407,12 +407,12 @@ class CommitBrowser(BaseController):
tree = self._commit.tree
limit, page, start = g.handle_paging(limit, page,
default=self.DEFAULT_PAGE_LIMIT)
+ diffs = self._commit.paged_diffs(start=start, end=start+limit)
result['artifacts'] = [
(t,f) for t in ('added', 'removed', 'changed', 'copied')
- for f in self._commit.diffs[t]
+ for f in diffs[t]
if t == 'removed' or tree.get_blob_by_path(f)]
- count = len(result['artifacts'])
- result['artifacts'] = result['artifacts'][start:start+limit]
+ count = diffs['total']
result.update(dict(page=page, limit=limit, count=count))
return result
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2c555051/Allura/allura/model/repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo.py b/Allura/allura/model/repo.py
index 569cbb3..568e7f8 100644
--- a/Allura/allura/model/repo.py
+++ b/Allura/allura/model/repo.py
@@ -263,6 +263,9 @@ class Commit(RepoObject):
@LazyProperty
def diffs(self):
+ return self.paged_diffs()
+
+ def paged_diffs(self, start=0, end=None):
di = DiffInfoDoc.m.get(_id=self._id)
if di is None:
return Object(added=[], removed=[], changed=[], copied=[])
@@ -270,7 +273,7 @@ class Commit(RepoObject):
removed = []
changed = []
copied = []
- for change in di.differences:
+ for change in di.differences[start:end]:
if change.rhs_id is None:
removed.append(change.name)
elif change.lhs_id is None:
@@ -280,7 +283,8 @@ class Commit(RepoObject):
copied = self._diffs_copied(added, removed)
return Object(
added=added, removed=removed,
- changed=changed, copied=copied)
+ changed=changed, copied=copied,
+ total=len(di.differences))
def _diffs_copied(self, added, removed):
'''Return list with file renames diffs.
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2c555051/ForgeSVN/forgesvn/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/model/test_repository.py b/ForgeSVN/forgesvn/tests/model/test_repository.py
index 9006271..f3ac7bc 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -208,12 +208,21 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
print entry.message
print entry.diffs
+ def test_paged_diffs(self):
+ entry = self.repo.log(2, limit=1)[0]
+ self.assertEqual(entry.diffs, entry.paged_diffs())
+ self.assertEqual(entry.diffs, entry.paged_diffs(start=0))
+ expected = dict(
+ copied=[], changed=[], removed=[],
+ added=['/a/b', '/a/b/c'], total=4)
+ self.assertEqual(expected, entry.paged_diffs(start=1, end=3))
+
def test_diff_create_file(self):
entry = self.repo.log(1, limit=1)[0]
self.assertEqual(
entry.diffs, dict(
copied=[], changed=[],
- removed=[], added=['/README']))
+ removed=[], added=['/README'], total=1))
def test_diff_create_path(self):
entry = self.repo.log(2, limit=1)[0]
@@ -222,21 +231,21 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
copied=[], changed=[], removed=[],
added=[
'/a', '/a/b', '/a/b/c',
- '/a/b/c/hello.txt']))
+ '/a/b/c/hello.txt'], total=4))
def test_diff_modify_file(self):
entry = self.repo.log(3, limit=1)[0]
self.assertEqual(
entry.diffs, dict(
copied=[], changed=['/README'],
- removed=[], added=[]))
+ removed=[], added=[], total=1))
def test_diff_delete(self):
entry = self.repo.log(4, limit=1)[0]
self.assertEqual(
entry.diffs, dict(
copied=[], changed=[],
- removed=['/a/b/c/hello.txt'], added=[]))
+ removed=['/a/b/c/hello.txt'], added=[], total=1))
def test_diff_copy(self):
# Copies are currently only detected as 'add'
@@ -244,7 +253,7 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
self.assertEqual(
entry.diffs, dict(
copied=[], changed=[],
- removed=[], added=['/b']))
+ removed=[], added=['/b'], total=1))
def test_commit(self):
entry = self.repo.commit(1)