Diffs: fixed missing limited diff container display on large diffs

This commit is contained in:
Daniel Dourvaris 2019-01-07 13:41:12 +01:00
parent 1ee8681939
commit f2c8c96013
4 changed files with 2192 additions and 295440 deletions

View file

@ -519,7 +519,7 @@ class DiffSet(object):
'operation': patch['operation'],
'source_mode': patch['stats']['old_mode'],
'target_mode': patch['stats']['new_mode'],
'limited_diff': isinstance(patch, LimitedDiffContainer),
'limited_diff': patch['is_limited_diff'],
'hunks': [],
'hunk_ops': None,
'diffset': self,

View file

@ -121,7 +121,7 @@ collapse_all = len(diffset.files) > collapse_when_files_over
<a class="tooltip revision" title="${h.tooltip(commit.message)}" href="${h.route_path('repo_commit',repo_name=diffset.repo_name,commit_id=commit.raw_id)}">${('r%s:%s' % (commit.idx,h.short_id(commit.raw_id)))}</a> -
${h.age_component(commit.date)}
% if diffset.limited_diff:
- ${_('The requested commit is too big and content was truncated.')}
- ${_('The requested changes are too big and content was truncated.')}
${_ungettext('%(num)s file changed.', '%(num)s files changed.', diffset.changed_files) % {'num': diffset.changed_files}}
<a href="${h.current_route_path(request, fulldiff=1)}" onclick="return confirm('${_("Showing a big diff might take some time and resources, continue?")}')">${_('Show full diff')}</a>
% elif hasattr(c, 'commit_ranges') and len(c.commit_ranges) > 1:
@ -180,22 +180,22 @@ collapse_all = len(diffset.files) > collapse_when_files_over
%if filediff.limited_diff:
<tr class="cb-warning cb-collapser">
<td class="cb-text" ${(c.user_session_attrs["diffmode"] == 'unified' and 'colspan=4' or 'colspan=6')}>
${_('The requested commit is too big and content was truncated.')} <a href="${h.current_route_path(request, fulldiff=1)}" onclick="return confirm('${_("Showing a big diff might take some time and resources, continue?")}')">${_('Show full diff')}</a>
${_('The requested commit or file is too big and content was truncated.')} <a href="${h.current_route_path(request, fulldiff=1)}" onclick="return confirm('${_("Showing a big diff might take some time and resources, continue?")}')">${_('Show full diff')}</a>
</td>
</tr>
%else:
%if over_lines_changed_limit:
<tr class="cb-warning cb-collapser">
<td class="cb-text" ${(c.user_session_attrs["diffmode"] == 'unified' and 'colspan=4' or 'colspan=6')}>
${_('This diff has been collapsed as it changes many lines, (%i lines changed)' % lines_changed)}
<a href="#" class="cb-expand"
onclick="$(this).closest('table').removeClass('cb-collapsed'); updateSticky(); return false;">${_('Show them')}
</a>
<a href="#" class="cb-collapse"
onclick="$(this).closest('table').addClass('cb-collapsed'); updateSticky(); return false;">${_('Hide them')}
</a>
</td>
</tr>
<tr class="cb-warning cb-collapser">
<td class="cb-text" ${(c.user_session_attrs["diffmode"] == 'unified' and 'colspan=4' or 'colspan=6')}>
${_('This diff has been collapsed as it changes many lines, (%i lines changed)' % lines_changed)}
<a href="#" class="cb-expand"
onclick="$(this).closest('table').removeClass('cb-collapsed'); updateSticky(); return false;">${_('Show them')}
</a>
<a href="#" class="cb-collapse"
onclick="$(this).closest('table').addClass('cb-collapsed'); updateSticky(); return false;">${_('Hide them')}
</a>
</td>
</tr>
%endif
%endif

File diff suppressed because one or more lines are too long

View file

@ -20,12 +20,16 @@
import textwrap
import mock
import pytest
from rhodecode.lib.codeblocks import DiffSet
from rhodecode.lib.diffs import (
DiffProcessor,
NEW_FILENODE, DEL_FILENODE, MOD_FILENODE, RENAMED_FILENODE,
CHMOD_FILENODE, BIN_FILENODE, COPIED_FILENODE)
from rhodecode.lib.utils2 import AttributeDict
from rhodecode.lib.vcs.backends.git import GitCommit
from rhodecode.tests.fixture import Fixture, no_newline_id_generator
from rhodecode.lib.vcs.backends.git.repository import GitDiff
from rhodecode.lib.vcs.backends.hg.repository import MercurialDiff
@ -596,57 +600,6 @@ DIFF_FIXTURES = [
}),
]),
# TODO: mikhail: do we still need this?
# (
# 'hg',
# 'large_diff.diff',
# [
# ('.hgignore', 'A', {
# 'deleted': 0, 'binary': False, 'added': 3, 'ops': {
# 1: 'new file 100644'}}),
# (
# 'MANIFEST.in', 'A',
# {'deleted': 0, 'binary': False, 'added': 3, 'ops': {
# 1: 'new file 100644'}}),
# (
# 'README.txt', 'A',
# {'deleted': 0, 'binary': False, 'added': 19, 'ops': {
# 1: 'new file 100644'}}),
# (
# 'development.ini', 'A', {
# 'deleted': 0, 'binary': False, 'added': 116, 'ops': {
# 1: 'new file 100644'}}),
# (
# 'docs/index.txt', 'A', {
# 'deleted': 0, 'binary': False, 'added': 19, 'ops': {
# 1: 'new file 100644'}}),
# (
# 'ez_setup.py', 'A', {
# 'deleted': 0, 'binary': False, 'added': 276, 'ops': {
# 1: 'new file 100644'}}),
# (
# 'hgapp.py', 'A', {
# 'deleted': 0, 'binary': False, 'added': 26, 'ops': {
# 1: 'new file 100644'}}),
# (
# 'hgwebdir.config', 'A', {
# 'deleted': 0, 'binary': False, 'added': 21, 'ops': {
# 1: 'new file 100644'}}),
# (
# 'pylons_app.egg-info/PKG-INFO', 'A', {
# 'deleted': 0, 'binary': False, 'added': 10, 'ops': {
# 1: 'new file 100644'}}),
# (
# 'pylons_app.egg-info/SOURCES.txt', 'A', {
# 'deleted': 0, 'binary': False, 'added': 33, 'ops': {
# 1: 'new file 100644'}}),
# (
# 'pylons_app.egg-info/dependency_links.txt', 'A', {
# 'deleted': 0, 'binary': False, 'added': 1, 'ops': {
# 1: 'new file 100644'}}),
# ]
# ),
]
DIFF_FIXTURES_WITH_CONTENT = [
@ -804,6 +757,39 @@ def diff_fixture_w_content(request):
return diff, expected
def test_diff_over_limit(request):
diff_limit = 1024
file_limit = 1024
raw_diff = fixture.load_resource('large_diff.diff')
vcs_diff = GitDiff(raw_diff)
diff_processor = DiffProcessor(
vcs_diff, format='newdiff', diff_limit=diff_limit, file_limit=file_limit,
show_full_diff=False)
_parsed = diff_processor.prepare()
commit1 = GitCommit(repository=mock.Mock(), raw_id='abcdef12', idx=1)
commit2 = GitCommit(repository=mock.Mock(), raw_id='abcdef34', idx=2)
diffset = DiffSet(
repo_name='repo_name',
source_node_getter=lambda *a, **kw: AttributeDict({'commit': commit1}),
target_node_getter=lambda *a, **kw: AttributeDict({'commit': commit2})
)
diffset = diffset.render_patchset(_parsed, commit1, commit2)
assert len(diffset.files) == 2
assert diffset.limited_diff is True
assert diffset.files[0].patch['filename'] == 'example.go'
assert diffset.files[0].limited_diff is True
assert diffset.files[1].patch['filename'] == 'README.md'
assert diffset.files[1].limited_diff is False
def test_diff_lib_newlines(diff_fixture_w_content):
diff, expected_data = diff_fixture_w_content
diff_proc = DiffProcessor(diff)