Mercurial > kallithea
changeset 6914:e85f08375dc6
diffs: drop the DiffLimitExceeded container - just make it a flag available as property
Keep it simple.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Tue, 03 Oct 2017 00:14:40 +0200 |
parents | 24a9bec8138c |
children | 52e756b40a2b |
files | kallithea/controllers/changeset.py kallithea/controllers/compare.py kallithea/controllers/feed.py kallithea/controllers/pullrequests.py kallithea/lib/diffs.py |
diffstat | 5 files changed, 10 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/controllers/changeset.py Tue Oct 03 00:14:40 2017 +0200 +++ b/kallithea/controllers/changeset.py Tue Oct 03 00:14:40 2017 +0200 @@ -48,7 +48,6 @@ from kallithea.model.changeset_status import ChangesetStatusModel from kallithea.model.meta import Session from kallithea.model.repo import RepoModel -from kallithea.lib.diffs import LimitedDiffContainer from kallithea.lib.exceptions import StatusChangeOnClosedPullRequestError from kallithea.lib.vcs.backends.base import EmptyChangeset from kallithea.lib.utils2 import safe_unicode @@ -279,9 +278,7 @@ diff_processor = diffs.DiffProcessor(raw_diff, vcs=c.db_repo_scm_instance.alias, diff_limit=diff_limit) - c.limited_diff = False - if isinstance(diff_processor.parsed, LimitedDiffContainer): - c.limited_diff = True + c.limited_diff = diff_processor.limited_diff for f in diff_processor.parsed: st = f['stats'] c.lines_added += st['added']
--- a/kallithea/controllers/compare.py Tue Oct 03 00:14:40 2017 +0200 +++ b/kallithea/controllers/compare.py Tue Oct 03 00:14:40 2017 +0200 @@ -42,7 +42,6 @@ from kallithea.lib.auth import LoginRequired, HasRepoPermissionLevelDecorator 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 @@ -272,11 +271,7 @@ context=line_context) diff_processor = diffs.DiffProcessor(raw_diff or '', diff_limit=diff_limit) - - c.limited_diff = False - if isinstance(diff_processor.parsed, LimitedDiffContainer): - c.limited_diff = True - + c.limited_diff = diff_processor.limited_diff c.file_diff_data = [] c.lines_added = 0 c.lines_deleted = 0
--- a/kallithea/controllers/feed.py Tue Oct 03 00:14:40 2017 +0200 +++ b/kallithea/controllers/feed.py Tue Oct 03 00:14:40 2017 +0200 @@ -38,7 +38,7 @@ from kallithea.lib import helpers as h from kallithea.lib.auth import LoginRequired, HasRepoPermissionLevelDecorator from kallithea.lib.base import BaseRepoController -from kallithea.lib.diffs import DiffProcessor, LimitedDiffContainer +from kallithea.lib.diffs import DiffProcessor from kallithea.model.db import CacheInvalidation from kallithea.lib.utils2 import safe_int, str2bool, safe_unicode @@ -76,9 +76,6 @@ diff_processor = DiffProcessor(raw_diff, diff_limit=diff_limit, inline_diff=False) - limited_diff = False - if isinstance(diff_processor.parsed, LimitedDiffContainer): - limited_diff = True for st in diff_processor.parsed: st.update({'added': st['stats']['added'], @@ -86,7 +83,7 @@ changes.append('\n %(operation)s %(filename)s ' '(%(added)s lines added, %(removed)s lines removed)' % st) - if limited_diff: + if diff_processor.limited_diff: changes = changes + ['\n ' + _('Changeset was too big and was cut off...')]
--- a/kallithea/controllers/pullrequests.py Tue Oct 03 00:14:40 2017 +0200 +++ b/kallithea/controllers/pullrequests.py Tue Oct 03 00:14:40 2017 +0200 @@ -39,7 +39,6 @@ from kallithea.lib.auth import LoginRequired, HasRepoPermissionLevelDecorator, \ NotAnonymous from kallithea.lib.base import BaseRepoController, render, jsonify -from kallithea.lib.diffs import LimitedDiffContainer from kallithea.lib.page import Page from kallithea.lib.utils import action_logger from kallithea.lib.vcs.exceptions import EmptyRepositoryError, ChangesetDoesNotExistError @@ -598,11 +597,7 @@ except ChangesetDoesNotExistError: raw_diff = _("The diff can't be shown - the PR revisions could not be found.") diff_processor = diffs.DiffProcessor(raw_diff or '', diff_limit=diff_limit) - - c.limited_diff = False - if isinstance(diff_processor.parsed, LimitedDiffContainer): - c.limited_diff = True - + c.limited_diff = diff_processor.limited_diff c.file_diff_data = [] c.lines_added = 0 c.lines_deleted = 0
--- a/kallithea/lib/diffs.py Tue Oct 03 00:14:40 2017 +0200 +++ b/kallithea/lib/diffs.py Tue Oct 03 00:14:40 2017 +0200 @@ -141,18 +141,6 @@ pass -class LimitedDiffContainer(object): - - def __init__(self, diff_limit, cur_diff_size, diff): - self.diff = diff - self.diff_limit = diff_limit - self.cur_diff_size = cur_diff_size - - def __iter__(self): - for l in self.diff: - yield l - - class DiffProcessor(object): """ Give it a unified or git diff and it returns a list of the files that were @@ -219,6 +207,7 @@ # calculate diff size self.diff_limit = diff_limit self.cur_diff_size = 0 + self.limited_diff = False self.vcs = vcs self.parsed = self._parse_gitdiff(inline_diff=inline_diff) @@ -306,11 +295,10 @@ def _parse_gitdiff(self, inline_diff): """Parse self._diff and return a list of dicts with meta info and chunks for each file. - If diff is truncated, wrap it in LimitedDiffContainer. + Might set limited_diff. Optionally, do an extra pass and to extra markup of one-liner changes. """ _files = [] # list of dicts with meta info and chunks - diff_container = lambda arg: arg starts = [m.start() for m in self._diff_git_re.finditer(self._diff)] starts.append(len(self._diff)) @@ -385,9 +373,7 @@ stats['ops'][MOD_FILENODE] = 'modified file' except DiffLimitExceeded: - diff_container = lambda _diff: \ - LimitedDiffContainer(self.diff_limit, - self.cur_diff_size, _diff) + self.limited_diff = True break else: # Git binary patch (or empty diff) # Git binary patch @@ -419,7 +405,7 @@ }) if not inline_diff: - return diff_container(_files) + return _files # highlight inline changes when one del is followed by one add for diff_data in _files: @@ -452,7 +438,7 @@ except StopIteration: pass - return diff_container(_files) + return _files def _parse_lines(self, diff_lines): """