| OLD | NEW |
| 1 # coding=utf8 | 1 # coding=utf8 |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 """Utility functions to handle patches.""" | 5 """Utility functions to handle patches.""" |
| 6 | 6 |
| 7 import posixpath | 7 import posixpath |
| 8 import os | 8 import os |
| 9 import re | 9 import re |
| 10 | 10 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 def __init__(self, filename, diff, svn_properties): | 90 def __init__(self, filename, diff, svn_properties): |
| 91 super(FilePatchDiff, self).__init__(filename) | 91 super(FilePatchDiff, self).__init__(filename) |
| 92 if not diff: | 92 if not diff: |
| 93 self._fail('File doesn\'t have a diff.') | 93 self._fail('File doesn\'t have a diff.') |
| 94 self.diff_header, self.diff_hunks = self._split_header(diff) | 94 self.diff_header, self.diff_hunks = self._split_header(diff) |
| 95 self.svn_properties = svn_properties or [] | 95 self.svn_properties = svn_properties or [] |
| 96 self.is_git_diff = self._is_git_diff_header(self.diff_header) | 96 self.is_git_diff = self._is_git_diff_header(self.diff_header) |
| 97 self.patchlevel = 0 | 97 self.patchlevel = 0 |
| 98 if self.is_git_diff: | 98 if self.is_git_diff: |
| 99 self._verify_git_header() | 99 self._verify_git_header() |
| 100 assert not svn_properties | |
| 101 else: | 100 else: |
| 102 self._verify_svn_header() | 101 self._verify_svn_header() |
| 103 | 102 |
| 104 def get(self): | 103 def get(self): |
| 105 return self.diff_header + self.diff_hunks | 104 return self.diff_header + self.diff_hunks |
| 106 | 105 |
| 107 def set_relpath(self, relpath): | 106 def set_relpath(self, relpath): |
| 108 old_filename = self.filename | 107 old_filename = self.filename |
| 109 super(FilePatchDiff, self).set_relpath(relpath) | 108 super(FilePatchDiff, self).set_relpath(relpath) |
| 110 # Update the header too. | 109 # Update the header too. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 if new not in (self.filename, 'dev/null'): | 189 if new not in (self.filename, 'dev/null'): |
| 191 self._fail('Unexpected git diff output name %s.' % new) | 190 self._fail('Unexpected git diff output name %s.' % new) |
| 192 if old == 'dev/null' and new == 'dev/null': | 191 if old == 'dev/null' and new == 'dev/null': |
| 193 self._fail('Unexpected /dev/null git diff.') | 192 self._fail('Unexpected /dev/null git diff.') |
| 194 break | 193 break |
| 195 | 194 |
| 196 if not old or not new: | 195 if not old or not new: |
| 197 self._fail('Unexpected git diff; couldn\'t find git header.') | 196 self._fail('Unexpected git diff; couldn\'t find git header.') |
| 198 | 197 |
| 199 # Handle these: | 198 # Handle these: |
| 199 # new file mode \d{6} |
| 200 # rename from <> | 200 # rename from <> |
| 201 # rename to <> | 201 # rename to <> |
| 202 # copy from <> | 202 # copy from <> |
| 203 # copy to <> | 203 # copy to <> |
| 204 while lines: | 204 while lines: |
| 205 if lines[0].startswith('--- '): | 205 if lines[0].startswith('--- '): |
| 206 break | 206 break |
| 207 match = re.match(r'^(rename|copy) from (.+)$', lines.pop(0)) | 207 line = lines.pop(0) |
| 208 if not match: | 208 match = re.match(r'^(rename|copy) from (.+)$', line) |
| 209 if match: |
| 210 if old != match.group(2): |
| 211 self._fail('Unexpected git diff input name for %s.' % match.group(1)) |
| 212 if not lines: |
| 213 self._fail('Missing git diff output name for %s.' % match.group(1)) |
| 214 match = re.match(r'^(rename|copy) to (.+)$', lines.pop(0)) |
| 215 if not match: |
| 216 self._fail('Missing git diff output name for %s.' % match.group(1)) |
| 217 if new != match.group(2): |
| 218 self._fail('Unexpected git diff output name for %s.' % match.group(1)) |
| 209 continue | 219 continue |
| 210 if old != match.group(2): | 220 |
| 211 self._fail('Unexpected git diff input name for %s.' % match.group(1)) | 221 match = re.match(r'^new file mode (\d{6})$', line) |
| 212 if not lines: | 222 if match: |
| 213 self._fail('Missing git diff output name for %s.' % match.group(1)) | 223 mode = match.group(1) |
| 214 match = re.match(r'^(rename|copy) to (.+)$', lines.pop(0)) | 224 # Only look at owner ACL for executable. |
| 215 if not match: | 225 if bool(int(mode[4]) & 4): |
| 216 self._fail('Missing git diff output name for %s.' % match.group(1)) | 226 self.svn_properties.append(('svn:executable', '*')) |
| 217 if new != match.group(2): | |
| 218 self._fail('Unexpected git diff output name for %s.' % match.group(1)) | |
| 219 | 227 |
| 220 # Handle ---/+++ | 228 # Handle ---/+++ |
| 221 while lines: | 229 while lines: |
| 222 match = re.match(r'^--- (.*)$', lines.pop(0)) | 230 match = re.match(r'^--- (.*)$', lines.pop(0)) |
| 223 if not match: | 231 if not match: |
| 224 continue | 232 continue |
| 225 if old != self.mangle(match.group(1)) and match.group(1) != '/dev/null': | 233 if old != self.mangle(match.group(1)) and match.group(1) != '/dev/null': |
| 226 self._fail('Unexpected git diff: %s != %s.' % (old, match.group(1))) | 234 self._fail('Unexpected git diff: %s != %s.' % (old, match.group(1))) |
| 227 if not lines: | 235 if not lines: |
| 228 self._fail('Missing git diff output name.') | 236 self._fail('Missing git diff output name.') |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 for patch in self.patches: | 289 for patch in self.patches: |
| 282 patch.set_relpath(relpath) | 290 patch.set_relpath(relpath) |
| 283 | 291 |
| 284 def __iter__(self): | 292 def __iter__(self): |
| 285 for patch in self.patches: | 293 for patch in self.patches: |
| 286 yield patch | 294 yield patch |
| 287 | 295 |
| 288 @property | 296 @property |
| 289 def filenames(self): | 297 def filenames(self): |
| 290 return [p.filename for p in self.patches] | 298 return [p.filename for p in self.patches] |
| OLD | NEW |