D10157: command: clarify `postincoming` return and that return handling
marmoute (Pierre-Yves David)
phabricator at mercurial-scm.org
Thu Mar 11 16:53:23 UTC 2021
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
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.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D10157
AFFECTED FILES
mercurial/commands.py
CHANGE DETAILS
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5256,9 +5256,11 @@
:optupdate: updating working directory is needed or not
:checkout: update destination revision (or None to default destination)
:brev: a name, which might be a bookmark to be activated after updating
+
+ return True if update raise any conflict, False otherwise.
"""
if modheads == 0:
- return
+ return False
if optupdate:
try:
return hg.updatetotally(ui, repo, checkout, brev)
@@ -5280,6 +5282,7 @@
ui.status(_(b"(run 'hg heads' to see heads)\n"))
elif not ui.configbool(b'commands', b'update.requiredest'):
ui.status(_(b"(run 'hg update' to get a working copy)\n"))
+ return False
@command(
@@ -5366,6 +5369,7 @@
ui.status(_(b'pulling from %s\n') % util.hidepassword(source))
ui.flush()
other = hg.peer(repo, opts, source)
+ update_conflict = None
try:
revs, checkout = hg.addbranchrevs(
repo, other, branches, opts.get(b'rev')
@@ -5444,7 +5448,7 @@
brev = branches[0]
repo._subtoppath = source
try:
- ret = postincoming(
+ update_conflict = postincoming(
ui, repo, modheads, opts.get(b'update'), checkout, brev
)
except error.FilteredRepoLookupError as exc:
@@ -5456,7 +5460,10 @@
finally:
other.close()
- return ret
+ if update_conflict:
+ return 1
+ else:
+ return 0
@command(
@@ -7546,7 +7553,10 @@
)
modheads = bundle2.combinechangegroupresults(op)
- return postincoming(ui, repo, modheads, opts.get('update'), None, None)
+ if postincoming(ui, repo, modheads, opts.get('update'), None, None):
+ return 1
+ else:
+ return 0
@command(
To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
More information about the Mercurial-devel
mailing list