You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2015/08/05 17:31:13 UTC

[03/12] allura git commit: [#7925] simplify and de-bug git output processing by using a new var, no in-place updates to 'files'

[#7925] simplify and de-bug git output processing by using a new var, no in-place updates to 'files'


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

Branch: refs/heads/db/7925
Commit: 952c0d4dff436465ac8188f78027301e5558f282
Parents: a011d9a
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Fri Jul 31 16:12:23 2015 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Fri Jul 31 16:27:30 2015 +0000

----------------------------------------------------------------------
 ForgeGit/forgegit/model/git_repo.py | 74 ++++++++++++++++++--------------
 1 file changed, 42 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/952c0d4d/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index ece0d6c..9462087 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -642,9 +642,9 @@ class GitImplementation(M.RepositoryImplementation):
             max_count=1).splitlines()[1:]
 
     def paged_diffs(self, commit_id, start=0, end=None):
-        result = {'added': [], 'removed': [], 'changed': [], 'copied': [], 'renamed': [], 'total': 0}
+        result = {'added': [], 'removed': [], 'changed': [], 'copied': [], 'renamed': []}
 
-        files = self._git.git.diff_tree(
+        cmd_output = self._git.git.diff_tree(
             '--no-commit-id',
             '--find-renames',
             '--find-copies',
@@ -656,39 +656,49 @@ class GitImplementation(M.RepositoryImplementation):
             '-z',  # don't escape filenames and use \x00 as fields delimiter
             commit_id).split('\x00')[:-1]
 
-        result['total'] = len(files) / 2
-        x = 0
-        while x < len(files):
-            try:
-                if files[x].startswith("R") or files[x].startswith("C"):
-                    change_list = result['renamed'] if files[x].startswith("R") else result['copied']
-                    ratio = float(files[x][1:4]) / 100.0
-                    change_list.append({
-                        'new': h.really_unicode(files[x + 2]),
-                        'old': h.really_unicode(files[x + 1]),
-                        'ratio': ratio,
-                        'diff': '',
-                    })
-                    del files[x:x+3]
-                    x += 3
-                    result['total'] -= 1
-                else:
-                    x += 2
-            except IndexError:
-                break
+        ''' cmd_output will be like:
+        [
+        'A',
+        'filename',
+        'D',
+        'another filename',
+        'M',
+        'po',
+        'R100',
+        'po/sr.po',
+        'po/sr_Latn.po',
+        ]
+        '''
 
-        files = [(files[i], h.really_unicode(files[i + 1]))
-                 for i in xrange(0, result['total'] + 1, 2)]
+        x = 0
+        files = []
+        while x < len(cmd_output):
+            status = cmd_output[x][0]
+            if status in ('R', 'C'):
+                # TODO: make sure we have a test for this
+                ratio = float(cmd_output[x][1:4]) / 100.0
+                files.append((status, {
+                    'new': h.really_unicode(cmd_output[x + 2]),
+                    'old': h.really_unicode(cmd_output[x + 1]),
+                    'ratio': ratio,
+                    'diff': '',
+                }))
+                x += 3
+            else:
+                files.append((status, h.really_unicode(cmd_output[x+1])))
+                x += 2
 
-        # files = [('A', u'filename'), ('D', u'another filename'), ...]
         for status, name in files[start:end]:
-            if status == 'A':
-                result['added'].append(name)
-            elif status == 'D':
-                result['removed'].append(name)
-            elif status == 'M':
-                result['changed'].append(name)
-
+            change_list = {
+                'R': result['renamed'],
+                'C': result['copied'],
+                'A': result['added'],
+                'D': result['removed'],
+                'M': result['changed']
+            }[status]
+            change_list.append(name)
+
+        result['total'] = len(files)
         return result
 
     @contextmanager