Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 itertools | 5 import itertools |
| 6 import re | 6 import re |
| 7 | 7 |
| 8 from recipe_engine import recipe_api | 8 from recipe_engine import recipe_api |
| 9 | 9 |
| 10 class GitApi(recipe_api.RecipeApi): | 10 class GitApi(recipe_api.RecipeApi): |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 a side effect of all stderr output of 'git fetch' going to that file. | 133 a side effect of all stderr output of 'git fetch' going to that file. |
| 134 can_fail_build (bool): if False, ignore errors during fetch or checkout. | 134 can_fail_build (bool): if False, ignore errors during fetch or checkout. |
| 135 set_got_revision (bool): if True, resolves HEAD and sets got_revision | 135 set_got_revision (bool): if True, resolves HEAD and sets got_revision |
| 136 property. | 136 property. |
| 137 remote_name (str): name of the git remote to use | 137 remote_name (str): name of the git remote to use |
| 138 display_fetch_size (bool): if True, run `git count-objects` before and | 138 display_fetch_size (bool): if True, run `git count-objects` before and |
| 139 after fetch and display delta. Adds two more steps. Defaults to False. | 139 after fetch and display delta. Adds two more steps. Defaults to False. |
| 140 file_name (str): optional path to a single file to checkout. | 140 file_name (str): optional path to a single file to checkout. |
| 141 submodule_update_recursive (bool): if True, updates submodules | 141 submodule_update_recursive (bool): if True, updates submodules |
| 142 recursively. | 142 recursively. |
| 143 | |
| 144 Returns: If set_got_revision is True and the checkout was successful, this | |
|
dnj
2016/02/12 21:54:45
Why not always return it, even if set_got_revision
| |
| 145 returns the commit hash of the checked-out-repo. Otherwise this returns | |
| 146 None. | |
| 143 """ | 147 """ |
| 148 retVal = None | |
| 149 | |
| 144 # TODO(robertocn): Break this function and refactor calls to it. | 150 # TODO(robertocn): Break this function and refactor calls to it. |
| 145 # The problem is that there are way too many unrealated use cases for | 151 # The problem is that there are way too many unrealated use cases for |
| 146 # it, and the function's signature is getting unwieldy and its body | 152 # it, and the function's signature is getting unwieldy and its body |
| 147 # unreadable. | 153 # unreadable. |
| 148 display_fetch_size = display_fetch_size or False | 154 display_fetch_size = display_fetch_size or False |
| 149 if not dir_path: | 155 if not dir_path: |
| 150 dir_path = url.rsplit('/', 1)[-1] | 156 dir_path = url.rsplit('/', 1)[-1] |
| 151 if dir_path.endswith('.git'): # ex: https://host/foobar.git | 157 if dir_path.endswith('.git'): # ex: https://host/foobar.git |
| 152 dir_path = dir_path[:-len('.git')] | 158 dir_path = dir_path[:-len('.git')] |
| 153 | 159 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 | 255 |
| 250 if set_got_revision: | 256 if set_got_revision: |
| 251 rev_parse_step = self('rev-parse', 'HEAD', | 257 rev_parse_step = self('rev-parse', 'HEAD', |
| 252 cwd=dir_path, | 258 cwd=dir_path, |
| 253 name='set got_revision', | 259 name='set got_revision', |
| 254 stdout=self.m.raw_io.output(), | 260 stdout=self.m.raw_io.output(), |
| 255 can_fail_build=False) | 261 can_fail_build=False) |
| 256 | 262 |
| 257 if rev_parse_step.presentation.status == 'SUCCESS': | 263 if rev_parse_step.presentation.status == 'SUCCESS': |
| 258 sha = rev_parse_step.stdout.strip() | 264 sha = rev_parse_step.stdout.strip() |
| 265 retVal = sha | |
| 259 rev_parse_step.presentation.properties['got_revision'] = sha | 266 rev_parse_step.presentation.properties['got_revision'] = sha |
| 260 | 267 |
| 261 clean_args = list(itertools.chain( | 268 clean_args = list(itertools.chain( |
| 262 *[('-e', path) for path in keep_paths or []])) | 269 *[('-e', path) for path in keep_paths or []])) |
| 263 | 270 |
| 264 self('clean', '-f', '-d', '-x', *clean_args, | 271 self('clean', '-f', '-d', '-x', *clean_args, |
| 265 name='git clean%s' % step_suffix, | 272 name='git clean%s' % step_suffix, |
| 266 cwd=dir_path, | 273 cwd=dir_path, |
| 267 can_fail_build=can_fail_build) | 274 can_fail_build=can_fail_build) |
| 268 | 275 |
| 269 if submodules: | 276 if submodules: |
| 270 self('submodule', 'sync', | 277 self('submodule', 'sync', |
| 271 name='submodule sync%s' % step_suffix, | 278 name='submodule sync%s' % step_suffix, |
| 272 cwd=dir_path, | 279 cwd=dir_path, |
| 273 can_fail_build=can_fail_build) | 280 can_fail_build=can_fail_build) |
| 274 submodule_update = ['submodule', 'update', '--init'] | 281 submodule_update = ['submodule', 'update', '--init'] |
| 275 if submodule_update_recursive: | 282 if submodule_update_recursive: |
| 276 submodule_update.append('--recursive') | 283 submodule_update.append('--recursive') |
| 277 if submodule_update_force: | 284 if submodule_update_force: |
| 278 submodule_update.append('--force') | 285 submodule_update.append('--force') |
| 279 self(*submodule_update, | 286 self(*submodule_update, |
| 280 name='submodule update%s' % step_suffix, | 287 name='submodule update%s' % step_suffix, |
| 281 cwd=dir_path, | 288 cwd=dir_path, |
| 282 can_fail_build=can_fail_build) | 289 can_fail_build=can_fail_build) |
| 283 | 290 |
| 291 return retVal | |
| 292 | |
| 284 def get_timestamp(self, commit='HEAD', test_data=None, **kwargs): | 293 def get_timestamp(self, commit='HEAD', test_data=None, **kwargs): |
| 285 """Find and return the timestamp of the given commit.""" | 294 """Find and return the timestamp of the given commit.""" |
| 286 step_test_data = None | 295 step_test_data = None |
| 287 if test_data is not None: | 296 if test_data is not None: |
| 288 step_test_data = lambda: self.m.raw_io.test_api.stream_output(test_data) | 297 step_test_data = lambda: self.m.raw_io.test_api.stream_output(test_data) |
| 289 return self('show', commit, '--format=%at', '-s', | 298 return self('show', commit, '--format=%at', '-s', |
| 290 stdout=self.m.raw_io.output(), | 299 stdout=self.m.raw_io.output(), |
| 291 step_test_data=step_test_data).stdout.rstrip() | 300 step_test_data=step_test_data).stdout.rstrip() |
| 292 | 301 |
| 293 def rebase(self, name_prefix, branch, dir_path, remote_name=None, | 302 def rebase(self, name_prefix, branch, dir_path, remote_name=None, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 | 349 |
| 341 Args: | 350 Args: |
| 342 bundle_path (Path): The path of the output bundle. | 351 bundle_path (Path): The path of the output bundle. |
| 343 refs (list): The list of refs to include in the bundle. If None, all | 352 refs (list): The list of refs to include in the bundle. If None, all |
| 344 refs in the Git checkout will be bundled. | 353 refs in the Git checkout will be bundled. |
| 345 kwargs: Forwarded to '__call__'. | 354 kwargs: Forwarded to '__call__'. |
| 346 """ | 355 """ |
| 347 if not rev_list_args: | 356 if not rev_list_args: |
| 348 rev_list_args = ['--all'] | 357 rev_list_args = ['--all'] |
| 349 self('bundle', 'create', bundle_path, *rev_list_args, **kwargs) | 358 self('bundle', 'create', bundle_path, *rev_list_args, **kwargs) |
| OLD | NEW |