comparison mercurial/commands.py @ 46762:052ab8d0a538

command: clarify `postincoming` return and that return handling The command should return None or a return code. The previous code was returning boolean directly relying on the fact that `True ? 1` and `False ? 0`. This is a good road to troubles, so lets be explicit about that return. Differential Revision: https://phab.mercurial-scm.org/D10157
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 10 Mar 2021 05:54:27 +0100
parents 66fb04552122
children 954bad9c32a0
comparison
equal deleted inserted replaced
46761:af7535249ea9 46762:052ab8d0a538
5254 5254
5255 :modheads: change of heads by pull/unbundle 5255 :modheads: change of heads by pull/unbundle
5256 :optupdate: updating working directory is needed or not 5256 :optupdate: updating working directory is needed or not
5257 :checkout: update destination revision (or None to default destination) 5257 :checkout: update destination revision (or None to default destination)
5258 :brev: a name, which might be a bookmark to be activated after updating 5258 :brev: a name, which might be a bookmark to be activated after updating
5259
5260 return True if update raise any conflict, False otherwise.
5259 """ 5261 """
5260 if modheads == 0: 5262 if modheads == 0:
5261 return 5263 return False
5262 if optupdate: 5264 if optupdate:
5263 try: 5265 try:
5264 return hg.updatetotally(ui, repo, checkout, brev) 5266 return hg.updatetotally(ui, repo, checkout, brev)
5265 except error.UpdateAbort as inst: 5267 except error.UpdateAbort as inst:
5266 msg = _(b"not updating: %s") % stringutil.forcebytestr(inst) 5268 msg = _(b"not updating: %s") % stringutil.forcebytestr(inst)
5278 ) 5280 )
5279 else: 5281 else:
5280 ui.status(_(b"(run 'hg heads' to see heads)\n")) 5282 ui.status(_(b"(run 'hg heads' to see heads)\n"))
5281 elif not ui.configbool(b'commands', b'update.requiredest'): 5283 elif not ui.configbool(b'commands', b'update.requiredest'):
5282 ui.status(_(b"(run 'hg update' to get a working copy)\n")) 5284 ui.status(_(b"(run 'hg update' to get a working copy)\n"))
5285 return False
5283 5286
5284 5287
5285 @command( 5288 @command(
5286 b'pull', 5289 b'pull',
5287 [ 5290 [
5364 5367
5365 source, branches = hg.parseurl(ui.expandpath(source), opts.get(b'branch')) 5368 source, branches = hg.parseurl(ui.expandpath(source), opts.get(b'branch'))
5366 ui.status(_(b'pulling from %s\n') % util.hidepassword(source)) 5369 ui.status(_(b'pulling from %s\n') % util.hidepassword(source))
5367 ui.flush() 5370 ui.flush()
5368 other = hg.peer(repo, opts, source) 5371 other = hg.peer(repo, opts, source)
5372 update_conflict = None
5369 try: 5373 try:
5370 revs, checkout = hg.addbranchrevs( 5374 revs, checkout = hg.addbranchrevs(
5371 repo, other, branches, opts.get(b'rev') 5375 repo, other, branches, opts.get(b'rev')
5372 ) 5376 )
5373 5377
5442 brev = opts[b'branch'][0] 5446 brev = opts[b'branch'][0]
5443 else: 5447 else:
5444 brev = branches[0] 5448 brev = branches[0]
5445 repo._subtoppath = source 5449 repo._subtoppath = source
5446 try: 5450 try:
5447 ret = postincoming( 5451 update_conflict = postincoming(
5448 ui, repo, modheads, opts.get(b'update'), checkout, brev 5452 ui, repo, modheads, opts.get(b'update'), checkout, brev
5449 ) 5453 )
5450 except error.FilteredRepoLookupError as exc: 5454 except error.FilteredRepoLookupError as exc:
5451 msg = _(b'cannot update to target: %s') % exc.args[0] 5455 msg = _(b'cannot update to target: %s') % exc.args[0]
5452 exc.args = (msg,) + exc.args[1:] 5456 exc.args = (msg,) + exc.args[1:]
5454 finally: 5458 finally:
5455 del repo._subtoppath 5459 del repo._subtoppath
5456 5460
5457 finally: 5461 finally:
5458 other.close() 5462 other.close()
5459 return ret 5463 if update_conflict:
5464 return 1
5465 else:
5466 return 0
5460 5467
5461 5468
5462 @command( 5469 @command(
5463 b'purge|clean', 5470 b'purge|clean',
5464 [ 5471 [
7544 b"information" 7551 b"information"
7545 ), 7552 ),
7546 ) 7553 )
7547 modheads = bundle2.combinechangegroupresults(op) 7554 modheads = bundle2.combinechangegroupresults(op)
7548 7555
7549 return postincoming(ui, repo, modheads, opts.get('update'), None, None) 7556 if postincoming(ui, repo, modheads, opts.get('update'), None, None):
7557 return 1
7558 else:
7559 return 0
7550 7560
7551 7561
7552 @command( 7562 @command(
7553 b'unshelve', 7563 b'unshelve',
7554 [ 7564 [