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

Side by Side Diff: recipe_modules/tryserver/api.py

Issue 1927403003: Avoid computing patch_root in get_files_affected_by_patch. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: review Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | recipe_modules/tryserver/example.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import contextlib 5 import contextlib
6 import hashlib 6 import hashlib
7 7
8 from recipe_engine import recipe_api 8 from recipe_engine import recipe_api
9 9
10 10
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 self.m.rietveld.calculate_issue_root(), 141 self.m.rietveld.calculate_issue_root(),
142 authentication=authentication) 142 authentication=authentication)
143 elif storage == PATCH_STORAGE_SVN: 143 elif storage == PATCH_STORAGE_SVN:
144 return self.apply_from_svn(cwd) 144 return self.apply_from_svn(cwd)
145 elif storage == PATCH_STORAGE_GIT: 145 elif storage == PATCH_STORAGE_GIT:
146 return self.apply_from_git(cwd) 146 return self.apply_from_git(cwd)
147 else: 147 else:
148 # Since this method is "maybe", we don't raise an Exception. 148 # Since this method is "maybe", we don't raise an Exception.
149 pass 149 pass
150 150
151 def get_files_affected_by_patch(self): 151 def get_files_affected_by_patch(self, patch_root=None):
152 """Returns list of paths to files affected by the patch.
153
154 Argument:
155 patch_root: path relative to api.path['root'], usually obtained from
156 api.gclient.calculate_patch_root(patch_project)
157
158 Returned paths will be relative to to patch_root.
159
160 TODO(tandrii): remove this doc.
161 Unless you use patch_root=None, in which case old behavior is used
162 which returns paths relative to checkout aka solution[0].name.
163 """
164 # patch_root must be set! None is for backwards compataibility and will be
165 # removed.
166 if patch_root is None:
167 return self._old_get_files_affected_by_patch()
168 step_result = self.m.git('diff', '--cached', '--name-only',
169 cwd=self.m.path['slave_build'].join(patch_root),
170 name='git diff to analyze patch',
171 stdout=self.m.raw_io.output(),
172 step_test_data=lambda:
173 self.m.raw_io.test_api.stream_output('foo.cc'))
174 paths = [self.m.path.join(patch_root, p) for p in
175 step_result.stdout.split()]
176 if self.m.platform.is_win:
177 # Looks like "analyze" wants POSIX slashes even on Windows (since git
178 # uses that format even on Windows).
179 paths = [path.replace('\\', '/') for path in paths]
180 step_result.presentation.logs['files'] = paths
181 return paths
182
183
184 def _old_get_files_affected_by_patch(self):
152 git_diff_kwargs = {} 185 git_diff_kwargs = {}
153 issue_root = self.m.rietveld.calculate_issue_root() 186 issue_root = self.m.rietveld.calculate_issue_root()
154 if issue_root: 187 if issue_root:
155 git_diff_kwargs['cwd'] = self.m.path['checkout'].join(issue_root) 188 git_diff_kwargs['cwd'] = self.m.path['checkout'].join(issue_root)
156 step_result = self.m.git('diff', '--cached', '--name-only', 189 step_result = self.m.git('diff', '--cached', '--name-only',
157 name='git diff to analyze patch', 190 name='git diff to analyze patch',
158 stdout=self.m.raw_io.output(), 191 stdout=self.m.raw_io.output(),
159 step_test_data=lambda: 192 step_test_data=lambda:
160 self.m.raw_io.test_api.stream_output('foo.cc'), 193 self.m.raw_io.test_api.stream_output('foo.cc'),
161 **git_diff_kwargs) 194 **git_diff_kwargs)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 self.add_failure_reason(e.reason) 271 self.add_failure_reason(e.reason)
239 272
240 failure_hash = hashlib.sha1() 273 failure_hash = hashlib.sha1()
241 failure_hash.update(self.m.json.dumps(self._failure_reasons)) 274 failure_hash.update(self.m.json.dumps(self._failure_reasons))
242 275
243 step_result = self.m.step.active_result 276 step_result = self.m.step.active_result
244 step_result.presentation.properties['failure_hash'] = \ 277 step_result.presentation.properties['failure_hash'] = \
245 failure_hash.hexdigest() 278 failure_hash.hexdigest()
246 279
247 raise 280 raise
OLDNEW
« no previous file with comments | « no previous file | recipe_modules/tryserver/example.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698