Chromium Code Reviews| Index: checkout.py |
| diff --git a/checkout.py b/checkout.py |
| index 022076c402218ea329ea0832969aa4eba955eef0..b0221040c29eed3909207070fd5a42fdf03d80fc 100644 |
| --- a/checkout.py |
| +++ b/checkout.py |
| @@ -132,7 +132,7 @@ class CheckoutBase(object): |
| raise NotImplementedError() |
| def apply_patch(self, patches, post_processors=None, verbose=False, |
| - name=None, email=None): |
| + name=None, email=None, whitelist=None, blacklist=None): |
|
M-A Ruel
2014/05/06 18:49:08
I think you are doing it at the wrong abstraction
Ryan Tseng
2014/05/06 19:31:53
Done.
|
| """Applies a patch and returns the list of modified files. |
| This function should throw patch.UnsupportedPatchFormat or |
| @@ -167,13 +167,17 @@ class RawCheckout(CheckoutBase): |
| pass |
| def apply_patch(self, patches, post_processors=None, verbose=False, |
| - name=None, email=None): |
| + name=None, email=None, whitelist=None, blacklist=None): |
| """Ignores svn properties.""" |
| post_processors = post_processors or self.post_processors or [] |
| for p in patches: |
| stdout = [] |
| try: |
| filepath = os.path.join(self.project_path, p.filename) |
| + if blacklist and p.filename in blacklist: |
| + continue |
| + if whitelist and p.filename not in whitelist: |
| + continue |
| if p.is_delete: |
| os.remove(filepath) |
| stdout.append('Deleted.') |
| @@ -352,11 +356,15 @@ class SvnCheckout(CheckoutBase, SvnMixIn): |
| return self._revert(revision) |
| def apply_patch(self, patches, post_processors=None, verbose=False, |
| - name=None, email=None): |
| + name=None, email=None, whitelist=None, blacklist=None): |
| post_processors = post_processors or self.post_processors or [] |
| for p in patches: |
| stdout = [] |
| try: |
| + if blacklist and p.filename in blacklist: |
| + continue |
| + if whitelist and p.filename not in whitelist: |
| + continue |
| filepath = os.path.join(self.project_path, p.filename) |
| # It is important to use credentials=False otherwise credentials could |
| # leak in the error message. Credentials are not necessary here for the |
| @@ -632,11 +640,14 @@ class GitCheckout(CheckoutBase): |
| return unicode(self._check_output_git(['rev-parse', 'HEAD']).strip()) |
| def apply_patch(self, patches, post_processors=None, verbose=False, |
| - name=None, email=None): |
| + name=None, email=None, whitelist=None, blacklist=None): |
| """Applies a patch on 'working_branch' and switches to it. |
| Also commits the changes on the local branch. |
| + If ignore_deps is set, then files matching deps will not get patched. |
| + If deps_only is set, then only files matching deps will get patched. |
| + |
| Ignores svn properties and raise an exception on unexpected ones. |
| """ |
| post_processors = post_processors or self.post_processors or [] |
| @@ -650,6 +661,10 @@ class GitCheckout(CheckoutBase): |
| for index, p in enumerate(patches): |
| stdout = [] |
| try: |
| + if blacklist and p.filename in blacklist: |
| + continue |
| + if whitelist and p.filename not in whitelist: |
| + continue |
| filepath = os.path.join(self.project_path, p.filename) |
| if p.is_delete: |
| if (not os.path.exists(filepath) and |
| @@ -689,6 +704,8 @@ class GitCheckout(CheckoutBase): |
| # applies here to figure out if the property will be correctly |
| # handled. |
| stdout.append('Property %s=%s' % (name, value)) |
| + # TODO(hinoka): Also remove the executable flag if svn:executabe |
| + # is not set yet the file is executable. |
| if not name in ( |
| 'svn:eol-style', 'svn:executable', 'svn:mime-type'): |
| raise patch.UnsupportedPatchFormat( |
| @@ -725,8 +742,13 @@ class GitCheckout(CheckoutBase): |
| found_files = self._check_output_git( |
| ['diff', base_ref, '--ignore-submodules', |
| '--name-only']).splitlines(False) |
| - assert sorted(patches.filenames) == sorted(found_files), ( |
| - sorted(patches.filenames), sorted(found_files)) |
| + expected_files = patches.filenames |
| + if whitelist: |
| + expected_files = whitelist |
| + if blacklist: |
| + expected_files = [f for f in expected_files if f not in blacklist] |
| + assert sorted(expected_files) == sorted(found_files), ( |
| + sorted(expected_files), sorted(found_files)) |
| def commit(self, commit_message, user): |
| """Commits, updates the commit message and pushes.""" |
| @@ -825,9 +847,15 @@ class ReadOnlyCheckout(object): |
| return self.checkout.get_settings(key) |
| def apply_patch(self, patches, post_processors=None, verbose=False, |
| - name=None, email=None): |
| + name=None, email=None, whitelist=None, blacklist=None): |
| + if not whitelist: |
| + whitelist = [] |
| + if not blacklist: |
| + blacklist = [] |
| return self.checkout.apply_patch( |
| - patches, post_processors or self.post_processors, verbose) |
| + patches, post_processors or self.post_processors, verbose, |
| + whitelist=whitelist, |
| + blacklist=blacklist) |
| def commit(self, message, user): # pylint: disable=R0201 |
| logging.info('Would have committed for %s with message: %s' % ( |