##// END OF EJS Templates
py3: use s.startswith() instead of s[n] while parsing patches...
Yuya Nishihara -
r37489:51d5e1ff default
parent child Browse files
Show More
@@ -171,6 +171,7 b' test-http-bundle1.t'
171 171 test-http-clone-r.t
172 172 test-identify.t
173 173 test-import-unknown.t
174 test-import.t
174 175 test-imports-checker.t
175 176 test-inherit-mode.t
176 177 test-issue1089.t
@@ -60,10 +60,10 b' PatchError = error.PatchError'
60 60 def split(stream):
61 61 '''return an iterator of individual patches from a stream'''
62 62 def isheader(line, inheader):
63 if inheader and line[0] in (' ', '\t'):
63 if inheader and line.startswith((' ', '\t')):
64 64 # continuation
65 65 return True
66 if line[0] in (' ', '-', '+'):
66 if line.startswith((' ', '-', '+')):
67 67 # diff line - don't check for header pattern in there
68 68 return False
69 69 l = line.split(': ', 1)
@@ -1391,13 +1391,13 b' class hunk(object):'
1391 1391 hlen = len(self.hunk)
1392 1392 for x in xrange(hlen - 1):
1393 1393 # the hunk starts with the @@ line, so use x+1
1394 if self.hunk[x + 1][0] == ' ':
1394 if self.hunk[x + 1].startswith(' '):
1395 1395 top += 1
1396 1396 else:
1397 1397 break
1398 1398 if not toponly:
1399 1399 for x in xrange(hlen - 1):
1400 if self.hunk[hlen - bot - 1][0] == ' ':
1400 if self.hunk[hlen - bot - 1].startswith(' '):
1401 1401 bot += 1
1402 1402 else:
1403 1403 break
@@ -1799,10 +1799,12 b' def scanpatch(fp):'
1799 1799 else:
1800 1800 lr.push(fromfile)
1801 1801 yield 'file', header
1802 elif line[0:1] == ' ':
1803 yield 'context', scanwhile(line, lambda l: l[0] in ' \\')
1804 elif line[0] in '-+':
1805 yield 'hunk', scanwhile(line, lambda l: l[0] in '-+\\')
1802 elif line.startswith(' '):
1803 cs = (' ', '\\')
1804 yield 'context', scanwhile(line, lambda l: l.startswith(cs))
1805 elif line.startswith(('-', '+')):
1806 cs = ('-', '+', '\\')
1807 yield 'hunk', scanwhile(line, lambda l: l.startswith(cs))
1806 1808 else:
1807 1809 m = lines_re.match(line)
1808 1810 if m:
@@ -2504,11 +2506,11 b' def difflabel(func, *args, **kw):'
2504 2506 if line.startswith('@'):
2505 2507 head = False
2506 2508 else:
2507 if line and line[0] not in ' +-@\\':
2509 if line and not line.startswith((' ', '+', '-', '@', '\\')):
2508 2510 head = True
2509 2511 stripline = line
2510 2512 diffline = False
2511 if not head and line and line[0] in '+-':
2513 if not head and line and line.startswith(('+', '-')):
2512 2514 # highlight tabs and trailing whitespace, but only in
2513 2515 # changed lines
2514 2516 stripline = line.rstrip()
@@ -2548,15 +2550,15 b' def _findmatches(slist):'
2548 2550 for i, line in enumerate(slist):
2549 2551 if line == '':
2550 2552 continue
2551 if line[0] == '-':
2553 if line.startswith('-'):
2552 2554 lastmatch = max(lastmatch, i)
2553 2555 newgroup = False
2554 2556 for j, newline in enumerate(slist[lastmatch + 1:]):
2555 2557 if newline == '':
2556 2558 continue
2557 if newline[0] == '-' and newgroup: # too far, no match
2559 if newline.startswith('-') and newgroup: # too far, no match
2558 2560 break
2559 if newline[0] == '+': # potential match
2561 if newline.startswith('+'): # potential match
2560 2562 newgroup = True
2561 2563 sim = difflib.SequenceMatcher(None, line, newline).ratio()
2562 2564 if sim > 0.7:
@@ -2568,7 +2570,7 b' def _findmatches(slist):'
2568 2570
2569 2571 def _inlinediff(s1, s2, operation):
2570 2572 '''Perform string diff to highlight specific changes.'''
2571 operation_skip = '+?' if operation == 'diff.deleted' else '-?'
2573 operation_skip = ('+', '?') if operation == 'diff.deleted' else ('-', '?')
2572 2574 if operation == 'diff.deleted':
2573 2575 s2, s1 = s1, s2
2574 2576
@@ -2590,10 +2592,10 b' def _inlinediff(s1, s2, operation):'
2590 2592
2591 2593 s = difflib.ndiff(_nonwordre.split(s2), _nonwordre.split(s1))
2592 2594 for part in s:
2593 if part[0] in operation_skip or len(part) == 2:
2595 if part.startswith(operation_skip) or len(part) == 2:
2594 2596 continue
2595 2597 l = operation + '.highlight'
2596 if part[0] in ' ':
2598 if part.startswith(' '):
2597 2599 l = operation
2598 2600 if part[2:] == '\t':
2599 2601 l = 'diff.tab'
General Comments 0
You need to be logged in to leave comments. Login now