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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « checkout.py ('k') | pending_manager.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
+
« 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