lothiraldan created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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. Update log to
  process to wrap the first function that gets the canonical command name in
  parameter `dispatch.runcommand` and create the environment variable
  `LTP_COMMAND` with its value.
  
  I tried storing the value in the `logtoprocessui` instead but the ui object is
  instantiated and copied too many time to safely gets the right instance with
  the value everywhere.
  
  I tested the patch with CHG and saw no incorrect behaviors. If someone with
  more CHG experience could confirm that it won't lead to incorrect behavior and
  incorrect values sent, I'm not an expert in CHG.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/logtoprocess.py

CHANGE DETAILS

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,
 )
 
@@ -53,6 +56,19 @@
 # leave the attribute unspecified.
 testedwith = 'ships-with-hg-core'
 
+def extsetup():
+    # this is to get the canonical name of the command: "commit", not "ci"
+    def wrapdispatch(orig, *args, **kwargs):
+        encoding.environ.pop("LTP_COMMAND", None)
+        return orig(*args, **kwargs)
+
+    def wrapruncommand(orig, *args, **kwargs):
+        encoding.environ["LTP_COMMAND"] = args[2]
+        return orig(*args, **kwargs)
+
+    extensions.wrapfunction(dispatch,'dispatch',wrapdispatch)
+    extensions.wrapfunction(dispatch,'runcommand',wrapruncommand)
+
 def uisetup(ui):
     if pycompat.iswindows:
         # no fork on Windows, but we can create a detached process



To: lothiraldan, #hg-reviewers
Cc: mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to