[PATCH 1 of 8] exchange: use early return
Gregory Szorc
gregory.szorc at gmail.com
Fri Aug 5 03:16:57 UTC 2016
# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1469900681 25200
# Sat Jul 30 10:44:41 2016 -0700
# Node ID 8a046444390debab5372de0b4f38863c57058f69
# Parent 5684bc429e6ab59fbb2c571509cb532c3a8b51cd
exchange: use early return
Avoid excessive indentation and confusing control flow by returning
early if there is no work to be done.
diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -1555,39 +1555,42 @@ def getbundle(repo, source, heads=None,
**kwargs)
return util.chunkbuffer(bundler.getchunks())
@getbundle2partsgenerator('changegroup')
def _getbundlechangegrouppart(bundler, repo, source, bundlecaps=None,
b2caps=None, heads=None, common=None, **kwargs):
"""add a changegroup part to the requested bundle"""
- cg = None
- if kwargs.get('cg', True):
- # build changegroup bundle here.
- version = '01'
- cgversions = b2caps.get('changegroup')
- if cgversions: # 3.1 and 3.2 ship with an empty value
- cgversions = [v for v in cgversions
- if v in changegroup.supportedoutgoingversions(repo)]
- if not cgversions:
- raise ValueError(_('no common changegroup version'))
- version = max(cgversions)
- outgoing = changegroup.computeoutgoing(repo, heads, common)
- cg = changegroup.getlocalchangegroupraw(repo, source, outgoing,
- bundlecaps=bundlecaps,
- version=version)
+ if not kwargs.get('cg', True):
+ return
- if cg:
- part = bundler.newpart('changegroup', data=cg)
- if cgversions:
- part.addparam('version', version)
- part.addparam('nbchanges', str(len(outgoing.missing)), mandatory=False)
- if 'treemanifest' in repo.requirements:
- part.addparam('treemanifest', '1')
+ # build changegroup bundle here.
+ version = '01'
+ cgversions = b2caps.get('changegroup')
+ if cgversions: # 3.1 and 3.2 ship with an empty value
+ cgversions = [v for v in cgversions
+ if v in changegroup.supportedoutgoingversions(repo)]
+ if not cgversions:
+ raise ValueError(_('no common changegroup version'))
+ version = max(cgversions)
+ outgoing = changegroup.computeoutgoing(repo, heads, common)
+ cg = changegroup.getlocalchangegroupraw(repo, source, outgoing,
+ bundlecaps=bundlecaps,
+ version=version)
+
+ if not cg:
+ return
+
+ part = bundler.newpart('changegroup', data=cg)
+ if cgversions:
+ part.addparam('version', version)
+ part.addparam('nbchanges', str(len(outgoing.missing)), mandatory=False)
+ if 'treemanifest' in repo.requirements:
+ part.addparam('treemanifest', '1')
@getbundle2partsgenerator('listkeys')
def _getbundlelistkeysparts(bundler, repo, source, bundlecaps=None,
b2caps=None, **kwargs):
"""add parts containing listkeys namespaces to the requested bundle"""
listkeys = kwargs.get('listkeys', ())
for namespace in listkeys:
part = bundler.newpart('listkeys')
More information about the Mercurial-devel
mailing list