OLD | NEW |
1 # coding=utf8 | 1 # coding=utf8 |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 311 |
312 def mangle(self, string): | 312 def mangle(self, string): |
313 """Mangle a file path.""" | 313 """Mangle a file path.""" |
314 return '/'.join(string.replace('\\', '/').split('/')[self.patchlevel:]) | 314 return '/'.join(string.replace('\\', '/').split('/')[self.patchlevel:]) |
315 | 315 |
316 def _verify_git_header(self): | 316 def _verify_git_header(self): |
317 """Sanity checks the header. | 317 """Sanity checks the header. |
318 | 318 |
319 Expects the following format: | 319 Expects the following format: |
320 | 320 |
321 <garbagge> | 321 <garbage> |
322 diff --git (|a/)<filename> (|b/)<filename> | 322 diff --git (|a/)<filename> (|b/)<filename> |
323 <similarity> | 323 <similarity> |
324 <filemode changes> | 324 <filemode changes> |
325 <index> | 325 <index> |
326 <copy|rename from> | 326 <copy|rename from> |
327 <copy|rename to> | 327 <copy|rename to> |
328 --- <filename> | 328 --- <filename> |
329 +++ <filename> | 329 +++ <filename> |
330 | 330 |
331 Everything is optional except the diff --git line. | 331 Everything is optional except the diff --git line. |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 def __iter__(self): | 534 def __iter__(self): |
535 for patch in self.patches: | 535 for patch in self.patches: |
536 yield patch | 536 yield patch |
537 | 537 |
538 def __getitem__(self, key): | 538 def __getitem__(self, key): |
539 return self.patches[key] | 539 return self.patches[key] |
540 | 540 |
541 @property | 541 @property |
542 def filenames(self): | 542 def filenames(self): |
543 return [p.filename for p in self.patches] | 543 return [p.filename for p in self.patches] |
OLD | NEW |