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

Unified Diff: checkout.py

Issue 8068008: Add post_processors override to apply_patch() and add more testing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 years, 3 months 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 | « no previous file | tests/checkout_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: checkout.py
diff --git a/checkout.py b/checkout.py
index 5f61d6f16598e0533e4fb37983c9551a6d9f377d..672ad9aeb788799ea655cc7426ce472e906726d9 100644
--- a/checkout.py
+++ b/checkout.py
@@ -92,7 +92,7 @@ class CheckoutBase(object):
"""
raise NotImplementedError()
- def apply_patch(self, patches):
+ def apply_patch(self, patches, post_processors=None):
"""Applies a patch and returns the list of modified files.
This function should throw patch.UnsupportedPatchFormat or
@@ -117,8 +117,9 @@ class RawCheckout(CheckoutBase):
"""Stubbed out."""
pass
- def apply_patch(self, patches):
+ def apply_patch(self, patches, post_processors=None):
"""Ignores svn properties."""
+ post_processors = post_processors or self.post_processors or []
for p in patches:
try:
stdout = ''
@@ -145,7 +146,7 @@ class RawCheckout(CheckoutBase):
elif p.is_new and not os.path.exists(filepath):
# There is only a header. Just create the file.
open(filepath, 'w').close()
- for post in (self.post_processors or []):
+ for post in post_processors:
post(self, p)
except OSError, e:
raise PatchApplicationFailed(p.filename, '%s%s' % (stdout, e))
@@ -261,7 +262,8 @@ class SvnCheckout(CheckoutBase, SvnMixIn):
(self.project_name, self.project_path))
return self._revert(revision)
- def apply_patch(self, patches):
+ def apply_patch(self, patches, post_processors=None):
+ post_processors = post_processors or self.post_processors or []
for p in patches:
try:
# It is important to use credentials=False otherwise credentials could
@@ -314,7 +316,7 @@ class SvnCheckout(CheckoutBase, SvnMixIn):
params = value.split('=', 1)
stdout += self._check_output_svn(
['propset'] + params + [p.filename], credentials=False)
- for post in (self.post_processors or []):
+ for post in post_processors:
post(self, p)
except OSError, e:
raise PatchApplicationFailed(p.filename, '%s%s' % (stdout, e))
@@ -418,13 +420,14 @@ class GitCheckoutBase(CheckoutBase):
if self.working_branch in branches:
self._call_git(['branch', '-D', self.working_branch])
- def apply_patch(self, patches):
+ def apply_patch(self, patches, post_processors=None):
"""Applies a patch on 'working_branch' and switch to it.
Also commits the changes on the local branch.
Ignores svn properties and raise an exception on unexpected ones.
"""
+ post_processors = post_processors or self.post_processors or []
# It this throws, the checkout is corrupted. Maybe worth deleting it and
# trying again?
if self.remote_branch:
@@ -461,7 +464,7 @@ class GitCheckoutBase(CheckoutBase):
p.filename,
'Cannot apply svn property %s to file %s.' % (
prop[0], p.filename))
- for post in (self.post_processors or []):
+ for post in post_processors:
post(self, p)
except OSError, e:
raise PatchApplicationFailed(p.filename, '%s%s' % (stdout, e))
@@ -693,9 +696,11 @@ class GitSvnCheckout(GitSvnCheckoutBase):
class ReadOnlyCheckout(object):
"""Converts a checkout into a read-only one."""
- def __init__(self, checkout):
+ def __init__(self, checkout, post_processors=None):
super(ReadOnlyCheckout, self).__init__()
self.checkout = checkout
+ self.post_processors = (post_processors or []) + (
+ self.checkout.post_processors or [])
def prepare(self, revision):
return self.checkout.prepare(revision)
@@ -703,8 +708,9 @@ class ReadOnlyCheckout(object):
def get_settings(self, key):
return self.checkout.get_settings(key)
- def apply_patch(self, patches):
- return self.checkout.apply_patch(patches)
+ def apply_patch(self, patches, post_processors=None):
M-A Ruel 2011/09/28 19:28:07 It's mainly for this edge case.
+ return self.checkout.apply_patch(
+ patches, post_processors or self.post_processors)
def commit(self, message, user): # pylint: disable=R0201
logging.info('Would have committed for %s with message: %s' % (
« no previous file with comments | « no previous file | tests/checkout_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698