changeset 6191:79676fef1ae0

diff: show correct operation for file diffs instead of '???' Fix issue seen on the url $repo/diff/$filename?diff2=hash2&diff1=hash2 . Drop returning unused size from diffs.wrapped_diff and return the operation instead.
author Mads Kiilerich <madski@unity3d.com>
date Tue, 06 Sep 2016 00:51:18 +0200
parents 020334bec94b
children 72acb38da217
files kallithea/controllers/files.py kallithea/lib/diffs.py
diffstat 2 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/files.py	Tue Sep 06 00:51:18 2016 +0200
+++ b/kallithea/controllers/files.py	Tue Sep 06 00:51:18 2016 +0200
@@ -683,13 +683,12 @@
             ign_whitespace_lcl = get_ignore_ws(fid, request.GET)
 
             lim = request.GET.get('fulldiff') or self.cut_off_limit
-            _, cs1, cs2, diff, st = diffs.wrapped_diff(filenode_old=node1,
+            cs1, cs2, op, diff, st = diffs.wrapped_diff(filenode_old=node1,
                                          filenode_new=node2,
                                          cut_off_limit=lim,
                                          ignore_whitespace=ign_whitespace_lcl,
                                          line_context=line_context_lcl,
                                          enable_comments=False)
-            op = ''
             filename = node1.path
             cs_changes = {
                 'fid': [cs1, cs2, op, filename, diff, st]
--- a/kallithea/lib/diffs.py	Tue Sep 06 00:51:18 2016 +0200
+++ b/kallithea/lib/diffs.py	Tue Sep 06 00:51:18 2016 +0200
@@ -62,27 +62,32 @@
     if filenode_old is None:
         filenode_old = FileNode(filenode_new.path, '', EmptyChangeset())
 
+    op = None
     if filenode_old.is_binary or filenode_new.is_binary:
         diff = wrap_to_table(_('Binary file'))
         stats = (0, 0)
-        size = 0
 
-    elif cut_off_limit != -1 and (cut_off_limit is None or
-    (filenode_old.size < cut_off_limit and filenode_new.size < cut_off_limit)):
+    elif cut_off_limit != -1 and (
+            cut_off_limit is None or
+            (filenode_old.size < cut_off_limit and filenode_new.size < cut_off_limit)):
 
         f_gitdiff = get_gitdiff(filenode_old, filenode_new,
                                 ignore_whitespace=ignore_whitespace,
                                 context=line_context)
         diff_processor = DiffProcessor(f_gitdiff, format='gitdiff')
+        _parsed = diff_processor.prepare()
+        if _parsed: # there should be exactly one element, for the specified file
+            f = _parsed[0]
+            op = f['operation']
 
         diff = diff_processor.as_html(enable_comments=enable_comments)
         stats = diff_processor.stat()
-        size = len(diff or '')
+
     else:
         diff = wrap_to_table(_('Changeset was too big and was cut off, use '
                                'diff menu to display this diff'))
         stats = (0, 0)
-        size = 0
+
     if not diff:
         submodules = filter(lambda o: isinstance(o, SubModuleNode),
                             [filenode_new, filenode_old])
@@ -94,7 +99,7 @@
     cs1 = filenode_old.changeset.raw_id
     cs2 = filenode_new.changeset.raw_id
 
-    return size, cs1, cs2, diff, stats
+    return cs1, cs2, op, diff, stats
 
 
 def get_gitdiff(filenode_old, filenode_new, ignore_whitespace=True, context=3):