Changeset - 12ce88eece5f
[Not reviewed]
default
0 10 0
Mads Kiilerich - 9 years ago 2016-09-06 00:51:18
madski@unity3d.com
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.
10 files changed with 35 insertions and 32 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/changeset.py
Show inline comments
 
@@ -293,13 +293,13 @@ class ChangesetController(BaseRepoContro
 
                    c.lines_deleted += st['deleted']
 
                    filename = f['filename']
 
                    fid = h.FID(changeset.raw_id, filename)
 
                    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()
 
                file_diff_data[''] = (None, None, None, diff, None)
 
            c.changes[changeset.raw_id] = (cs1, cs2, file_diff_data)
 

	
kallithea/controllers/compare.py
Show inline comments
 
@@ -285,9 +285,9 @@ class CompareController(BaseRepoControll
 
            c.lines_added += st['added']
 
            c.lines_deleted += st['deleted']
 
            filename = f['filename']
 
            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')
kallithea/controllers/files.py
Show inline comments
 
@@ -680,19 +680,19 @@ class FilesController(BaseRepoController
 
        else:
 
            fid = h.FID(diff2, node2.path)
 
            line_context_lcl = get_line_ctx(fid, request.GET)
 
            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')
 

	
 
    @LoginRequired()
 
    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
 
                                   'repository.admin')
kallithea/controllers/pullrequests.py
Show inline comments
 
@@ -704,13 +704,13 @@ class PullrequestsController(BaseRepoCon
 
            c.lines_added += st['added']
 
            c.lines_deleted += st['deleted']
 
            filename = f['filename']
 
            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
 
        c.inline_comments = cc_model.get_inline_comments(
 
                                c.db_repo.repo_id,
 
                                pull_request=pull_request_id)
kallithea/lib/diffs.py
Show inline comments
 
@@ -60,12 +60,13 @@ def wrapped_diff(filenode_old, filenode_
 
    """
 

	
 
    if filenode_old is None:
 
        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)
 

	
 
    elif cut_off_limit != -1 and (
 
            cut_off_limit is None or
 
@@ -76,12 +77,13 @@ def wrapped_diff(filenode_old, filenode_
 
                                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']
 
            a_path = f['old_filename']
 

	
 
        diff = diff_processor.as_html(enable_comments=enable_comments)
 
        stats = diff_processor.stat()
 

	
 
    else:
 
        diff = wrap_to_table(_('Changeset was too big and was cut off, use '
 
@@ -96,13 +98,13 @@ def wrapped_diff(filenode_old, filenode_
 
        else:
 
            diff = wrap_to_table(_('No changes detected'))
 

	
 
    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):
 
    """
 
    Returns git style diff between given ``filenode_old`` and ``filenode_new``.
 

	
 
@@ -473,12 +475,13 @@ class DiffProcessor(object):
 
                'action':     'context',
 
                'line':       msg,
 
                } for _op, msg in stats['ops'].iteritems()
 
                  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'],
 
                'chunks':           chunks,
 
                'operation':        op,
 
                'stats':            stats,
kallithea/templates/changeset/changeset.html
Show inline comments
 
@@ -165,13 +165,13 @@ ${self.repo_context_bar('changelog', c.c
 
                  ${ungettext('%s file changed', '%s files changed', len(file_diff_data)) % len(file_diff_data)}:
 
              % else:
 
                  ${ungettext('%s file changed with %s insertions and %s deletions', '%s files changed with %s insertions and %s deletions', len(file_diff_data)) % (len(file_diff_data), c.lines_added, c.lines_deleted)}:
 
              %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>
 
                          ${h.link_to(h.safe_unicode(path), '#%s' % fid)}
 
                      </div>
 
                      <div class="changes">${h.fancy_file_stats(stats)}</div>
kallithea/templates/changeset/changeset_range.html
Show inline comments
 
@@ -57,13 +57,13 @@ ${self.repo_context_bar('changelog')}
 
            </div>
 
            <div style="font-size:1.1em;font-weight: bold;clear:both;padding-top:10px">${_('Files affected')}</div>
 
            <div class="cs_files">
 
                %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>
 
                                ${h.link_to(h.safe_unicode(path), '#%s' % fid)}
 
                            </div>
 
                            <div class="changes">${h.fancy_file_stats(stats)}</div>
kallithea/templates/changeset/diff_block.html
Show inline comments
 
@@ -4,60 +4,60 @@
 
                       cs_repo_name, cs_ref_name, cs_ref_type, cs_rev,
 
                       file_diff_data)">
 
<div class="diff-collapse">
 
    <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)}
 
                  ${c.context_url(request.GET, url_fid)}
 
                </div>
 
                <span style="float:right;margin-top:-3px">
 
@@ -65,27 +65,27 @@
 
                        ${_('Show inline comments')}
 
                        ${h.checkbox('',checked="checked",class_="show-inline-comments",id_for=url_fid)}
 
                    </label>
 
                </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>
 
              %endif
 
              <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
 
        </div>
 
    </div>
 
</%def>
kallithea/templates/compare/compare_diff.html
Show inline comments
 
@@ -67,13 +67,13 @@ ${self.repo_context_bar('changelog')}
 

	
 
                </div>
 
                <div class="cs_files">
 
                  %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>
 
                          ${h.link_to(h.safe_unicode(path), '#%s' % fid)}
 
                      </div>
 
                      <div class="changes">${h.fancy_file_stats(stats)}</div>
kallithea/templates/pullrequests/pullrequest_show.html
Show inline comments
 
@@ -331,13 +331,13 @@ ${self.repo_context_bar('showpullrequest
 

	
 
              </div>
 
              <div class="cs_files">
 
                %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>
 
                          ${h.link_to(h.safe_unicode(path), '#%s' % fid)}
 
                      </div>
 
                      <div class="changes">${h.fancy_file_stats(stats)}</div>
0 comments (0 inline, 0 general)