Mercurial > kallithea
changeset 6194:4034992774fa
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.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Tue, 06 Sep 2016 00:51:18 +0200 |
parents | dc4cb1d4e084 |
children | 12ce88eece5f |
files | kallithea/controllers/compare.py kallithea/controllers/pullrequests.py kallithea/templates/changeset/diff_block.html kallithea/templates/compare/compare_diff.html kallithea/templates/pullrequests/pullrequest_show.html |
diffstat | 5 files changed, 27 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ -44,7 +44,7 @@ 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__) @@ -277,8 +277,7 @@ 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: @@ -287,8 +286,8 @@ 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')
--- 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 @@ -35,7 +35,7 @@ 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 @@ -695,8 +695,7 @@ 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 @@ -706,10 +705,9 @@ 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, - parsed_lines=[f]) - c.changes[fid] = [f['operation'], filename, htmldiff] + diff = diff_processor.as_html(enable_comments=True, + parsed_lines=[f]) + c.file_diff_data[fid] = (None, f['operation'], filename, diff, st) # inline comments c.inline_cnt = 0
--- 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 @@ -15,22 +15,6 @@ </div> </%def> -<%def name="diff_block_simple(files, changes)"> -<div class="diff-collapse"> - <span target="${'diff-container-%s' % (id(changes))}" class="diff-collapse-button">↑ ${_('Collapse Diff')} ↑</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)"
--- 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 @@ -57,9 +57,9 @@ <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)} @@ -67,20 +67,20 @@ </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> @@ -88,7 +88,8 @@ ## 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
--- 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 @@ -324,23 +324,23 @@ <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: @@ -365,7 +365,8 @@ <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