Changeset - 4034992774fa
[Not reviewed]
default
0 5 0
Mads Kiilerich - 9 years ago 2016-09-06 00:51:18
madski@unity3d.com
diffs: fold diff_block_simple (used by PR and compare) into diff_block

Change to using the same datamodel and enjoy the reduced amount of code
duplication.
5 files changed with 26 insertions and 43 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/compare.py
Show inline comments
 
@@ -41,13 +41,13 @@ from kallithea.lib.base import BaseRepoC
 
from kallithea.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
 
from kallithea.lib import diffs
 
from kallithea.model.db import Repository
 
from kallithea.lib.diffs import LimitedDiffContainer
 
from kallithea.controllers.changeset import _ignorews_url, _context_url
 
from kallithea.lib.graphmod import graph_data
 
from kallithea.lib.compat import json
 
from kallithea.lib.compat import json, OrderedDict
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
class CompareController(BaseRepoController):
 

	
 
@@ -274,21 +274,20 @@ class CompareController(BaseRepoControll
 
        _parsed = diff_processor.prepare()
 

	
 
        c.limited_diff = False
 
        if isinstance(_parsed, LimitedDiffContainer):
 
            c.limited_diff = True
 

	
 
        c.files = []
 
        c.changes = {}
 
        c.file_diff_data = OrderedDict()
 
        c.lines_added = 0
 
        c.lines_deleted = 0
 
        for f in _parsed:
 
            st = f['stats']
 
            c.lines_added += st['added']
 
            c.lines_deleted += st['deleted']
 
            filename = f['filename']
 
            fid = h.FID('', filename)
 
            c.files.append([fid, f['operation'], filename, f['stats']])
 
            htmldiff = diff_processor.as_html(enable_comments=False, parsed_lines=[f])
 
            c.changes[fid] = [f['operation'], filename, htmldiff]
 
            diff = diff_processor.as_html(enable_comments=False,
 
                                          parsed_lines=[f])
 
            c.file_diff_data[fid] = (None, f['operation'], filename, diff, st)
 

	
 
        return render('compare/compare_diff.html')
kallithea/controllers/pullrequests.py
Show inline comments
 
@@ -32,13 +32,13 @@ import re
 

	
 
from pylons import request, tmpl_context as c, url
 
from pylons.i18n.translation import _
 
from webob.exc import HTTPFound, HTTPNotFound, HTTPForbidden, HTTPBadRequest
 

	
 
from kallithea.lib.vcs.utils.hgcompat import unionrepo
 
from kallithea.lib.compat import json
 
from kallithea.lib.compat import json, OrderedDict
 
from kallithea.lib.base import BaseRepoController, render
 
from kallithea.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator, \
 
    NotAnonymous
 
from kallithea.lib.helpers import Page
 
from kallithea.lib import helpers as h
 
from kallithea.lib import diffs
 
@@ -692,27 +692,25 @@ class PullrequestsController(BaseRepoCon
 
        _parsed = diff_processor.prepare()
 

	
 
        c.limited_diff = False
 
        if isinstance(_parsed, LimitedDiffContainer):
 
            c.limited_diff = True
 

	
 
        c.files = []
 
        c.changes = {}
 
        c.file_diff_data = OrderedDict()
 
        c.lines_added = 0
 
        c.lines_deleted = 0
 

	
 
        for f in _parsed:
 
            st = f['stats']
 
            c.lines_added += st['added']
 
            c.lines_deleted += st['deleted']
 
            filename = f['filename']
 
            fid = h.FID('', filename)
 
            c.files.append([fid, f['operation'], filename, f['stats']])
 
            htmldiff = diff_processor.as_html(enable_comments=True,
 
            diff = diff_processor.as_html(enable_comments=True,
 
                                              parsed_lines=[f])
 
            c.changes[fid] = [f['operation'], filename, htmldiff]
 
            c.file_diff_data[fid] = (None, f['operation'], 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/templates/changeset/diff_block.html
Show inline comments
 
@@ -12,28 +12,12 @@
 
        a_repo_name, a_rev, a_ref_type, a_ref_name,
 
        cs_repo_name, cs_rev, cs_ref_type, cs_ref_name)}
 
%endfor
 
</div>
 
</%def>
 

	
 
<%def name="diff_block_simple(files, changes)">
 
<div class="diff-collapse">
 
    <span target="${'diff-container-%s' % (id(changes))}" class="diff-collapse-button">&uarr; ${_('Collapse Diff')} &uarr;</span>
 
</div>
 
<div class="diff-container" id="${'diff-container-%s' % (id(changes))}">
 
  %for fid, ch, f, stat in files:
 
    <%
 
    op, filename, diff = changes[fid]
 
    %>
 
    ${diff_block_diffblock(h.FID('', filename), None, op, filename, diff,
 
        c.a_repo.repo_name, c.a_rev, c.a_ref_type, c.a_ref_name,
 
        c.cs_repo.repo_name, c.cs_rev, c.cs_ref_type, c.cs_ref_name)}
 
  %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)"
 
>
 
    <div id="${id_fid}_target" style="clear:both;margin-top:25px"></div>
 
    <div id="${id_fid}" class="diffblock margined comm">
kallithea/templates/compare/compare_diff.html
Show inline comments
 
@@ -54,44 +54,45 @@ ${self.repo_context_bar('changelog')}
 
                <%include file="compare_cs.html" />
 

	
 
                ## FILES
 
                <div style="font-size:1.1em;font-weight: bold;clear:both;padding-top:10px">
 

	
 
                % if c.limited_diff:
 
                    ${ungettext('%s file changed', '%s files changed', len(c.files)) % len(c.files)}:
 
                    ${ungettext('%s file changed', '%s files changed', len(c.file_diff_data)) % len(c.file_diff_data)}:
 
                % else:
 
                    ${ungettext('%s file changed with %s insertions and %s deletions','%s files changed with %s insertions and %s deletions', len(c.files)) % (len(c.files),c.lines_added,c.lines_deleted)}:
 
                    ${ungettext('%s file changed with %s insertions and %s deletions','%s files changed with %s insertions and %s deletions', len(c.file_diff_data)) % (len(c.file_diff_data),c.lines_added,c.lines_deleted)}:
 
                %endif
 

	
 
                ${c.ignorews_url(request.GET)}
 
                ${c.context_url(request.GET)}
 

	
 
                </div>
 
                <div class="cs_files">
 
                  %if not c.files:
 
                  %if not c.file_diff_data:
 
                     <span class="empty_data">${_('No files')}</span>
 
                  %endif
 
                  %for fid, op, f, stat in c.files:
 
                  %for fid, (url_fid, op, 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(f), '#' + fid)}
 
                          ${h.link_to(h.safe_unicode(path), '#%s' % fid)}
 
                      </div>
 
                      <div class="changes">${h.fancy_file_stats(stat)}</div>
 
                      <div class="changes">${h.fancy_file_stats(stats)}</div>
 
                    </div>
 
                  %endfor
 
                  %if c.limited_diff:
 
                    <h5>${_('Changeset was too big and was cut off...')} <a href="${h.url.current(fulldiff=1, **request.GET.mixed())}">${_('Show full diff')}</a></h5>
 
                    <h5>${_('Changeset was too big and was cut off...')} <a href="${h.url.current(fulldiff=1, **request.GET.mixed())}">${_('Show full diff anyway')}</a></h5>
 
                  %endif
 
                </div>
 
         </div>
 

	
 
        ## diff block
 
        <%namespace name="diff_block" file="/changeset/diff_block.html"/>
 
        ${diff_block.diff_block_js()}
 
        ${diff_block.diff_block_simple(c.files, c.changes)}
 
        ${diff_block.diff_block(c.a_repo.repo_name, c.a_ref_type, c.a_ref_name, c.a_rev,
 
                                c.cs_repo.repo_name, c.cs_ref_type, c.cs_ref_name, c.cs_rev, c.file_diff_data)}
 
        % if c.limited_diff:
 
          <h4>${_('Changeset was too big and was cut off...')} <a href="${h.url.current(fulldiff=1, **request.GET.mixed())}">${_('Show full diff')}</a></h4>
 
        % endif
 
    %endif
 
    </div>
 

	
kallithea/templates/pullrequests/pullrequest_show.html
Show inline comments
 
@@ -321,29 +321,29 @@ ${self.repo_context_bar('showpullrequest
 
              </div>
 

	
 
              ## FILES
 
              <div style="font-size:1.1em;font-weight: bold;clear:both;padding-top:10px">
 

	
 
              % if c.limited_diff:
 
                  ${ungettext('%s file changed', '%s files changed', len(c.files)) % len(c.files)}:
 
                  ${ungettext('%s file changed', '%s files changed', len(c.file_diff_data)) % len(c.file_diff_data)}:
 
              % else:
 
                  ${ungettext('%s file changed with %s insertions and %s deletions','%s files changed with %s insertions and %s deletions', len(c.files)) % (len(c.files),c.lines_added,c.lines_deleted)}:
 
                  ${ungettext('%s file changed with %s insertions and %s deletions','%s files changed with %s insertions and %s deletions', len(c.file_diff_data)) % (len(c.file_diff_data),c.lines_added,c.lines_deleted)}:
 
              %endif
 

	
 
              </div>
 
              <div class="cs_files">
 
                %if not c.files:
 
                %if not c.file_diff_data:
 
                   <span class="empty_data">${_('No files')}</span>
 
                %endif
 
                %for fid, op, f, stat in c.files:
 
                %for fid, (url_fid, op, 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(f),'#' + fid)}
 
                          ${h.link_to(h.safe_unicode(path), '#%s' % fid)}
 
                      </div>
 
                      <div class="changes">${h.fancy_file_stats(stat)}</div>
 
                      <div class="changes">${h.fancy_file_stats(stats)}</div>
 
                    </div>
 
                %endfor
 
                %if c.limited_diff:
 
                  <h5>${_('Changeset was too big and was cut off...')} <a href="${h.url.current(fulldiff=1, **request.GET.mixed())}">${_('Show full diff anyway')}</a></h5>
 
                %endif
 
              </div>
 
@@ -362,13 +362,14 @@ ${self.repo_context_bar('showpullrequest
 
    </script>
 

	
 
    ## diff block
 
    <div class="commentable-diff">
 
    <%namespace name="diff_block" file="/changeset/diff_block.html"/>
 
    ${diff_block.diff_block_js()}
 
    ${diff_block.diff_block_simple(c.files, c.changes)}
 
    ${diff_block.diff_block(c.a_repo.repo_name, c.a_ref_type, c.a_ref_name, c.a_rev,
 
                            c.cs_repo.repo_name, c.cs_ref_type, c.cs_ref_name, c.cs_rev, c.file_diff_data)}
 
    % if c.limited_diff:
 
      <h4>${_('Changeset was too big and was cut off...')} <a href="${h.url.current(fulldiff=1, **request.GET.mixed())}">${_('Show full diff anyway')}</a></h4>
 
    % endif
 
    </div>
 

	
 
    ## template for inline comment form
0 comments (0 inline, 0 general)