git @ Cat's Eye Technologies klaus / 1c234b9
Fix #113: Fix whitespace in filenames in diff The 'diff.py' module used to parse unified diff lines like +++ a/foo/bar /spam/eggs as "/foo/bar" i.e. stripping anything behind whitespace. This is because it tried to recognize the part after whitespace as a commit revision id. As dulwich never uses the latter, I simply removed that feature. Whitespace isn't special-cased anymore now. Jonas Haag 10 years ago
1 changed file(s) with 12 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
2626 """:param udiff: a text in udiff format"""
2727 self.lines = [escape(line) for line in udiff.splitlines()]
2828
29 def _extract_rev(self, line1, line2):
30 def _extract(line):
31 parts = line.split(None, 1)
32 if parts[0].startswith(('a/', 'b/')):
33 parts[0] = parts[0][2:]
34 return parts[0], (len(parts) == 2 and parts[1] or None)
35 try:
36 if line1.startswith('--- ') and line2.startswith('+++ '):
37 return _extract(line1[4:]), _extract(line2[4:])
38 except (ValueError, IndexError):
39 pass
40 return (None, None), (None, None)
29 def _extract_filename(self, line):
30 """
31 Extract file name from unified diff line:
32 --- a/foo/bar ==> foo/bar
33 +++ b/foo/bar ==> foo/bar
34 """
35 if line.startswith(("--- /dev/null", "+++ /dev/null")):
36 return line[len("--- "):]
37 else:
38 return line[len("--- a/"):]
4139
4240 def _highlight_line(self, line, next):
4341 """Highlight inline changes in both lines."""
9088
9189 in_header = False
9290 chunks = []
93 old, new = self._extract_rev(line, lineiter.next())
9491 adds, dels = 0, 0
9592 files.append({
9693 'is_header': False,
97 'old_filename': old[0],
98 'old_revision': old[1],
99 'new_filename': new[0],
100 'new_revision': new[1],
94 'old_filename': self._extract_filename(line),
95 'new_filename': self._extract_filename(lineiter.next()),
10196 'additions': adds,
10297 'deletions': dels,
10398 'chunks': chunks