Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: patch.py

Issue 5968005: Move patch management functions into their own file, patch.py. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/commit-queue
Patch Set: rebase against trunk Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « checkout.py ('k') | pending_manager.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « checkout.py ('k') | pending_manager.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698