changeset 46775: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 af7535249ea9
children 954bad9c32a0
files mercurial/commands.py
diffstat 1 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Wed Mar 10 05:54:02 2021 +0100
+++ b/mercurial/commands.py	Wed Mar 10 05:54:27 2021 +0100
@@ -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(