allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject [29/45] allura git commit: [#7837] ticket:736 Rewrite Commit.paged_diffs for Git
Date Mon, 30 Mar 2015 12:26:45 GMT
[#7837] ticket:736 Rewrite Commit.paged_diffs for Git


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

Branch: refs/heads/ib/7837
Commit: d14a5463239c56fd7c0280840911e4ca2b9e3b5b
Parents: b42fa1a
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Mar 2 14:37:40 2015 +0000
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Fri Mar 27 15:09:23 2015 +0000

----------------------------------------------------------------------
 Allura/allura/model/repository.py   | 36 ++++++++++++++++----------------
 ForgeGit/forgegit/model/git_repo.py | 25 ++++++++++++++++++++++
 2 files changed, 43 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/d14a5463/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 867a6d2..9255c66 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -313,6 +313,14 @@ class RepositoryImplementation(object):
         """
         raise NotImplemented('get_changes')
 
+    def paged_diffs(self, commit_id, start=0, end=None):
+        """
+        Returns files touched by the commit, grouped by status (added, removed,
+        and changed) and the total number of such files.  Paginates according
+        to :param start: and :param end:.
+        """
+        raise NotImplemented('paged_diffs')
+
 
 class Repository(Artifact, ActivityObject):
     BATCH_SIZE = 100
@@ -485,6 +493,9 @@ class Repository(Artifact, ActivityObject):
     def set_default_branch(self, name):
         return self._impl.set_default_branch(name)
 
+    def paged_diffs(self, commit_id, start=0, end=None):
+        return self._impl.paged_diffs(commit_id, start, end)
+
     def _log(self, rev, skip, limit):
         head = self.commit(rev)
         if head is None:
@@ -1104,25 +1115,14 @@ class Commit(RepoObject, ActivityObject):
         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=[], total=0)
-        added = []
-        removed = []
-        changed = []
-        copied = []
-        for change in di.differences[start:end]:
-            if change.rhs_id is None:
-                removed.append(change.name)
-            elif change.lhs_id is None:
-                added.append(change.name)
-            else:
-                changed.append(change.name)
-        copied = self._diffs_copied(added, removed)
+        diffs = self.repo.paged_diffs(self._id, start, end)
+        diffs['copied'] = self._diffs_copied(diffs['added'], diffs['removed'])
         return Object(
-            added=added, removed=removed,
-            changed=changed, copied=copied,
-            total=len(di.differences))
+            added=diffs['added'],
+            removed=diffs['removed'],
+            changed=diffs['changed'],
+            copied=diffs['copied'],
+            total=diffs['total'])
 
     def _diffs_copied(self, added, removed):
         '''Return list with file renames diffs.

http://git-wip-us.apache.org/repos/asf/allura/blob/d14a5463/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 8841f52..e1d16e8 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -600,6 +600,31 @@ class GitImplementation(M.RepositoryImplementation):
             pretty='format:',
             max_count=1).splitlines()[1:]
 
+    def paged_diffs(self, commit_id, start, end):
+        added, removed, changed = [], [], []
+        files = self._git.git.diff_tree(
+            '--no-commit-id',
+            '--name-status',
+            '--no-renames',
+            '-r',
+            commit_id)
+        files = files.splitlines()
+        total = len(files)
+        for f in files[start:end]:
+            status, name = f.split('\t', 1)
+            if status == 'A':
+                added.append(name)
+            elif status == 'D':
+                removed.append(name)
+            elif status == 'M':
+                changed.append(name)
+        return {
+            'added': added,
+            'removed': removed,
+            'changed': changed,
+            'total': total,
+        }
+
 
 class _OpenedGitBlob(object):
     CHUNK_SIZE = 4096


Mime
View raw message