From c9dae6458fe07d1416ebf8c56db7fb10776f8ac2 Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Mon, 21 Aug 2023 16:41:05 +0000 Subject: [PATCH] [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 Commit-Queue: Josip Sokcevic --- gclient.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gclient.py b/gclient.py index e7e16ea758..958c6aed72 100755 --- a/gclient.py +++ b/gclient.py @@ -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.')