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

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

Issue 1785443002: depot_tools: adjust for resource API changes in recipe engine (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
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):
11 _GIT_HASH_RE = re.compile('[0-9a-f]{40}', re.IGNORECASE) 11 _GIT_HASH_RE = re.compile('[0-9a-f]{40}', re.IGNORECASE)
12 12
13 def __init__(self, *args, **kwargs): 13 def __init__(self, *args, **kwargs):
14 super(GitApi, self).__init__(*args, **kwargs) 14 super(GitApi, self).__init__(*args, **kwargs)
15 self.initialized_win_git = False 15 self.initialized_win_git = False
16 16
17 def __call__(self, *args, **kwargs): 17 def __call__(self, *args, **kwargs):
18 """Return a git command step.""" 18 """Return a git command step."""
19 name = kwargs.pop('name', 'git '+args[0]) 19 name = kwargs.pop('name', 'git '+args[0])
20 infra_step = kwargs.pop('infra_step', True) 20 infra_step = kwargs.pop('infra_step', True)
21 if 'cwd' not in kwargs: 21 if 'cwd' not in kwargs:
22 kwargs.setdefault('cwd', self.m.path['checkout']) 22 kwargs.setdefault('cwd', self.m.path['checkout'])
23 git_cmd = ['git'] 23 git_cmd = ['git']
24 if self.m.platform.is_win: 24 if self.m.platform.is_win:
25 self.ensure_win_git_tooling() 25 self.ensure_win_git_tooling()
26 git_cmd = [self.package_resource('git.bat')] 26 git_cmd = [self.package_repo_resource('git.bat')]
27 options = kwargs.pop('git_config_options', {}) 27 options = kwargs.pop('git_config_options', {})
28 for k, v in sorted(options.iteritems()): 28 for k, v in sorted(options.iteritems()):
29 git_cmd.extend(['-c', '%s=%s' % (k, v)]) 29 git_cmd.extend(['-c', '%s=%s' % (k, v)])
30 can_fail_build = kwargs.pop('can_fail_build', True) 30 can_fail_build = kwargs.pop('can_fail_build', True)
31 try: 31 try:
32 return self.m.step(name, git_cmd + list(args), infra_step=infra_step, 32 return self.m.step(name, git_cmd + list(args), infra_step=infra_step,
33 **kwargs) 33 **kwargs)
34 except self.m.step.StepFailure as f: 34 except self.m.step.StepFailure as f:
35 if can_fail_build: 35 if can_fail_build:
36 raise 36 raise
37 else: 37 else:
38 return f.result 38 return f.result
39 39
40 def ensure_win_git_tooling(self): 40 def ensure_win_git_tooling(self):
41 """Ensures that depot_tools/git.bat actually exists.""" 41 """Ensures that depot_tools/git.bat actually exists."""
42 if not self.m.platform.is_win or self.initialized_win_git: 42 if not self.m.platform.is_win or self.initialized_win_git:
43 return 43 return
44 self.m.step( 44 self.m.step(
45 'ensure git tooling on windows', 45 'ensure git tooling on windows',
46 [self.package_resource('bootstrap', 'win', 'win_tools.bat')], 46 [self.package_repo_resource('bootstrap', 'win', 'win_tools.bat')],
47 infra_step=True, 47 infra_step=True,
48 cwd=self.package_resource()) 48 cwd=self.package_repo_resource())
49 self.initialized_win_git = True 49 self.initialized_win_git = True
50 50
51 def fetch_tags(self, remote_name=None, **kwargs): 51 def fetch_tags(self, remote_name=None, **kwargs):
52 """Fetches all tags from the remote.""" 52 """Fetches all tags from the remote."""
53 kwargs.setdefault('name', 'git fetch tags') 53 kwargs.setdefault('name', 'git fetch tags')
54 remote_name = remote_name or 'origin' 54 remote_name = remote_name or 'origin'
55 return self('fetch', remote_name, '--tags', **kwargs) 55 return self('fetch', remote_name, '--tags', **kwargs)
56 56
57 def cat_file_at_commit(self, file_path, commit_hash, remote_name=None, 57 def cat_file_at_commit(self, file_path, commit_hash, remote_name=None,
58 **kwargs): 58 **kwargs):
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 182
183 git_setup_args = ['--path', dir_path, '--url', url] 183 git_setup_args = ['--path', dir_path, '--url', url]
184 184
185 if remote_name: 185 if remote_name:
186 git_setup_args += ['--remote', remote_name] 186 git_setup_args += ['--remote', remote_name]
187 else: 187 else:
188 remote_name = 'origin' 188 remote_name = 'origin'
189 189
190 if self.m.platform.is_win: 190 if self.m.platform.is_win:
191 self.ensure_win_git_tooling() 191 self.ensure_win_git_tooling()
192 git_setup_args += ['--git_cmd_path', self.package_resource('git.bat')] 192 git_setup_args += [
193 '--git_cmd_path', self.package_repo_resource('git.bat')]
193 194
194 step_suffix = '' if step_suffix is None else ' (%s)' % step_suffix 195 step_suffix = '' if step_suffix is None else ' (%s)' % step_suffix
195 self.m.python( 196 self.m.python(
196 'git setup%s' % step_suffix, 197 'git setup%s' % step_suffix,
197 self.resource('git_setup.py'), 198 self.resource('git_setup.py'),
198 git_setup_args) 199 git_setup_args)
199 200
200 # There are five kinds of refs we can be handed: 201 # There are five kinds of refs we can be handed:
201 # 0) None. In this case, we default to properties['branch']. 202 # 0) None. In this case, we default to properties['branch'].
202 # 1) A 40-character SHA1 hash. 203 # 1) A 40-character SHA1 hash.
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 368
368 Args: 369 Args:
369 bundle_path (Path): The path of the output bundle. 370 bundle_path (Path): The path of the output bundle.
370 refs (list): The list of refs to include in the bundle. If None, all 371 refs (list): The list of refs to include in the bundle. If None, all
371 refs in the Git checkout will be bundled. 372 refs in the Git checkout will be bundled.
372 kwargs: Forwarded to '__call__'. 373 kwargs: Forwarded to '__call__'.
373 """ 374 """
374 if not rev_list_args: 375 if not rev_list_args:
375 rev_list_args = ['--all'] 376 rev_list_args = ['--all']
376 self('bundle', 'create', bundle_path, *rev_list_args, **kwargs) 377 self('bundle', 'create', bundle_path, *rev_list_args, **kwargs)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698