allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hei...@apache.org
Subject [39/50] [abbrv] allura git commit: [#7925] simplify and de-bug git output processing by using a new var, no in-place updates to 'files'
Date Mon, 10 Aug 2015 17:33:10 GMT
[#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/5adbb285
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/5adbb285
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/5adbb285

Branch: refs/heads/hs/7925
Commit: 5adbb2858dd0f5ac189bc10dc85530e481380cba
Parents: 787ee90
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Fri Jul 31 16:12:23 2015 +0000
Committer: Heith Seewald <hseewald@slashdotmedia.com>
Committed: Mon Aug 10 09:38:36 2015 -0400

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


http://git-wip-us.apache.org/repos/asf/allura/blob/5adbb285/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


Mime
View raw message