From d9e5cf0ee76d55a94079c34f78ffb9dff858e93e Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 26 Aug 2019 03:12:55 -0400 Subject: sync: invert --force-broken with --fail-fast People seem to not expect the sync process to halt immediately if an error is encountered. It's also basically guaranteed to leave their tree in an incomplete state. Lets invert the default behavior so we attempt to sync (both fetch & checkout) all projects. If an error is hit, we still exit(1) and show it at the end. If people want the sync to abort quickly, they can use the new option --fail-fast. Bug: https://crbug.com/gerrit/11293 Change-Id: I49dd6c4dc8fd5cce8aa905ee169ff3cbe230eb3d Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/234812 Reviewed-by: David Pursehouse Tested-by: Mike Frysinger --- subcmds/sync.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'subcmds') diff --git a/subcmds/sync.py b/subcmds/sync.py index 3b4c23c5..3eab2fcf 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -132,8 +132,8 @@ from the user's .netrc file. if the manifest server specified in the manifest file already includes credentials. -The -f/--force-broken option can be used to proceed with syncing -other projects if a project sync fails. +By default, all projects will be synced. The --fail-fast option can be used +to halt syncing as soon as possible when the the first project fails to sync. The --force-sync option can be used to overwrite existing git directories if they have previously been linked to a different @@ -199,8 +199,10 @@ later is required to fix a server side protocol bug. self.jobs = 1 p.add_option('-f', '--force-broken', - dest='force_broken', action='store_true', - help="continue sync even if a project fails to sync") + help='obsolete option (to be deleted in the future)') + p.add_option('--fail-fast', + dest='fail_fast', action='store_true', + help='stop syncing after first error is hit') p.add_option('--force-sync', dest='force_sync', action='store_true', help="overwrite an existing git directory if it needs to " @@ -284,7 +286,7 @@ later is required to fix a server side protocol bug. try: for project in projects: success = self._FetchHelper(opt, project, *args, **kwargs) - if not success and not opt.force_broken: + if not success and opt.fail_fast: break finally: sem.release() @@ -343,10 +345,7 @@ later is required to fix a server side protocol bug. print('error: Cannot fetch %s from %s' % (project.name, project.remote.url), file=sys.stderr) - if opt.force_broken: - print('warn: --force-broken, continuing to sync', - file=sys.stderr) - else: + if opt.fail_fast: raise _FetchError() fetched.add(project.gitdir) @@ -384,7 +383,7 @@ later is required to fix a server side protocol bug. for project_list in objdir_project_map.values(): # Check for any errors before running any more tasks. # ...we'll let existing threads finish, though. - if err_event.isSet() and not opt.force_broken: + if err_event.isSet() and opt.fail_fast: break sem.acquire() @@ -410,7 +409,7 @@ later is required to fix a server side protocol bug. t.join() # If we saw an error, exit with code 1 so that other scripts can check. - if err_event.isSet() and not opt.force_broken: + if err_event.isSet() and opt.fail_fast: print('\nerror: Exited sync due to fetch errors', file=sys.stderr) sys.exit(1) @@ -532,7 +531,7 @@ later is required to fix a server side protocol bug. for project in all_projects: # Check for any errors before running any more tasks. # ...we'll let existing threads finish, though. - if err_event.isSet() and not opt.force_broken: + if err_event.isSet() and opt.fail_fast: break sem.acquire() @@ -746,6 +745,9 @@ later is required to fix a server side protocol bug. soft_limit, _ = _rlimit_nofile() self.jobs = min(self.jobs, (soft_limit - 5) // 3) + if opt.force_broken: + print('warning: -f/--force-broken is now the default behavior, and the ' + 'options are deprecated', file=sys.stderr) if opt.network_only and opt.detach_head: print('error: cannot combine -n and -d', file=sys.stderr) sys.exit(1) -- cgit v1.2.3-54-g00ecf