Edgewall Software

Ticket #1054: Diff.py.2.diff

File Diff.py.2.diff, 2.7 KB (added by anonymous, 4 years ago)

re-attach the diff from svn repository

  • trac/Diff.py

     
    2222import re 
    2323from util import add_to_hdf, escape 
    2424 
    25 line_re = re.compile('@@ [+-]([0-9]+),([0-9]+) [+-]([0-9]+),([0-9]+) @@') 
     25line_re = re.compile('^@@ [+-]([0-9]+),([0-9]+) [+-]([0-9]+),([0-9]+) @@') 
    2626space_re = re.compile(' ( +)|^ ') 
    2727 
    2828 
     
    3939        self.blockno = 0 
    4040        self.offset_base = 0 
    4141        self.offset_changed = 0 
     42        self.lines_base = 0 
     43        self.lines_changed = 0 
    4244 
    4345    def _escape(self, text): 
    4446        return space_re.sub(lambda m: 
     
    9193        self.blockno += 1 
    9294 
    9395    def writeline(self, text): 
    94         if text[0:2] in ['++', '--']: 
    95             return 
    96         match = line_re.search(text) 
    97         if match: 
    98             self.print_block() 
    99             self.changeno += 1 
    100             self.blockno = 0 
    101             self.offset_base = int(match.group(1)) - 1 
    102             self.offset_changed = int(match.group(3)) - 1 
    103             return 
    104         ttype = text[0] 
    105         text = text[1:] 
    106         text = text.expandtabs(self.tabwidth) 
    107         if ttype == self.ttype: 
    108             self.block.append(text) 
     96        if self.lines_base == 0 and self.lines_changed == 0: 
     97            match = line_re.search(text) 
     98            if match: 
     99                self.print_block() 
     100                self.changeno += 1 
     101                self.blockno = 0 
     102                self.offset_base = int(match.group(1)) - 1 
     103                self.offset_changed = int(match.group(3)) - 1 
     104                self.lines_base = int(match.group(2)) 
     105                self.lines_changed = int(match.group(4)) 
     106                return 
    109107        else: 
    110             if ttype == '+' and self.ttype == '-': 
    111                 self.p_block = self.block 
    112                 self.p_type = self.ttype 
     108            ttype = text[0] 
     109            text = text[1:] 
     110            text = text.expandtabs(self.tabwidth) 
     111            if ttype == self.ttype: 
     112                self.block.append(text) 
    113113            else: 
    114                 self.print_block() 
    115             self.block = [text] 
    116             self.ttype = ttype 
     114                if ttype == '+' and self.ttype == '-': 
     115                    self.p_block = self.block 
     116                    self.p_type = self.ttype 
     117                else: 
     118                    self.print_block() 
     119                self.block = [text] 
     120                self.ttype = ttype 
     121            if ttype == '+': 
     122                self.lines_changed -= 1 
     123            elif ttype == '-': 
     124                self.lines_base -= 1 
     125            else: 
     126                self.lines_base -= 1 
     127                self.lines_changed -= 1 
    117128 
    118129    def close(self): 
    119130        self.print_block()