Changeset - 5fe0f744bec0
[Not reviewed]
beta
0 1 0
Marcin Kuzminski - 13 years ago 2012-07-06 20:29:36
marcin@python-works.com
fixed issue #492 missing `\ No newline at end of file` test at the end of new chunk
in html diff
1 file changed with 18 insertions and 10 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/diffs.py
Show inline comments
 
@@ -131,12 +131,13 @@ class DiffProcessor(object):
 
    """
 
    Give it a unified diff and it returns a list of the files that were
 
    mentioned in the diff together with a dict of meta information that
 
    can be used to render it in a HTML template.
 
    """
 
    _chunk_re = re.compile(r'@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)')
 
    _newline_marker = '\\ No newline at end of file\n'
 

	
 
    def __init__(self, diff, differ='diff', format='gitdiff'):
 
        """
 
        :param diff:   a text in diff format or generator
 
        :param format: format of diff passed, `udiff` or `gitdiff`
 
        """
 
@@ -342,17 +343,23 @@ class DiffProcessor(object):
 
                                'new_lineno': '...',
 
                                'action':     'context',
 
                                'line':       line,
 
                            })
 

	
 
                    line = lineiter.next()
 

	
 
                    while old_line < old_end or new_line < new_end:
 
                        if line:
 
                            command, line = line[0], line[1:]
 
                            command = line[0]
 
                            if command in ['+', '-', ' ']:
 
                                #only modify the line if it's actually a diff
 
                                # thing
 
                                line = line[1:]
 
                        else:
 
                            command = ' '
 

	
 
                        affects_old = affects_new = False
 

	
 
                        # ignore those if we don't expect them
 
                        if command in '#@':
 
                            continue
 
                        elif command == '+':
 
@@ -364,31 +371,32 @@ class DiffProcessor(object):
 
                            action = 'del'
 
                            stats[1] += 1
 
                        else:
 
                            affects_old = affects_new = True
 
                            action = 'unmod'
 

	
 
                        if line.find('No newline at end of file') != -1:
 
                            lines.append({
 
                                'old_lineno':   '...',
 
                                'new_lineno':   '...',
 
                                'action':       'context',
 
                                'line':         line
 
                            })
 

	
 
                        else:
 
                        if line != self._newline_marker:
 
                            old_line += affects_old
 
                            new_line += affects_new
 
                            lines.append({
 
                                'old_lineno':   affects_old and old_line or '',
 
                                'new_lineno':   affects_new and new_line or '',
 
                                'action':       action,
 
                                'line':         line
 
                            })
 

	
 
                        line = lineiter.next()
 
                        if line == self._newline_marker:
 
                            # we need to append to lines, since this is not
 
                            # counted in the line specs of diff
 
                            lines.append({
 
                                'old_lineno':   '...',
 
                                'new_lineno':   '...',
 
                                'action':       'context',
 
                                'line':         line
 
                            })
 

	
 
        except StopIteration:
 
            pass
 

	
 
        sorter = lambda info: {'A': 0, 'M': 1, 'D': 2}.get(info['operation'])
 
        if inline_diff is False:
0 comments (0 inline, 0 general)