changeset 38038:6f9ac3cb0987

dispatch: unify handling of None returned by a command function A command function may return None in place of 0 just for convenience, but dispatch() doesn't need to inherit that property. This patch makes it be friendly to callers.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 12 May 2018 15:33:09 +0900
parents e9c588802529
children 0fa050bc68cb
files mercurial/commandserver.py mercurial/dispatch.py tests/test-blackbox.t tests/test-dispatch.py.out
diffstat 4 files changed, 14 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commandserver.py	Fri May 11 21:23:48 2018 -0700
+++ b/mercurial/commandserver.py	Sat May 12 15:33:09 2018 +0900
@@ -256,7 +256,7 @@
                                self.cout, self.cerr)
 
         try:
-            ret = (dispatch.dispatch(req) or 0) & 255 # might return None
+            ret = dispatch.dispatch(req) & 255
             self.cresult.write(struct.pack('>i', int(ret)))
         finally:
             # restore old cwd
--- a/mercurial/dispatch.py	Fri May 11 21:23:48 2018 -0700
+++ b/mercurial/dispatch.py	Sat May 12 15:33:09 2018 +0900
@@ -87,7 +87,7 @@
     req = request(pycompat.sysargv[1:])
     err = None
     try:
-        status = dispatch(req) or 0
+        status = dispatch(req)
     except error.StdioError as e:
         err = e
         status = -1
@@ -175,7 +175,7 @@
     return ' '.join(procutil.shellquote(a) for a in args)
 
 def dispatch(req):
-    "run the command specified in req.args"
+    """run the command specified in req.args; returns an integer status code"""
     if req.ferr:
         ferr = req.ferr
     elif req.ui:
@@ -208,9 +208,9 @@
 
     msg = _formatargs(req.args)
     starttime = util.timer()
-    ret = None
+    ret = -1
     try:
-        ret = _runcatch(req)
+        ret = _runcatch(req) or 0
     except error.ProgrammingError as inst:
         req.ui.warn(_('** ProgrammingError: %s\n') % inst)
         if inst.hint:
--- a/tests/test-blackbox.t	Fri May 11 21:23:48 2018 -0700
+++ b/tests/test-blackbox.t	Sat May 12 15:33:09 2018 +0900
@@ -206,7 +206,7 @@
   committing changelog
   updating the branch cache
   committed changeset 0:0e46349438790c460c5c9f7546bfcd39b267bbd2
-  result: None
+  result: 0
   running: --debug commit -m commit2 -d 2000-01-02 foo
   committing files:
   foo
@@ -214,7 +214,7 @@
   committing changelog
   updating the branch cache
   committed changeset 1:45589e459b2edfbf3dbde7e01f611d2c1e7453d7
-  result: None
+  result: 0
   running: --debug log -r 0
   changeset:   0:0e46349438790c460c5c9f7546bfcd39b267bbd2
   phase:       draft
@@ -229,7 +229,7 @@
   commit1
   
   
-  result: None
+  result: 0
   running: --debug log -r tip
   changeset:   1:45589e459b2edfbf3dbde7e01f611d2c1e7453d7
   tag:         tip
@@ -245,7 +245,7 @@
   commit2
   
   
-  result: None
+  result: 0
   $ hg blackbox
   1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> updating the branch cache
   1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> updated served branch cache in * seconds (glob)
--- a/tests/test-dispatch.py.out	Fri May 11 21:23:48 2018 -0700
+++ b/tests/test-dispatch.py.out	Sat May 12 15:33:09 2018 +0900
@@ -1,18 +1,18 @@
 running: init test1
-result: None
+result: 0
 running: add foo
 result: 0
 running: commit -m commit1 -d 2000-01-01 foo
-result: None
+result: 0
 running: commit -m commit2 -d 2000-01-02 foo
-result: None
+result: 0
 running: log -r 0
 changeset:   0:0e4634943879
 user:        test
 date:        Sat Jan 01 00:00:00 2000 +0000
 summary:     commit1
 
-result: None
+result: 0
 running: log -r tip
 changeset:   1:45589e459b2e
 tag:         tip
@@ -20,4 +20,4 @@
 date:        Sun Jan 02 00:00:00 2000 +0000
 summary:     commit2
 
-result: None
+result: 0