diff mercurial/dispatch.py @ 40402:106adc261492

logtoprocess: sends the canonical command name to the subprocess One of the use-case of logtoprocess is to monitor command duration. With the current code, we only get whatever command name the user typed (either abbreviated or aliased). This makes analytics on the collected data more difficult. Stores the canonical command name in the request object. Pass the stored canonical name in the `req.ui.log("commandfinish", ...)` call as keyword argument to not break potential string formatting. Pass the value as the environment variable named `LTP_COMMAND` to the called script. Differential Revision: https://phab.mercurial-scm.org/D4820
author Boris Feld <boris.feld@octobus.net>
date Mon, 22 Oct 2018 15:51:01 +0200
parents 24e493ec2229
children 444861dc1e55
line wrap: on
line diff
--- a/mercurial/dispatch.py	Mon Oct 22 15:47:30 2018 +0200
+++ b/mercurial/dispatch.py	Mon Oct 22 15:51:01 2018 +0200
@@ -66,6 +66,9 @@
         # low-level repo state (for example, changelog) before extensions.
         self.prereposetups = prereposetups or []
 
+        # store the parsed and canonical command
+        self.canonical_command = None
+
     def _runexithandlers(self):
         exc = None
         handlers = self.ui._exithandlers
@@ -243,7 +246,8 @@
                 req.ui.log('uiblocked', 'ui blocked ms',
                            **pycompat.strkwargs(req.ui._blockedtimes))
             req.ui.log("commandfinish", "%s exited %d after %0.2f seconds\n",
-                       msg, ret & 255, duration)
+                       msg, ret & 255, duration,
+                       canonical_command=req.canonical_command)
             try:
                 req._runexithandlers()
             except: # exiting, so no re-raises
@@ -853,6 +857,9 @@
         fullargs = args
         cmd, func, args, options, cmdoptions = _parse(lui, args)
 
+        # store the canonical command name in request object for later access
+        req.canonical_command = cmd
+
         if options["config"] != req.earlyoptions["config"]:
             raise error.Abort(_("option --config may not be abbreviated!"))
         if options["cwd"] != req.earlyoptions["cwd"]: