summaryrefslogtreecommitdiffstats
path: root/subcmds/sync.py
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2019-08-27 01:10:59 -0400
committerMike Frysinger <vapier@google.com>2019-08-28 03:54:11 +0000
commitae6cb08ae52d488a4cc6892f811c1c1acf8c3c12 (patch)
treec927415df288d9bf9076e758835db53cc633597d /subcmds/sync.py
parent3fc157285cb61d6a4faa55dc4f011fb94d598c20 (diff)
downloadgit-repo-ae6cb08ae52d488a4cc6892f811c1c1acf8c3c12.tar.gz
split out cli validation from executionv1.13.5
A common pattern in our subcommands is to verify the arguments & options before executing things. For some subcommands, that check stage is quite long which makes the execution function even bigger. Lets split that logic out of the execute phase so it's easier to manage these. This is most noticeable in the sync subcommand whose Execute func is quite large, and the option checking makes up ~15% of it. The manifest command's Execute can be simplified significantly as the optparse configuration always sets output_file to a string. Change-Id: I7097847ff040e831345e63de6b467ee17609990e Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/234834 Reviewed-by: David Pursehouse <dpursehouse@collab.net> Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'subcmds/sync.py')
-rw-r--r--subcmds/sync.py34
1 files changed, 14 insertions, 20 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 3eab2fcf..5655a1e6 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -738,36 +738,30 @@ later is required to fix a server side protocol bug.
738 fd.close() 738 fd.close()
739 return 0 739 return 0
740 740
741 def Execute(self, opt, args): 741 def ValidateOptions(self, opt, args):
742 if opt.jobs:
743 self.jobs = opt.jobs
744 if self.jobs > 1:
745 soft_limit, _ = _rlimit_nofile()
746 self.jobs = min(self.jobs, (soft_limit - 5) // 3)
747
748 if opt.force_broken: 742 if opt.force_broken:
749 print('warning: -f/--force-broken is now the default behavior, and the ' 743 print('warning: -f/--force-broken is now the default behavior, and the '
750 'options are deprecated', file=sys.stderr) 744 'options are deprecated', file=sys.stderr)
751 if opt.network_only and opt.detach_head: 745 if opt.network_only and opt.detach_head:
752 print('error: cannot combine -n and -d', file=sys.stderr) 746 self.OptionParser.error('cannot combine -n and -d')
753 sys.exit(1)
754 if opt.network_only and opt.local_only: 747 if opt.network_only and opt.local_only:
755 print('error: cannot combine -n and -l', file=sys.stderr) 748 self.OptionParser.error('cannot combine -n and -l')
756 sys.exit(1)
757 if opt.manifest_name and opt.smart_sync: 749 if opt.manifest_name and opt.smart_sync:
758 print('error: cannot combine -m and -s', file=sys.stderr) 750 self.OptionParser.error('cannot combine -m and -s')
759 sys.exit(1)
760 if opt.manifest_name and opt.smart_tag: 751 if opt.manifest_name and opt.smart_tag:
761 print('error: cannot combine -m and -t', file=sys.stderr) 752 self.OptionParser.error('cannot combine -m and -t')
762 sys.exit(1)
763 if opt.manifest_server_username or opt.manifest_server_password: 753 if opt.manifest_server_username or opt.manifest_server_password:
764 if not (opt.smart_sync or opt.smart_tag): 754 if not (opt.smart_sync or opt.smart_tag):
765 print('error: -u and -p may only be combined with -s or -t', 755 self.OptionParser.error('-u and -p may only be combined with -s or -t')
766 file=sys.stderr)
767 sys.exit(1)
768 if None in [opt.manifest_server_username, opt.manifest_server_password]: 756 if None in [opt.manifest_server_username, opt.manifest_server_password]:
769 print('error: both -u and -p must be given', file=sys.stderr) 757 self.OptionParser.error('both -u and -p must be given')
770 sys.exit(1) 758
759 def Execute(self, opt, args):
760 if opt.jobs:
761 self.jobs = opt.jobs
762 if self.jobs > 1:
763 soft_limit, _ = _rlimit_nofile()
764 self.jobs = min(self.jobs, (soft_limit - 5) // 3)
771 765
772 if opt.manifest_name: 766 if opt.manifest_name:
773 self.manifest.Override(opt.manifest_name) 767 self.manifest.Override(opt.manifest_name)