| Index: patch.py
|
| diff --git a/patch.py b/patch.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..af18ee43e212583815d27d138d1fc426883eb663
|
| --- /dev/null
|
| +++ b/patch.py
|
| @@ -0,0 +1,31 @@
|
| +# Copyright (c) 2010 The Chromium Authors. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +"""Utility functions to handle patches."""
|
| +
|
| +import re
|
| +import subprocess2
|
| +
|
| +
|
| +def auto_mangle_git_patch(patch):
|
| + """Mangles a patch and automatically strip out git decoration."""
|
| + # Git patches have a/ at the beginning of source paths. We strip that out
|
| + # with a regexp rather than the -p flag to patch so we can feed either Git
|
| + # or svn-style patches into the same apply command. re.sub() should be used
|
| + # but flags=re.MULTILINE is only in python 2.7.
|
| + out = []
|
| + for line in patch.splitlines(True):
|
| + # TODO: It should just process the header lines.
|
| + out.append(re.sub(r'^--- a/', r'--- ',
|
| + re.sub(r'^\+\+\+ b/', r'+++ ', line)))
|
| + return ''.join(out)
|
| +
|
| +
|
| +def apply_patch(location, patch):
|
| + """Applies a svn patch, manually applying svn meta data."""
|
| + # TODO: Do not shell out patch to enable svn cp/mv/ren and friends
|
| + # TODO: Add binary support
|
| + # TODO: Reuse some webkit svn-apply stuff?
|
| + cmd = ['patch', '-p0', '--forward', '--force']
|
| + subprocess2.check_call(cmd, stdin=patch, cwd=location)
|
| +
|
|
|