Skip to content

Commit f596392

Browse files
committed
[Update Checkout] Print hashes at the end of the successful clone/update.
- Support dump-hashes with skipped repos - Remove duplicated code from dump hashes
1 parent 7e8ce6c commit f596392

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

utils/update_checkout/update_checkout/update_checkout.py

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import re
1818
import sys
1919
import traceback
20-
2120
from functools import reduce
2221
from multiprocessing import freeze_support
2322

@@ -309,49 +308,42 @@ def obtain_all_additional_swift_sources(args, config, with_ssh, scheme_name,
309308
args.n_processes)
310309

311310

312-
def dump_repo_hashes(config):
311+
def dump_repo_hashes(config, branch_scheme_name='repro'):
313312
"""
314313
Dumps the current state of the repo into a new config file that contains a
315314
master branch scheme with the relevant branches set to the appropriate
316315
hashes.
317316
"""
318-
branch_scheme_name = 'repro'
319317
new_config = {}
320318
config_copy_keys = ['ssh-clone-pattern', 'https-clone-pattern', 'repos']
321319
for config_copy_key in config_copy_keys:
322320
new_config[config_copy_key] = config[config_copy_key]
323321
repos = {}
322+
repos = repo_hashes(config)
324323
branch_scheme = {'aliases': [branch_scheme_name], 'repos': repos}
325324
new_config['branch-schemes'] = {branch_scheme_name: branch_scheme}
326-
for repo_name, repo_info in sorted(config['repos'].items(),
327-
key=lambda x: x[0]):
328-
with shell.pushd(os.path.join(SWIFT_SOURCE_ROOT, repo_name),
329-
dry_run=False,
330-
echo=False):
331-
h = shell.capture(["git", "rev-parse", "HEAD"],
332-
echo=False).strip()
333-
repos[repo_name] = str(h)
334325
json.dump(new_config, sys.stdout, indent=4)
335326

336327

337-
def dump_hashes_config(args, config):
338-
branch_scheme_name = args.dump_hashes_config
339-
new_config = {}
340-
config_copy_keys = ['ssh-clone-pattern', 'https-clone-pattern', 'repos']
341-
for config_copy_key in config_copy_keys:
342-
new_config[config_copy_key] = config[config_copy_key]
328+
def repo_hashes(config):
343329
repos = {}
344-
branch_scheme = {'aliases': [branch_scheme_name], 'repos': repos}
345-
new_config['branch-schemes'] = {args.dump_hashes_config: branch_scheme}
346330
for repo_name, repo_info in sorted(config['repos'].items(),
347331
key=lambda x: x[0]):
348-
with shell.pushd(os.path.join(SWIFT_SOURCE_ROOT, repo_name),
349-
dry_run=False,
350-
echo=False):
351-
h = shell.capture(["git", "rev-parse", "HEAD"],
352-
echo=False).strip()
353-
repos[repo_name] = str(h)
354-
json.dump(new_config, sys.stdout, indent=4)
332+
repo_path = os.path.join(SWIFT_SOURCE_ROOT, repo_name)
333+
if os.path.exists(repo_path):
334+
with shell.pushd(repo_path, dry_run=False, echo=False):
335+
h = shell.capture(["git", "rev-parse", "HEAD"],
336+
echo=False).strip()
337+
else:
338+
h = 'skip'
339+
repos[repo_name] = str(h)
340+
return repos
341+
342+
343+
def print_repo_hashes(config):
344+
repos = repo_hashes(config)
345+
for repo_name, repo_hash in repos.iteritems():
346+
print("{:<35}: {:<35}".format(repo_name, repo_hash))
355347

356348

357349
def validate_config(config):
@@ -520,7 +512,7 @@ def main():
520512
return (None, None)
521513

522514
if args.dump_hashes_config:
523-
dump_hashes_config(args, config)
515+
dump_repo_hashes(config, args.dump_hashes_config)
524516
return (None, None)
525517

526518
cross_repos_pr = {}
@@ -563,4 +555,5 @@ def main():
563555
print("update-checkout failed, fix errors and try again")
564556
else:
565557
print("update-checkout succeeded")
558+
print_repo_hashes(config)
566559
sys.exit(fail_count)

0 commit comments

Comments
 (0)