Changeset - 791430c43bca
[Not reviewed]
default
0 5 0
Mads Kiilerich - 8 years ago 2017-10-03 00:14:40
mads@kiilerich.com
diffs: drop partially un-implemented udiff support - everything is now what formerly was known as gitdiff
5 files changed with 10 insertions and 55 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/changeset.py
Show inline comments
 
@@ -276,7 +276,6 @@ class ChangesetController(BaseRepoContro
 
            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':
kallithea/controllers/compare.py
Show inline comments
 
@@ -271,8 +271,7 @@ class CompareController(BaseRepoControll
 
                                      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
kallithea/controllers/files.py
Show inline comments
 
@@ -654,7 +654,7 @@ class FilesController(BaseRepoController
 
            _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 @@ class FilesController(BaseRepoController
 
            _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()
 

	
kallithea/controllers/pullrequests.py
Show inline comments
 
@@ -597,8 +597,7 @@ class PullrequestsController(BaseRepoCon
 
                                                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
kallithea/lib/diffs.py
Show inline comments
 
@@ -77,7 +77,7 @@ def wrapped_diff(filenode_old, filenode_
 
        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 @@ class DiffProcessor(object):
 

	
 
    _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 @@ class DiffProcessor(object):
 
            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 @@ class DiffProcessor(object):
 
        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 @@ class DiffProcessor(object):
 

	
 
        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 <del>/<ins>.
 
@@ -293,36 +284,6 @@ class DiffProcessor(object):
 
        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>%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 @@ class DiffProcessor(object):
 
                            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 @@ class DiffProcessor(object):
 
        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
0 comments (0 inline, 0 general)