comparison mercurial/exchange.py @ 38792:afb442f58cbf

exchange: refactor control flow of _getbundlechangegrouppart() The use of early return makes the control flow of this function much easier to reason about IMO. Differential Revision: https://phab.mercurial-scm.org/D4010
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 02 Jul 2018 18:39:48 -0700
parents 7e66e7999bdd
children 98df52d5042c
comparison
equal deleted inserted replaced
38791:7e66e7999bdd 38792:afb442f58cbf
2094 2094
2095 @getbundle2partsgenerator('changegroup') 2095 @getbundle2partsgenerator('changegroup')
2096 def _getbundlechangegrouppart(bundler, repo, source, bundlecaps=None, 2096 def _getbundlechangegrouppart(bundler, repo, source, bundlecaps=None,
2097 b2caps=None, heads=None, common=None, **kwargs): 2097 b2caps=None, heads=None, common=None, **kwargs):
2098 """add a changegroup part to the requested bundle""" 2098 """add a changegroup part to the requested bundle"""
2099 cgstream = None 2099 if not kwargs.get(r'cg', True):
2100 if kwargs.get(r'cg', True): 2100 return
2101 # build changegroup bundle here. 2101
2102 version = '01' 2102 version = '01'
2103 cgversions = b2caps.get('changegroup') 2103 cgversions = b2caps.get('changegroup')
2104 if cgversions: # 3.1 and 3.2 ship with an empty value 2104 if cgversions: # 3.1 and 3.2 ship with an empty value
2105 cgversions = [v for v in cgversions 2105 cgversions = [v for v in cgversions
2106 if v in changegroup.supportedoutgoingversions(repo)] 2106 if v in changegroup.supportedoutgoingversions(repo)]
2107 if not cgversions: 2107 if not cgversions:
2108 raise ValueError(_('no common changegroup version')) 2108 raise ValueError(_('no common changegroup version'))
2109 version = max(cgversions) 2109 version = max(cgversions)
2110 outgoing = _computeoutgoing(repo, heads, common) 2110
2111 if outgoing.missing: 2111 outgoing = _computeoutgoing(repo, heads, common)
2112 cgstream = changegroup.makestream(repo, outgoing, version, source, 2112 if not outgoing.missing:
2113 bundlecaps=bundlecaps) 2113 return
2114 2114
2115 if cgstream: 2115 cgstream = changegroup.makestream(repo, outgoing, version, source,
2116 part = bundler.newpart('changegroup', data=cgstream) 2116 bundlecaps=bundlecaps)
2117 if cgversions: 2117
2118 part.addparam('version', version) 2118 part = bundler.newpart('changegroup', data=cgstream)
2119 part.addparam('nbchanges', '%d' % len(outgoing.missing), 2119 if cgversions:
2120 mandatory=False) 2120 part.addparam('version', version)
2121 if 'treemanifest' in repo.requirements: 2121
2122 part.addparam('treemanifest', '1') 2122 part.addparam('nbchanges', '%d' % len(outgoing.missing),
2123 mandatory=False)
2124
2125 if 'treemanifest' in repo.requirements:
2126 part.addparam('treemanifest', '1')
2123 2127
2124 @getbundle2partsgenerator('bookmarks') 2128 @getbundle2partsgenerator('bookmarks')
2125 def _getbundlebookmarkpart(bundler, repo, source, bundlecaps=None, 2129 def _getbundlebookmarkpart(bundler, repo, source, bundlecaps=None,
2126 b2caps=None, **kwargs): 2130 b2caps=None, **kwargs):
2127 """add a bookmark part to the requested bundle""" 2131 """add a bookmark part to the requested bundle"""