D4820: logtoprocess: sends the canonical command name to the subprocess

lothiraldan (Boris Feld) phabricator at mercurial-scm.org
Tue Oct 16 11:10:24 EDT 2018


lothiraldan updated this revision to Diff 12161.
lothiraldan edited the summary of this revision.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4820?vs=11521&id=12161

REVISION DETAIL
  https://phab.mercurial-scm.org/D4820

AFFECTED FILES
  hgext/logtoprocess.py
  mercurial/dispatch.py

CHANGE DETAILS

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -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"]:
diff --git a/hgext/logtoprocess.py b/hgext/logtoprocess.py
--- a/hgext/logtoprocess.py
+++ b/hgext/logtoprocess.py
@@ -40,6 +40,9 @@
 import sys
 
 from mercurial import (
+    dispatch,
+    encoding,
+    extensions,
     pycompat,
 )
 
@@ -110,6 +113,12 @@
             script = self.config('logtoprocess', event)
             if script:
                 if msg:
+
+                    # extract the canonical command from the passed opts
+                    canonical_command = opts.pop("canonical_command", None)
+                    if canonical_command is None:
+                        canonical_command = ""
+
                     # try to format the log message given the remaining
                     # arguments
                     try:
@@ -134,7 +143,8 @@
                     for key, value in opts.iteritems())
                 env = dict(itertools.chain(procutil.shellenviron().items(),
                                            msgpairs, optpairs),
-                           EVENT=event, HGPID=str(os.getpid()))
+                           EVENT=event, HGPID=str(os.getpid()),
+                           LTP_COMMAND=canonical_command)
                 runshellcommand(script, env)
             return super(logtoprocessui, self).log(event, *msg, **opts)
 



To: lothiraldan, #hg-reviewers
Cc: yuja, mercurial-devel


More information about the Mercurial-devel mailing list