comparison mercurial/dispatch.py @ 37995: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 48853a927757
comparison
equal deleted inserted replaced
37994:e9c588802529 37995:6f9ac3cb0987
85 "run the command in sys.argv" 85 "run the command in sys.argv"
86 initstdio() 86 initstdio()
87 req = request(pycompat.sysargv[1:]) 87 req = request(pycompat.sysargv[1:])
88 err = None 88 err = None
89 try: 89 try:
90 status = dispatch(req) or 0 90 status = dispatch(req)
91 except error.StdioError as e: 91 except error.StdioError as e:
92 err = e 92 err = e
93 status = -1 93 status = -1
94 94
95 # In all cases we try to flush stdio streams. 95 # In all cases we try to flush stdio streams.
173 173
174 def _formatargs(args): 174 def _formatargs(args):
175 return ' '.join(procutil.shellquote(a) for a in args) 175 return ' '.join(procutil.shellquote(a) for a in args)
176 176
177 def dispatch(req): 177 def dispatch(req):
178 "run the command specified in req.args" 178 """run the command specified in req.args; returns an integer status code"""
179 if req.ferr: 179 if req.ferr:
180 ferr = req.ferr 180 ferr = req.ferr
181 elif req.ui: 181 elif req.ui:
182 ferr = req.ui.ferr 182 ferr = req.ui.ferr
183 else: 183 else:
206 _formatparse(ferr.write, inst) 206 _formatparse(ferr.write, inst)
207 return -1 207 return -1
208 208
209 msg = _formatargs(req.args) 209 msg = _formatargs(req.args)
210 starttime = util.timer() 210 starttime = util.timer()
211 ret = None 211 ret = -1
212 try: 212 try:
213 ret = _runcatch(req) 213 ret = _runcatch(req) or 0
214 except error.ProgrammingError as inst: 214 except error.ProgrammingError as inst:
215 req.ui.warn(_('** ProgrammingError: %s\n') % inst) 215 req.ui.warn(_('** ProgrammingError: %s\n') % inst)
216 if inst.hint: 216 if inst.hint:
217 req.ui.warn(_('** (%s)\n') % inst.hint) 217 req.ui.warn(_('** (%s)\n') % inst.hint)
218 raise 218 raise