| OLD | NEW |
| (Empty) | |
| 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 """Utility functions to handle patches.""" |
| 5 |
| 6 import re |
| 7 import subprocess2 |
| 8 |
| 9 |
| 10 def auto_mangle_git_patch(patch): |
| 11 """Mangles a patch and automatically strip out git decoration.""" |
| 12 # Git patches have a/ at the beginning of source paths. We strip that out |
| 13 # with a regexp rather than the -p flag to patch so we can feed either Git |
| 14 # or svn-style patches into the same apply command. re.sub() should be used |
| 15 # but flags=re.MULTILINE is only in python 2.7. |
| 16 out = [] |
| 17 for line in patch.splitlines(True): |
| 18 # TODO: It should just process the header lines. |
| 19 out.append(re.sub(r'^--- a/', r'--- ', |
| 20 re.sub(r'^\+\+\+ b/', r'+++ ', line))) |
| 21 return ''.join(out) |
| 22 |
| 23 |
| 24 def apply_patch(location, patch): |
| 25 """Applies a svn patch, manually applying svn meta data.""" |
| 26 # TODO: Do not shell out patch to enable svn cp/mv/ren and friends |
| 27 # TODO: Add binary support |
| 28 # TODO: Reuse some webkit svn-apply stuff? |
| 29 cmd = ['patch', '-p0', '--forward', '--force'] |
| 30 subprocess2.check_call(cmd, stdin=patch, cwd=location) |
| 31 |
| OLD | NEW |