[gclient] Optimize gitmodules script

This reduces calls to git-update-index from N (number of deps) to 1.

R=aravindvasudev@google.com, jojwang@google.com

Change-Id: I46d7eec37d8e27cd54039ff0a03782857b440317
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4795126
Reviewed-by: Aravind Vasudevan <aravindvasudev@google.com>
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
changes/26/4795126/4
Josip Sokcevic 2 years ago committed by LUCI CQ
parent 5561f8be12
commit c9dae6458f

@ -2707,6 +2707,7 @@ def CMDgitmodules(parser, args):
if delta_path:
prefix_length = len(delta_path.replace(os.path.sep, '/')) + 1
cache_info = []
with open(options.output_gitmodules, 'w') as f:
for path, dep in ls.get('deps').items():
if path in options.skip_dep:
@ -2721,13 +2722,13 @@ def CMDgitmodules(parser, args):
if prefix_length:
path = path[prefix_length:]
subprocess2.call([
'git', 'update-index', '--add', '--cacheinfo',
f'160000,{commit},{path}'
])
cache_info += ['--cacheinfo', f'160000,{commit},{path}']
f.write(f'[submodule "{path}"]\n\tpath = {path}\n\turl = {url}\n')
if 'condition' in dep:
f.write(f'\tgclient-condition = {dep["condition"]}\n')
if cache_info:
subprocess2.call(['git', 'update-index', '--add'] + cache_info)
subprocess2.call(['git', 'add', '.gitmodules'])
print('.gitmodules and gitlinks updated. Please check git diff and '
'commit changes.')

Loading…
Cancel
Save