D4820: logtoprocess: sends the canonical command name to the subprocess
This revision was automatically updated to reflect the committed changes. Closed by commit rHG106adc261492: logtoprocess: sends the canonical command name to the subprocess (authored by lothiraldan, committed by ). REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D4820?vs=12307=12308 REVISION DETAIL https://phab.mercurial-scm.org/D4820 AFFECTED FILES mercurial/dispatch.py tests/test-logtoprocess.t CHANGE DETAILS diff --git a/tests/test-logtoprocess.t b/tests/test-logtoprocess.t --- a/tests/test-logtoprocess.t +++ b/tests/test-logtoprocess.t @@ -17,7 +17,7 @@ > configitem('logtoprocess', 'foo', > default=None, > ) - > @command(b'foo', []) + > @command(b'foobar', []) > def foo(ui, repo): > ui.log('foo', 'a message: %s\n', 'spam') > EOF @@ -35,7 +35,8 @@ > echo "\$EVENT"; > echo "\$MSG1"; > echo "\$MSG2"; - > echo "\$MSG3") > $TESTTMP/commandfinish.log + > echo "\$MSG3"; + > echo "canonical: \$OPT_CANONICAL_COMMAND") > $TESTTMP/commandfinish.log > foo=(echo 'logtoprocess foo output:'; > echo "\$EVENT"; > echo "\$MSG1"; @@ -46,22 +47,23 @@ ui.log('commandfinish') call. The foo command also uses ui.log. Use sort to avoid ordering issues between the various processes we spawn: - $ hg foo + $ hg fooba $ sleep 1 $ cat $TESTTMP/command.log | sort command - foo - foo + fooba + fooba logtoprocess command output: #if no-chg $ cat $TESTTMP/commandfinish.log | sort 0 + canonical: foobar commandfinish - foo - foo exited 0 after * seconds (glob) + fooba + fooba exited 0 after * seconds (glob) logtoprocess commandfinish output: $ cat $TESTTMP/foo.log | sort 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"]: To: lothiraldan, #hg-reviewers Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D4820: logtoprocess: sends the canonical command name to the subprocess
lothiraldan updated this revision to Diff 12307. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D4820?vs=12298=12307 REVISION DETAIL https://phab.mercurial-scm.org/D4820 AFFECTED FILES mercurial/dispatch.py tests/test-logtoprocess.t CHANGE DETAILS diff --git a/tests/test-logtoprocess.t b/tests/test-logtoprocess.t --- a/tests/test-logtoprocess.t +++ b/tests/test-logtoprocess.t @@ -17,7 +17,7 @@ > configitem('logtoprocess', 'foo', > default=None, > ) - > @command(b'foo', []) + > @command(b'foobar', []) > def foo(ui, repo): > ui.log('foo', 'a message: %s\n', 'spam') > EOF @@ -35,7 +35,8 @@ > echo "\$EVENT"; > echo "\$MSG1"; > echo "\$MSG2"; - > echo "\$MSG3") > $TESTTMP/commandfinish.log + > echo "\$MSG3"; + > echo "canonical: \$OPT_CANONICAL_COMMAND") > $TESTTMP/commandfinish.log > foo=(echo 'logtoprocess foo output:'; > echo "\$EVENT"; > echo "\$MSG1"; @@ -46,22 +47,23 @@ ui.log('commandfinish') call. The foo command also uses ui.log. Use sort to avoid ordering issues between the various processes we spawn: - $ hg foo + $ hg fooba $ sleep 1 $ cat $TESTTMP/command.log | sort command - foo - foo + fooba + fooba logtoprocess command output: #if no-chg $ cat $TESTTMP/commandfinish.log | sort 0 + canonical: foobar commandfinish - foo - foo exited 0 after * seconds (glob) + fooba + fooba exited 0 after * seconds (glob) logtoprocess commandfinish output: $ cat $TESTTMP/foo.log | sort 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"]: To: lothiraldan, #hg-reviewers Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D4820: logtoprocess: sends the canonical command name to the subprocess
lothiraldan added a comment. In https://phab.mercurial-scm.org/D4820#77397, @yuja wrote: > > +# extract the canonical command from the passed opts. > > +# we need to pop it up from the opts else the msg will try > > +# being formatted using the passed opts. > > Oops, that's probably a bug. IIUC, `**opts` is just ancillary data, and > the `msg[0]` should always be parameterized by `msg[1:]`. That's how blackbox > works. > > Can you send a separate patch to fix the issue? Done, I hope the stack was correctly saved because I had to to it through the interface, `phabsend` didn't worked. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D4820 To: lothiraldan, #hg-reviewers Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D4820: logtoprocess: sends the canonical command name to the subprocess
lothiraldan updated this revision to Diff 12298. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D4820?vs=12296=12298 REVISION DETAIL https://phab.mercurial-scm.org/D4820 AFFECTED FILES mercurial/dispatch.py tests/test-logtoprocess.t CHANGE DETAILS diff --git a/tests/test-logtoprocess.t b/tests/test-logtoprocess.t --- a/tests/test-logtoprocess.t +++ b/tests/test-logtoprocess.t @@ -17,7 +17,7 @@ > configitem('logtoprocess', 'foo', > default=None, > ) - > @command(b'foo', []) + > @command(b'foobar', []) > def foo(ui, repo): > ui.log('foo', 'a message: %s\n', 'spam') > EOF @@ -35,7 +35,8 @@ > echo "\$EVENT"; > echo "\$MSG1"; > echo "\$MSG2"; - > echo "\$MSG3") > $TESTTMP/commandfinish.log + > echo "\$MSG3"; + > echo "canonical: \$OPT_CANONICAL_COMMAND") > $TESTTMP/commandfinish.log > foo=(echo 'logtoprocess foo output:'; > echo "\$EVENT"; > echo "\$MSG1"; @@ -46,22 +47,23 @@ ui.log('commandfinish') call. The foo command also uses ui.log. Use sort to avoid ordering issues between the various processes we spawn: - $ hg foo + $ hg fooba $ sleep 0.2 $ cat $TESTTMP/command.log | sort command - foo - foo + fooba + fooba logtoprocess command output: #if no-chg $ cat $TESTTMP/commandfinish.log | sort 0 + canonical: foobar commandfinish - foo - foo exited 0 after * seconds (glob) + fooba + fooba exited 0 after * seconds (glob) logtoprocess commandfinish output: $ cat $TESTTMP/foo.log | sort 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"]: To: lothiraldan, #hg-reviewers Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D4820: logtoprocess: sends the canonical command name to the subprocess
yuja added a comment. > +# extract the canonical command from the passed opts. > +# we need to pop it up from the opts else the msg will try > +# being formatted using the passed opts. Oops, that's probably a bug. IIUC, `**opts` is just ancillary data, and the `msg[0]` should always be parameterized by `msg[1:]`. That's how blackbox works. Can you send a separate patch to fix the issue? REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D4820 To: lothiraldan, #hg-reviewers Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D4820: logtoprocess: sends the canonical command name to the subprocess
lothiraldan updated this revision to Diff 12296. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D4820?vs=12161=12296 REVISION DETAIL https://phab.mercurial-scm.org/D4820 AFFECTED FILES hgext/logtoprocess.py mercurial/dispatch.py tests/test-logtoprocess.t CHANGE DETAILS diff --git a/tests/test-logtoprocess.t b/tests/test-logtoprocess.t --- a/tests/test-logtoprocess.t +++ b/tests/test-logtoprocess.t @@ -17,7 +17,7 @@ > configitem('logtoprocess', 'foo', > default=None, > ) - > @command(b'foo', []) + > @command(b'foobar', []) > def foo(ui, repo): > ui.log('foo', 'a message: %(bar)s\n', bar='spam') > EOF @@ -35,7 +35,8 @@ > echo "\$EVENT"; > echo "\$MSG1"; > echo "\$MSG2"; - > echo "\$MSG3") > $TESTTMP/commandfinish.log + > echo "\$MSG3"; + > echo "canonical: \$OPT_CANONICAL_COMMAND") > $TESTTMP/commandfinish.log > foo=(echo 'logtoprocess foo output:'; > echo "\$EVENT"; > echo "\$MSG1"; @@ -46,22 +47,23 @@ ui.log('commandfinish') call. The foo command also uses ui.log. Use sort to avoid ordering issues between the various processes we spawn: - $ hg foo + $ hg fooba $ sleep 0.2 $ cat $TESTTMP/command.log | sort command - foo - foo + fooba + fooba logtoprocess command output: #if no-chg $ cat $TESTTMP/commandfinish.log | sort 0 + canonical: foobar commandfinish - foo - foo exited 0 after * seconds (glob) + fooba + fooba exited 0 after * seconds (glob) logtoprocess commandfinish output: $ cat $TESTTMP/foo.log | sort 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 @@ -110,6 +110,14 @@ script = self.config('logtoprocess', event) if script: if msg: + +# extract the canonical command from the passed opts. +# we need to pop it up from the opts else the msg will try +# being formatted using 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 +142,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()), + OPT_CANONICAL_COMMAND=canonical_command) runshellcommand(script, env) return super(logtoprocessui, self).log(event, *msg, **opts) To: lothiraldan, #hg-reviewers Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D4820: logtoprocess: sends the canonical command name to the subprocess
yuja added a comment. > - a/hgext/logtoprocess.py +++ b/hgext/logtoprocess.py @@ -40,6 +40,9 @@ import sys > > from mercurial import ( +dispatch, +encoding, +extensions, Unused. > @@ -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 = "" > + > > 1. try to format the log message given the remaining > 2. 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) As I said before, `LTP_*` doesn't sound great. Can't we simply pass in `canonical_command` as `OPT_CANONICAL_COMMAND`? If we really want to name it other than `OPT_*`, please document it. And I noticed there's no test. Can you add some? REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D4820 To: lothiraldan, #hg-reviewers Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Re: D4820: logtoprocess: sends the canonical command name to the subprocess
> --- a/hgext/logtoprocess.py > +++ b/hgext/logtoprocess.py > @@ -40,6 +40,9 @@ > import sys > > from mercurial import ( > +dispatch, > +encoding, > +extensions, Unused. > @@ -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) As I said before, `LTP_*` doesn't sound great. Can't we simply pass in `canonical_command` as `OPT_CANONICAL_COMMAND`? If we really want to name it other than `OPT_*`, please document it. And I noticed there's no test. Can you add some? ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D4820: logtoprocess: sends the canonical command name to the subprocess
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=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 ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D4820: logtoprocess: sends the canonical command name to the subprocess
yuja added a comment. > I tried to pass it to the `ui.log()` but didn't find a clean way to transfer it from `dispatch._dispatch` to `dispatch.dispatch`. I tried storing it in the ui object but without luck. > > Do you think it would be ok to store it in the `request` object? If that helps, yes. I think using `request` object is better than abusing `ui`, given the command lifetime is quite the same as the request. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D4820 To: lothiraldan, #hg-reviewers Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Re: D4820: logtoprocess: sends the canonical command name to the subprocess
> I tried to pass it to the `ui.log()` but didn't find a clean way to > transfer it from `dispatch._dispatch` to `dispatch.dispatch`. I tried storing > it in the ui object but without luck. > > Do you think it would be ok to store it in the `request` object? If that helps, yes. I think using `request` object is better than abusing `ui`, given the command lifetime is quite the same as the request. ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D4820: logtoprocess: sends the canonical command name to the subprocess
lothiraldan added a comment. In https://phab.mercurial-scm.org/D4820#73256, @yuja wrote: > > +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) > > It's scary to update the environment variables globally and pass > `LTP_COMMAND` in to any child processes. > > Can you add a proper way to teach the command name to the logtoprocess > extension, by `ui.log()` for example? > > Also, the word `LTP` isn't used anywhere. It'll need a better name, and > should be documented. I tried to pass it to the `ui.log()` but didn't find a clean way to transfer it from `dispatch._dispatch` to `dispatch.dispatch`. I tried storing it in the ui object but without luck. Do you think it would be ok to store it in the `request` object? REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D4820 To: lothiraldan, #hg-reviewers Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D4820: logtoprocess: sends the canonical command name to the subprocess
yuja added a comment. > +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) It's scary to update the environment variables globally and pass `LTP_COMMAND` in to any child processes. Can you add a proper way to teach the command name to the logtoprocess extension, by `ui.log()` for example? Also, the word `LTP` isn't used anywhere. It'll need a better name, and should be documented. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D4820 To: lothiraldan, #hg-reviewers Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Re: D4820: logtoprocess: sends the canonical command name to the subprocess
> +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) It's scary to update the environment variables globally and pass `LTP_COMMAND` in to any child processes. Can you add a proper way to teach the command name to the logtoprocess extension, by `ui.log()` for example? Also, the word `LTP` isn't used anywhere. It'll need a better name, and should be documented. ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D4820: logtoprocess: sends the canonical command name to the subprocess
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