comparison mercurial/exchange.py @ 43790:44b605638918

exchange: guard against method invocation on `b2caps=None` args I couldn't figure out how these are called, but the value is pretty obviously set at least for the cases that have tests. Differential Revision: https://phab.mercurial-scm.org/D7512
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 23 Nov 2019 00:03:18 -0500
parents 27c6d6f53d46
children 0f6782df1100
comparison
equal deleted inserted replaced
43789:27c6d6f53d46 43790:44b605638918
2472 heads=None, 2472 heads=None,
2473 common=None, 2473 common=None,
2474 **kwargs 2474 **kwargs
2475 ): 2475 ):
2476 """add a changegroup part to the requested bundle""" 2476 """add a changegroup part to the requested bundle"""
2477 if not kwargs.get('cg', True): 2477 if not kwargs.get('cg', True) or not b2caps:
2478 return 2478 return
2479 2479
2480 version = b'01' 2480 version = b'01'
2481 cgversions = b2caps.get(b'changegroup') 2481 cgversions = b2caps.get(b'changegroup')
2482 if cgversions: # 3.1 and 3.2 ship with an empty value 2482 if cgversions: # 3.1 and 3.2 ship with an empty value
2534 bundler, repo, source, bundlecaps=None, b2caps=None, **kwargs 2534 bundler, repo, source, bundlecaps=None, b2caps=None, **kwargs
2535 ): 2535 ):
2536 """add a bookmark part to the requested bundle""" 2536 """add a bookmark part to the requested bundle"""
2537 if not kwargs.get('bookmarks', False): 2537 if not kwargs.get('bookmarks', False):
2538 return 2538 return
2539 if b'bookmarks' not in b2caps: 2539 if not b2caps or b'bookmarks' not in b2caps:
2540 raise error.Abort(_(b'no common bookmarks exchange method')) 2540 raise error.Abort(_(b'no common bookmarks exchange method'))
2541 books = bookmod.listbinbookmarks(repo) 2541 books = bookmod.listbinbookmarks(repo)
2542 data = bookmod.binaryencode(books) 2542 data = bookmod.binaryencode(books)
2543 if data: 2543 if data:
2544 bundler.newpart(b'bookmarks', data=data) 2544 bundler.newpart(b'bookmarks', data=data)
2575 def _getbundlephasespart( 2575 def _getbundlephasespart(
2576 bundler, repo, source, bundlecaps=None, b2caps=None, heads=None, **kwargs 2576 bundler, repo, source, bundlecaps=None, b2caps=None, heads=None, **kwargs
2577 ): 2577 ):
2578 """add phase heads part to the requested bundle""" 2578 """add phase heads part to the requested bundle"""
2579 if kwargs.get('phases', False): 2579 if kwargs.get('phases', False):
2580 if not b'heads' in b2caps.get(b'phases'): 2580 if not b2caps or not b'heads' in b2caps.get(b'phases'):
2581 raise error.Abort(_(b'no common phases exchange method')) 2581 raise error.Abort(_(b'no common phases exchange method'))
2582 if heads is None: 2582 if heads is None:
2583 heads = repo.heads() 2583 heads = repo.heads()
2584 2584
2585 headsbyphase = collections.defaultdict(set) 2585 headsbyphase = collections.defaultdict(set)
2639 filenodes raw values. 2639 filenodes raw values.
2640 """ 2640 """
2641 # Don't send unless: 2641 # Don't send unless:
2642 # - changeset are being exchanged, 2642 # - changeset are being exchanged,
2643 # - the client supports it. 2643 # - the client supports it.
2644 if not (kwargs.get('cg', True) and b'hgtagsfnodes' in b2caps): 2644 if not b2caps or not (kwargs.get('cg', True) and b'hgtagsfnodes' in b2caps):
2645 return 2645 return
2646 2646
2647 outgoing = _computeoutgoing(repo, heads, common) 2647 outgoing = _computeoutgoing(repo, heads, common)
2648 bundle2.addparttagsfnodescache(repo, bundler, outgoing) 2648 bundle2.addparttagsfnodescache(repo, bundler, outgoing)
2649 2649
2673 # - changeset are being exchanged, 2673 # - changeset are being exchanged,
2674 # - the client supports it. 2674 # - the client supports it.
2675 # - narrow bundle isn't in play (not currently compatible). 2675 # - narrow bundle isn't in play (not currently compatible).
2676 if ( 2676 if (
2677 not kwargs.get('cg', True) 2677 not kwargs.get('cg', True)
2678 or not b2caps
2678 or b'rev-branch-cache' not in b2caps 2679 or b'rev-branch-cache' not in b2caps
2679 or kwargs.get('narrow', False) 2680 or kwargs.get('narrow', False)
2680 or repo.ui.has_section(_NARROWACL_SECTION) 2681 or repo.ui.has_section(_NARROWACL_SECTION)
2681 ): 2682 ):
2682 return 2683 return