changeset 6195:12ce88eece5f

diff: correct handling of links to old filename in renames There were links to the file at the parent revision ... but if the file had been renamed, it used the wrong name.
author Mads Kiilerich <madski@unity3d.com>
date Tue, 06 Sep 2016 00:51:18 +0200
parents 4034992774fa
children 596393436724
files kallithea/controllers/changeset.py kallithea/controllers/compare.py kallithea/controllers/files.py kallithea/controllers/pullrequests.py kallithea/lib/diffs.py kallithea/templates/changeset/changeset.html kallithea/templates/changeset/changeset_range.html kallithea/templates/changeset/diff_block.html kallithea/templates/compare/compare_diff.html kallithea/templates/pullrequests/pullrequest_show.html
diffstat 10 files changed, 35 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/changeset.py	Tue Sep 06 00:51:18 2016 +0200
+++ b/kallithea/controllers/changeset.py	Tue Sep 06 00:51:18 2016 +0200
@@ -296,7 +296,7 @@
                     url_fid = h.FID('', filename)
                     diff = diff_processor.as_html(enable_comments=enable_comments,
                                                   parsed_lines=[f])
-                    file_diff_data[fid] = (url_fid, f['operation'], filename, diff, st)
+                    file_diff_data[fid] = (url_fid, f['operation'], f['old_filename'], filename, diff, st)
             else:
                 # downloads/raw we only need RAW diff nothing else
                 diff = diff_processor.as_raw()
--- a/kallithea/controllers/compare.py	Tue Sep 06 00:51:18 2016 +0200
+++ b/kallithea/controllers/compare.py	Tue Sep 06 00:51:18 2016 +0200
@@ -288,6 +288,6 @@
             fid = h.FID('', filename)
             diff = diff_processor.as_html(enable_comments=False,
                                           parsed_lines=[f])
-            c.file_diff_data[fid] = (None, f['operation'], filename, diff, st)
+            c.file_diff_data[fid] = (None, f['operation'], f['old_filename'], filename, diff, st)
 
         return render('compare/compare_diff.html')
--- 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,13 @@
             ign_whitespace_lcl = get_ignore_ws(fid, request.GET)
 
             lim = request.GET.get('fulldiff') or self.cut_off_limit
-            c.a_rev, c.cs_rev, op, diff, st = diffs.wrapped_diff(filenode_old=node1,
+            c.a_rev, c.cs_rev, a_path, diff, st, op = 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)
-            c.file_diff_data = {fid: (fid, op, node1.path, diff, st)}
+            c.file_diff_data = {fid: (fid, op, a_path, node2.path, diff, st)}
 
             return render('files/file_diff.html')
 
--- a/kallithea/controllers/pullrequests.py	Tue Sep 06 00:51:18 2016 +0200
+++ b/kallithea/controllers/pullrequests.py	Tue Sep 06 00:51:18 2016 +0200
@@ -707,7 +707,7 @@
             fid = h.FID('', filename)
             diff = diff_processor.as_html(enable_comments=True,
                                           parsed_lines=[f])
-            c.file_diff_data[fid] = (None, f['operation'], filename, diff, st)
+            c.file_diff_data[fid] = (None, f['operation'], f['old_filename'], filename, diff, st)
 
         # inline comments
         c.inline_cnt = 0
--- 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
@@ -63,6 +63,7 @@
         filenode_old = FileNode(filenode_new.path, '', EmptyChangeset())
 
     op = None
+    a_path = filenode_old.path # default, might be overriden by actual rename in diff
     if filenode_old.is_binary or filenode_new.is_binary:
         diff = wrap_to_table(_('Binary file'))
         stats = (0, 0)
@@ -79,6 +80,7 @@
         if _parsed: # there should be exactly one element, for the specified file
             f = _parsed[0]
             op = f['operation']
+            a_path = f['old_filename']
 
         diff = diff_processor.as_html(enable_comments=enable_comments)
         stats = diff_processor.stat()
@@ -99,7 +101,7 @@
     cs1 = filenode_old.changeset.raw_id
     cs2 = filenode_new.changeset.raw_id
 
-    return cs1, cs2, op, diff, stats
+    return cs1, cs2, a_path, diff, stats, op
 
 
 def get_gitdiff(filenode_old, filenode_new, ignore_whitespace=True, context=3):
@@ -476,6 +478,7 @@
                   if _op not in [MOD_FILENODE]])
 
             _files.append({
+                'old_filename':     head['a_path'],
                 'filename':         head['b_path'],
                 'old_revision':     head['a_blob_id'],
                 'new_revision':     head['b_blob_id'],
--- a/kallithea/templates/changeset/changeset.html	Tue Sep 06 00:51:18 2016 +0200
+++ b/kallithea/templates/changeset/changeset.html	Tue Sep 06 00:51:18 2016 +0200
@@ -168,7 +168,7 @@
               %endif
               </div>
               <div class="cs_files">
-                %for fid, (url_fid, op, path, diff, stats) in file_diff_data.iteritems():
+                %for fid, (url_fid, op, a_path, path, diff, stats) in file_diff_data.iteritems():
                     <div class="cs_${op}">
                       <div class="node">
                           <i class="icon-diff-${op}"></i>
--- a/kallithea/templates/changeset/changeset_range.html	Tue Sep 06 00:51:18 2016 +0200
+++ b/kallithea/templates/changeset/changeset_range.html	Tue Sep 06 00:51:18 2016 +0200
@@ -60,7 +60,7 @@
                 %for cs in c.cs_ranges:
                     <div class="cur_cs">${h.link_to(h.show_id(cs),h.url('changeset_home',repo_name=c.cs_repo.repo_name,revision=cs.raw_id))}</div>
                     <% a_rev, cs_rev, file_diff_data = c.changes[cs.raw_id] %>
-                    %for fid, (url_fid, op, path, diff, stats) in file_diff_data.iteritems():
+                    %for fid, (url_fid, op, a_path, path, diff, stats) in file_diff_data.iteritems():
                         <div class="cs_${op}">
                             <div class="node">
                                 <i class="icon-diff-${op}"></i>
--- a/kallithea/templates/changeset/diff_block.html	Tue Sep 06 00:51:18 2016 +0200
+++ b/kallithea/templates/changeset/diff_block.html	Tue Sep 06 00:51:18 2016 +0200
@@ -7,54 +7,54 @@
     <span target="${'diff-container-%s' % (id(file_diff_data))}" class="diff-collapse-button">&uarr; ${_('Collapse Diff')} &uarr;</span>
 </div>
 <div class="diff-container" id="${'diff-container-%s' % (id(file_diff_data))}">
-%for id_fid, (url_fid, op, filename, diff, stats) in file_diff_data.iteritems():
-    ${diff_block_diffblock(id_fid, url_fid, op, filename, diff,
-        a_repo_name, a_rev, a_ref_type, a_ref_name,
-        cs_repo_name, cs_rev, cs_ref_type, cs_ref_name)}
+%for id_fid, (url_fid, op, a_filename, cs_filename, diff, stats) in file_diff_data.iteritems():
+    ${diff_block_diffblock(id_fid, url_fid, op, diff,
+        a_repo_name, a_rev, a_ref_type, a_ref_name, a_filename,
+        cs_repo_name, cs_rev, cs_ref_type, cs_ref_name, cs_filename)}
 %endfor
 </div>
 </%def>
 
-<%def name="diff_block_diffblock(id_fid, url_fid, op, filename, diff,
-    a_repo_name, a_rev, a_ref_type, a_ref_name,
-    cs_repo_name, cs_rev, cs_ref_type, cs_ref_name)"
+<%def name="diff_block_diffblock(id_fid, url_fid, op, diff,
+    a_repo_name, a_rev, a_ref_type, a_ref_name, a_filename,
+    cs_repo_name, cs_rev, cs_ref_type, cs_ref_name, cs_filename)"
 >
     <div id="${id_fid}_target" style="clear:both;margin-top:25px"></div>
     <div id="${id_fid}" class="diffblock margined comm">
         <div class="code-header">
             <div class="changeset_header">
                 <div class="changeset_file">
-                    ${h.safe_unicode(filename)} |
+                    ${h.safe_unicode(cs_filename)} |
                     %if op == 'A':
                       ${_('Added')}
-                      <a class="spantag" href="${h.url('files_home', repo_name=cs_repo_name, f_path=filename, revision=cs_rev)}">${h.short_ref(cs_ref_type, cs_ref_name)}</a>
+                      <a class="spantag" href="${h.url('files_home', repo_name=cs_repo_name, f_path=cs_filename, revision=cs_rev)}">${h.short_ref(cs_ref_type, cs_ref_name)}</a>
                     %elif op == 'M':
-                      <a class="spantag" href="${h.url('files_home', repo_name=a_repo_name, f_path=filename, revision=a_rev)}">${h.short_ref(a_ref_type, a_ref_name)}</a>
+                      <a class="spantag" href="${h.url('files_home', repo_name=a_repo_name, f_path=a_filename, revision=a_rev)}">${h.short_ref(a_ref_type, a_ref_name)}</a>
                       <i class="icon-right"></i>
-                      <a class="spantag" href="${h.url('files_home', repo_name=cs_repo_name, f_path=filename, revision=cs_rev)}">${h.short_ref(cs_ref_type, cs_ref_name)}</a>
+                      <a class="spantag" href="${h.url('files_home', repo_name=cs_repo_name, f_path=cs_filename, revision=cs_rev)}">${h.short_ref(cs_ref_type, cs_ref_name)}</a>
                     %elif op == 'D':
                       ${_('Deleted')}
-                      <a class="spantag" href="${h.url('files_home', repo_name=a_repo_name, f_path=filename, revision=a_rev)}">${h.short_ref(a_ref_type, a_ref_name)}</a>
+                      <a class="spantag" href="${h.url('files_home', repo_name=a_repo_name, f_path=cs_filename, revision=a_rev)}">${h.short_ref(a_ref_type, a_ref_name)}</a>
                     %elif op == 'R':
                       ${_('Renamed')}
-                      <a class="spantag" href="${h.url('files_home', repo_name=a_repo_name, f_path=filename, revision=a_rev)}">${h.short_ref(a_ref_type, a_ref_name)}</a>
+                      <a class="spantag" href="${h.url('files_home', repo_name=a_repo_name, f_path=a_filename, revision=a_rev)}">${h.short_ref(a_ref_type, a_ref_name)}</a>
                       <i class="icon-right"></i>
-                      <a class="spantag" href="${h.url('files_home', repo_name=cs_repo_name, f_path=filename, revision=cs_rev)}">${h.short_ref(cs_ref_type, cs_ref_name)}</a>
+                      <a class="spantag" href="${h.url('files_home', repo_name=cs_repo_name, f_path=cs_filename, revision=cs_rev)}">${h.short_ref(cs_ref_type, cs_ref_name)}</a>
                     %else:
                       ${op}???
                     %endif
                 </div>
                 <div class="diff-actions">
-                  <a href="${h.url('files_diff_home',repo_name=cs_repo_name,f_path=h.safe_unicode(filename),diff2=cs_rev,diff1=a_rev,diff='diff',fulldiff=1)}" class="tooltip" title="${_('Show full diff for this file')}">
+                  <a href="${h.url('files_diff_home',repo_name=cs_repo_name,f_path=h.safe_unicode(cs_filename),diff2=cs_rev,diff1=a_rev,diff='diff',fulldiff=1)}" class="tooltip" title="${_('Show full diff for this file')}">
                       <i class="icon-file-code"></i>
                   </a>
-                  <a href="${h.url('files_diff_2way_home',repo_name=cs_repo_name,f_path=h.safe_unicode(filename),diff2=cs_rev,diff1=a_rev,diff='diff',fulldiff=1)}" class="tooltip" title="${_('Show full side-by-side diff for this file')}">
+                  <a href="${h.url('files_diff_2way_home',repo_name=cs_repo_name,f_path=h.safe_unicode(cs_filename),diff2=cs_rev,diff1=a_rev,diff='diff',fulldiff=1)}" class="tooltip" title="${_('Show full side-by-side diff for this file')}">
                       <i class="icon-docs"></i>
                   </a>
-                  <a href="${h.url('files_diff_home',repo_name=cs_repo_name,f_path=h.safe_unicode(filename),diff2=cs_rev,diff1=a_rev,diff='raw')}" class="tooltip" title="${_('Raw diff')}">
+                  <a href="${h.url('files_diff_home',repo_name=cs_repo_name,f_path=h.safe_unicode(cs_filename),diff2=cs_rev,diff1=a_rev,diff='raw')}" class="tooltip" title="${_('Raw diff')}">
                       <i class="icon-diff"></i>
                   </a>
-                  <a href="${h.url('files_diff_home',repo_name=cs_repo_name,f_path=h.safe_unicode(filename),diff2=cs_rev,diff1=a_rev,diff='download')}" class="tooltip" title="${_('Download diff')}">
+                  <a href="${h.url('files_diff_home',repo_name=cs_repo_name,f_path=h.safe_unicode(cs_filename),diff2=cs_rev,diff1=a_rev,diff='download')}" class="tooltip" title="${_('Download diff')}">
                       <i class="icon-floppy"></i>
                   </a>
                   ${c.ignorews_url(request.GET, url_fid)}
@@ -68,9 +68,9 @@
                 </span>
             </div>
         </div>
-        <div class="code-body full_f_path" data-f_path="${h.safe_unicode(filename)}">
+        <div class="code-body full_f_path" data-f_path="${h.safe_unicode(cs_filename)}">
             ${diff|n}
-            %if filename.rsplit('.')[-1] in ['png', 'gif', 'jpg', 'bmp']:
+            %if cs_filename.rsplit('.')[-1] in ['png', 'gif', 'jpg', 'bmp']:
               <div class="btn btn-image-diff-show">Show images</div>
               %if op == 'M':
                 <div id="${id_fid}_image-diff" class="btn btn-image-diff-swap" style="display:none">Press to swap images</div>
@@ -78,11 +78,11 @@
               <div style="font-size: 0">
                 %if op in 'DM':
                   <img id="${id_fid}_image-diff-img-a" class="img-diff img-diff-swapable" style="display:none"
-                      realsrc="${h.url('files_raw_home',repo_name=a_repo_name,revision=a_rev,f_path=filename)}" />
+                      realsrc="${h.url('files_raw_home',repo_name=a_repo_name,revision=a_rev,f_path=a_filename)}" />
                 %endif
                 %if op in 'AM':
                   <img id="${id_fid}_image-diff-img-b" class="img-diff img-diff-swapable" style="display:none"
-                      realsrc="${h.url('files_raw_home',repo_name=cs_repo_name,revision=cs_rev,f_path=filename)}" />
+                      realsrc="${h.url('files_raw_home',repo_name=cs_repo_name,revision=cs_rev,f_path=cs_filename)}" />
                 %endif
               </div>
             %endif
--- a/kallithea/templates/compare/compare_diff.html	Tue Sep 06 00:51:18 2016 +0200
+++ b/kallithea/templates/compare/compare_diff.html	Tue Sep 06 00:51:18 2016 +0200
@@ -70,7 +70,7 @@
                   %if not c.file_diff_data:
                      <span class="empty_data">${_('No files')}</span>
                   %endif
-                  %for fid, (url_fid, op, path, diff, stats) in c.file_diff_data.iteritems():
+                  %for fid, (url_fid, op, a_path, path, diff, stats) in c.file_diff_data.iteritems():
                     <div class="cs_${op}">
                       <div class="node">
                           <i class="icon-diff-${op}"></i>
--- a/kallithea/templates/pullrequests/pullrequest_show.html	Tue Sep 06 00:51:18 2016 +0200
+++ b/kallithea/templates/pullrequests/pullrequest_show.html	Tue Sep 06 00:51:18 2016 +0200
@@ -334,7 +334,7 @@
                 %if not c.file_diff_data:
                    <span class="empty_data">${_('No files')}</span>
                 %endif
-                %for fid, (url_fid, op, path, diff, stats) in c.file_diff_data.iteritems():
+                %for fid, (url_fid, op, a_path, path, diff, stats) in c.file_diff_data.iteritems():
                     <div class="cs_${op}">
                       <div class="node">
                           <i class="icon-diff-${op}"></i>