| 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 | 239 |
| 240 A svn diff can contain only property changes, in that case there will be no | 240 A svn diff can contain only property changes, in that case there will be no |
| 241 proper header. To make things worse, this property change header is | 241 proper header. To make things worse, this property change header is |
| 242 localized. | 242 localized. |
| 243 """ | 243 """ |
| 244 lines = self.diff_header.splitlines() | 244 lines = self.diff_header.splitlines() |
| 245 while lines: | 245 while lines: |
| 246 match = re.match(r'^--- ([^\t]+).*$', lines.pop(0)) | 246 match = re.match(r'^--- ([^\t]+).*$', lines.pop(0)) |
| 247 if not match: | 247 if not match: |
| 248 continue | 248 continue |
| 249 if match.group(1) not in (self.filename, '/dev/null'): | 249 # For copy and renames, it's possible that the -- line doesn't match +++, |
| 250 self._fail('Unexpected diff: %s.' % match.group(1)) | 250 # so don't check match.group(1) to match self.filename or '/dev/null', it |
| 251 # can be anything else. |
| 252 # TODO(maruel): Handle rename/copy explicitly. |
| 253 # if match.group(1) not in (self.filename, '/dev/null'): |
| 254 # self.source_file = match.group(1) |
| 255 if not lines: |
| 256 self._fail('Nothing after header.') |
| 251 match = re.match(r'^\+\+\+ ([^\t]+).*$', lines.pop(0)) | 257 match = re.match(r'^\+\+\+ ([^\t]+).*$', lines.pop(0)) |
| 252 if not match: | 258 if not match: |
| 253 self._fail('Unexpected diff: --- not following +++.') | 259 self._fail('Unexpected diff: --- not following +++.') |
| 254 if match.group(1) not in (self.filename, '/dev/null'): | 260 if match.group(1) not in (self.filename, '/dev/null'): |
| 255 self._fail('Unexpected diff: %s.' % match.group(1)) | 261 self._fail('Unexpected diff: %s.' % match.group(1)) |
| 256 assert not lines, '_split_header() is broken' | 262 assert not lines, '_split_header() is broken' |
| 257 break | 263 break |
| 258 else: | 264 else: |
| 259 # Cheap check to make sure the file name is at least mentioned in the | 265 # Cheap check to make sure the file name is at least mentioned in the |
| 260 # 'diff' header. That the only remaining invariant. | 266 # 'diff' header. That the only remaining invariant. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 273 for patch in self.patches: | 279 for patch in self.patches: |
| 274 patch.set_relpath(relpath) | 280 patch.set_relpath(relpath) |
| 275 | 281 |
| 276 def __iter__(self): | 282 def __iter__(self): |
| 277 for patch in self.patches: | 283 for patch in self.patches: |
| 278 yield patch | 284 yield patch |
| 279 | 285 |
| 280 @property | 286 @property |
| 281 def filenames(self): | 287 def filenames(self): |
| 282 return [p.filename for p in self.patches] | 288 return [p.filename for p in self.patches] |
| OLD | NEW |