diff mercurial/dispatch.py @ 19229:41e39a0299cb stable

blackbox: fix recording exit codes (issue3938) Previously the blackbox wrapped runcommand, but this failed to see the error codes that were created if an exception occurred. I moved that logging to now wrap _runcatch, so it can observe and log the actual error code (such as when a user ctrl+c's during a command). Updated the tests as well. Tested the change by running all the tests with the blackbox extension enabled and verifying nothing broke (aside from things that printed what extensions were enabeld). The progress tests are affected by calls to time.time() so they needed to be updated to pass.
author Durham Goode <durham@fb.com>
date Wed, 22 May 2013 17:31:47 -0700
parents fc081623f4bd
children 09573ad59f7b
line wrap: on
line diff
--- a/mercurial/dispatch.py	Tue May 21 15:31:56 2013 -0500
+++ b/mercurial/dispatch.py	Wed May 22 17:31:47 2013 -0700
@@ -62,7 +62,16 @@
             ferr.write(_("hg: parse error: %s\n") % inst.args[0])
         return -1
 
-    return _runcatch(req)
+    msg = ' '.join(' ' in a and repr(a) or a for a in req.args)
+    starttime = time.time()
+    ret = None
+    try:
+        ret = _runcatch(req)
+        return ret
+    finally:
+        duration = time.time() - starttime
+        req.ui.log("commandfinish", "%s exited %s after %0.2f seconds\n",
+                   msg, ret or 0, duration)
 
 def _runcatch(req):
     def catchterm(*args):
@@ -764,16 +773,10 @@
     msg = ' '.join(' ' in a and repr(a) or a for a in fullargs)
     ui.log("command", '%s\n', msg)
     d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
-    starttime = time.time()
-    ret = None
     try:
-        ret = runcommand(lui, repo, cmd, fullargs, ui, options, d,
-                         cmdpats, cmdoptions)
-        return ret
+        return runcommand(lui, repo, cmd, fullargs, ui, options, d,
+                          cmdpats, cmdoptions)
     finally:
-        duration = time.time() - starttime
-        ui.log("commandfinish", "%s exited %s after %0.2f seconds\n",
-               cmd, ret, duration)
         if repo and repo != req.repo:
             repo.close()