mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
sync: create dedicated smart sync func
The smart sync logic takes up about 45% of the overall Execute func and is about 100 lines of code. The only effect it has on the rest of the code is to set the manifest_name variable. Since this func is already quite huge, split the smart sync logic out. Change-Id: Id861849b0011ab47387d74e92c2ac15afcc938ba Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/234835 Tested-by: Mike Frysinger <vapier@google.com> Reviewed-by: David Pursehouse <dpursehouse@collab.net>
This commit is contained in:
parent
4c263b52e7
commit
01d6c3c0c5
@ -739,40 +739,7 @@ later is required to fix a server side protocol bug.
|
||||
fd.close()
|
||||
return 0
|
||||
|
||||
def ValidateOptions(self, opt, args):
|
||||
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:
|
||||
self.OptionParser.error('cannot combine -n and -d')
|
||||
if opt.network_only and opt.local_only:
|
||||
self.OptionParser.error('cannot combine -n and -l')
|
||||
if opt.manifest_name and opt.smart_sync:
|
||||
self.OptionParser.error('cannot combine -m and -s')
|
||||
if opt.manifest_name and opt.smart_tag:
|
||||
self.OptionParser.error('cannot combine -m and -t')
|
||||
if opt.manifest_server_username or opt.manifest_server_password:
|
||||
if not (opt.smart_sync or opt.smart_tag):
|
||||
self.OptionParser.error('-u and -p may only be combined with -s or -t')
|
||||
if None in [opt.manifest_server_username, opt.manifest_server_password]:
|
||||
self.OptionParser.error('both -u and -p must be given')
|
||||
|
||||
def Execute(self, opt, args):
|
||||
if opt.jobs:
|
||||
self.jobs = opt.jobs
|
||||
if self.jobs > 1:
|
||||
soft_limit, _ = _rlimit_nofile()
|
||||
self.jobs = min(self.jobs, (soft_limit - 5) // 3)
|
||||
|
||||
if opt.manifest_name:
|
||||
self.manifest.Override(opt.manifest_name)
|
||||
|
||||
manifest_name = opt.manifest_name
|
||||
smart_sync_manifest_name = "smart_sync_override.xml"
|
||||
smart_sync_manifest_path = os.path.join(
|
||||
self.manifest.manifestProject.worktree, smart_sync_manifest_name)
|
||||
|
||||
if opt.smart_sync or opt.smart_tag:
|
||||
def _SmartSyncSetup(self, opt, smart_sync_manifest_path):
|
||||
if not self.manifest.manifest_server:
|
||||
print('error: cannot smart sync: no manifest server defined in '
|
||||
'manifest', file=sys.stderr)
|
||||
@ -840,7 +807,7 @@ later is required to fix a server side protocol bug.
|
||||
[success, manifest_str] = server.GetManifest(opt.smart_tag)
|
||||
|
||||
if success:
|
||||
manifest_name = smart_sync_manifest_name
|
||||
manifest_name = os.path.basename(smart_sync_manifest_path)
|
||||
try:
|
||||
f = open(smart_sync_manifest_path, 'w')
|
||||
try:
|
||||
@ -866,7 +833,44 @@ later is required to fix a server side protocol bug.
|
||||
% (self.manifest.manifest_server, e.errcode, e.errmsg),
|
||||
file=sys.stderr)
|
||||
sys.exit(1)
|
||||
else: # Not smart sync or smart tag mode
|
||||
|
||||
return manifest_name
|
||||
|
||||
def ValidateOptions(self, opt, args):
|
||||
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:
|
||||
self.OptionParser.error('cannot combine -n and -d')
|
||||
if opt.network_only and opt.local_only:
|
||||
self.OptionParser.error('cannot combine -n and -l')
|
||||
if opt.manifest_name and opt.smart_sync:
|
||||
self.OptionParser.error('cannot combine -m and -s')
|
||||
if opt.manifest_name and opt.smart_tag:
|
||||
self.OptionParser.error('cannot combine -m and -t')
|
||||
if opt.manifest_server_username or opt.manifest_server_password:
|
||||
if not (opt.smart_sync or opt.smart_tag):
|
||||
self.OptionParser.error('-u and -p may only be combined with -s or -t')
|
||||
if None in [opt.manifest_server_username, opt.manifest_server_password]:
|
||||
self.OptionParser.error('both -u and -p must be given')
|
||||
|
||||
def Execute(self, opt, args):
|
||||
if opt.jobs:
|
||||
self.jobs = opt.jobs
|
||||
if self.jobs > 1:
|
||||
soft_limit, _ = _rlimit_nofile()
|
||||
self.jobs = min(self.jobs, (soft_limit - 5) // 3)
|
||||
|
||||
if opt.manifest_name:
|
||||
self.manifest.Override(opt.manifest_name)
|
||||
|
||||
manifest_name = opt.manifest_name
|
||||
smart_sync_manifest_path = os.path.join(
|
||||
self.manifest.manifestProject.worktree, 'smart_sync_override.xml')
|
||||
|
||||
if opt.smart_sync or opt.smart_tag:
|
||||
manifest_name = self._SmartSyncSetup(opt, smart_sync_manifest_path)
|
||||
else:
|
||||
if os.path.isfile(smart_sync_manifest_path):
|
||||
try:
|
||||
platform_utils.remove(smart_sync_manifest_path)
|
||||
|
Loading…
Reference in New Issue
Block a user