Ticket #1054: Diff.py.2.diff
| File Diff.py.2.diff, 2.7 KB (added by anonymous, 4 years ago) |
|---|
-
trac/Diff.py
22 22 import re 23 23 from util import add_to_hdf, escape 24 24 25 line_re = re.compile(' @@ [+-]([0-9]+),([0-9]+) [+-]([0-9]+),([0-9]+) @@')25 line_re = re.compile('^@@ [+-]([0-9]+),([0-9]+) [+-]([0-9]+),([0-9]+) @@') 26 26 space_re = re.compile(' ( +)|^ ') 27 27 28 28 … … 39 39 self.blockno = 0 40 40 self.offset_base = 0 41 41 self.offset_changed = 0 42 self.lines_base = 0 43 self.lines_changed = 0 42 44 43 45 def _escape(self, text): 44 46 return space_re.sub(lambda m: … … 91 93 self.blockno += 1 92 94 93 95 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 109 107 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) 113 113 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 117 128 118 129 def close(self): 119 130 self.print_block()
