# HG changeset patch # User Mads Kiilerich # Date 1506982480 -7200 # Node ID 791430c43bcab43d78b5ba706684da1a51cd3e95 # Parent 71a29042ab8afed4d8e27d150f2594a4bddd68f0 diffs: drop partially un-implemented udiff support - everything is now what formerly was known as gitdiff diff -r 71a29042ab8a -r 791430c43bca kallithea/controllers/changeset.py --- 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 @@ -276,7 +276,6 @@ diff_limit = None if c.fulldiff else self.cut_off_limit diff_processor = diffs.DiffProcessor(_diff, vcs=c.db_repo_scm_instance.alias, - format='gitdiff', diff_limit=diff_limit) file_diff_data = [] if method == 'show': diff -r 71a29042ab8a -r 791430c43bca kallithea/controllers/compare.py --- 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 @@ -271,8 +271,7 @@ ignore_whitespace=ignore_whitespace, context=line_context) - diff_processor = diffs.DiffProcessor(txtdiff or '', format='gitdiff', - diff_limit=diff_limit) + diff_processor = diffs.DiffProcessor(txtdiff or '', diff_limit=diff_limit) _parsed = diff_processor.prepare() c.limited_diff = False diff -r 71a29042ab8a -r 791430c43bca kallithea/controllers/files.py --- a/kallithea/controllers/files.py Tue Oct 03 00:14:40 2017 +0200 +++ b/kallithea/controllers/files.py Tue Oct 03 00:14:40 2017 +0200 @@ -654,7 +654,7 @@ _diff = diffs.get_gitdiff(node1, node2, ignore_whitespace=ignore_whitespace, context=line_context) - diff = diffs.DiffProcessor(_diff, format='gitdiff') + diff = diffs.DiffProcessor(_diff) diff_name = '%s_vs_%s.diff' % (diff1, diff2) response.content_type = 'text/plain' @@ -667,7 +667,7 @@ _diff = diffs.get_gitdiff(node1, node2, ignore_whitespace=ignore_whitespace, context=line_context) - diff = diffs.DiffProcessor(_diff, format='gitdiff') + diff = diffs.DiffProcessor(_diff) response.content_type = 'text/plain' return diff.as_raw() diff -r 71a29042ab8a -r 791430c43bca kallithea/controllers/pullrequests.py --- 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 @@ -597,8 +597,7 @@ context=line_context) except ChangesetDoesNotExistError: txtdiff = _("The diff can't be shown - the PR revisions could not be found.") - diff_processor = diffs.DiffProcessor(txtdiff or '', format='gitdiff', - diff_limit=diff_limit) + diff_processor = diffs.DiffProcessor(txtdiff or '', diff_limit=diff_limit) _parsed = diff_processor.prepare() c.limited_diff = False diff -r 71a29042ab8a -r 791430c43bca kallithea/lib/diffs.py --- 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 @@ -77,7 +77,7 @@ f_gitdiff = get_gitdiff(filenode_old, filenode_new, ignore_whitespace=ignore_whitespace, context=line_context) - diff_processor = DiffProcessor(f_gitdiff, format='gitdiff') + diff_processor = DiffProcessor(f_gitdiff) _parsed = diff_processor.prepare() if _parsed: # there should be exactly one element, for the specified file f = _parsed[0] @@ -206,11 +206,10 @@ _escape_re = re.compile(r'(&)|(<)|(>)|(\t)|(\r)|(?<=.)( \n| $)') - def __init__(self, diff, vcs='hg', format='gitdiff', diff_limit=None): + def __init__(self, diff, vcs='hg', diff_limit=None): """ :param diff: a text in diff format :param vcs: type of version control hg or git - :param format: format of diff passed, `udiff` or `gitdiff` :param diff_limit: define the size of diff that is considered "big" based on that parameter cut off will be triggered, set to None to show full diff @@ -219,7 +218,6 @@ raise Exception('Diff must be a basestring got %s instead' % type(diff)) self._diff = diff - self._format = format self.adds = 0 self.removes = 0 # calculate diff size @@ -230,13 +228,6 @@ self.parsed_diff = [] self.vcs = vcs - if format == 'gitdiff': - self.differ = self._highlight_line_difflib - self._parser = self._parse_gitdiff - else: - self.differ = self._highlight_line_udiff - self._parser = self._parse_udiff - def _escaper(self, string): """ Do HTML escaping/markup and check the diff limit @@ -266,7 +257,7 @@ return self._escape_re.sub(substitute, safe_unicode(string)) - def _highlight_line_difflib(self, old, new): + def _highlight_inline_diff(self, old, new): """ Highlight simple add/remove in two lines given as info dicts. They are modified in place and given markup with /. @@ -293,36 +284,6 @@ old['line'] = "".join(oldfragments) new['line'] = "".join(newfragments) - def _highlight_line_udiff(self, line, next_): - """ - Highlight inline changes in both lines. - """ - start = 0 - limit = min(len(line['line']), len(next_['line'])) - while start < limit and line['line'][start] == next_['line'][start]: - start += 1 - end = -1 - limit -= start - while -end <= limit and line['line'][end] == next_['line'][end]: - end -= 1 - end += 1 - if start or end: - def do(l): - last = end + len(l['line']) - if l['action'] == 'add': - tag = 'ins' - else: - tag = 'del' - l['line'] = '%s<%s>%s%s' % ( - l['line'][:start], - tag, - l['line'][start:last], - tag, - l['line'][last:] - ) - do(line) - do(next_) - def _get_header(self, diff_chunk): """ Parses a Git diff for a single file (header and chunks) and returns a tuple with: @@ -493,19 +454,16 @@ peekline = lineiter.next() except StopIteration: # add was last line - ok - self.differ(delline, addline) + self._highlight_inline_diff(delline, addline) raise if peekline['action'] != 'add': # there was only one add line - ok - self.differ(delline, addline) + self._highlight_inline_diff(delline, addline) except StopIteration: pass return diff_container(_files) - def _parse_udiff(self, inline_diff=True): - raise NotImplementedError() - def _parse_lines(self, diff): """ Given an iterator of diff body lines, parse them and return a dict per @@ -629,7 +587,7 @@ Prepare the passed udiff for HTML rendering. It'll return a list of dicts with diff information """ - parsed = self._parser(inline_diff=inline_diff) + parsed = self._parse_gitdiff(inline_diff=inline_diff) self.parsed = True self.parsed_diff = parsed return parsed