Patchwork dispatch: fix so that --help more reliably shows command help (issue4240)

login
register
mail settings
Submitter Prabhu GS
Date July 1, 2014, 5:05 p.m.
Message ID <43e4cd31fae70005b468.1404234355@sparta.ap01.lucent.com>
Download mbox | patch
Permalink /patch/5091/
State Accepted
Headers show

Comments

Prabhu GS - July 1, 2014, 5:05 p.m.
# HG changeset patch
# User Prabhu Gnana Sundar <pprabhugs@gmail.com>
# Date 1404234214 -19800
#      Tue Jul 01 22:33:34 2014 +0530
# Node ID 43e4cd31fae70005b4680ccb53b51f46b962e5b6
# Parent  99db956b88ab699644c99095fecadbc4c83adbfc
dispatch: fix so that --help more reliably shows command help (issue4240)

After hg 3.0, "hg showconfig --help" was showing the configuration man page
instead of the 'hg help -c showconfig' output.

This patch fixes the 'hg showconfig --help' regression issue by removing an
unwanted assignement of aliases[0] to cmd and shows the correct command
in the first line of help description.
Also, added a test case to test 'hg showconfig --help'.
Prabhu GS - July 8, 2014, 7:25 p.m.
Hi,

Waiting for the patch to be reviewed..


Cheers,
Prabhu


On Tue, Jul 1, 2014 at 10:35 PM, Prabhu Gnana Sundar <pprabhugs@gmail.com>
wrote:

> # HG changeset patch
> # User Prabhu Gnana Sundar <pprabhugs@gmail.com>
> # Date 1404234214 -19800
> #      Tue Jul 01 22:33:34 2014 +0530
> # Node ID 43e4cd31fae70005b4680ccb53b51f46b962e5b6
> # Parent  99db956b88ab699644c99095fecadbc4c83adbfc
> dispatch: fix so that --help more reliably shows command help (issue4240)
>
> After hg 3.0, "hg showconfig --help" was showing the configuration man page
> instead of the 'hg help -c showconfig' output.
>
> This patch fixes the 'hg showconfig --help' regression issue by removing an
> unwanted assignement of aliases[0] to cmd and shows the correct command
> in the first line of help description.
> Also, added a test case to test 'hg showconfig --help'.
>
> diff -r 99db956b88ab -r 43e4cd31fae7 mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py      Sun Jun 01 16:01:01 2014 -0700
> +++ b/mercurial/cmdutil.py      Tue Jul 01 22:33:34 2014 +0530
> @@ -39,11 +39,13 @@
>          if cmd in aliases:
>              found = cmd
>          elif not strict:
> -            for a in aliases:
> -                if a.startswith(cmd):
> -                    found = a
> +            for alias in aliases:
> +                if alias.startswith(cmd):
> +                    found = alias
>                      break
>          if found is not None:
> +            aliases = [alias for alias in aliases if alias != cmd]
> +            aliases.insert(0, cmd)
>              if aliases[0].startswith("debug") or
> found.startswith("debug"):
>                  debugchoice[found] = (aliases, table[e])
>              else:
> diff -r 99db956b88ab -r 43e4cd31fae7 mercurial/dispatch.py
> --- a/mercurial/dispatch.py     Sun Jun 01 16:01:01 2014 -0700
> +++ b/mercurial/dispatch.py     Tue Jul 01 22:33:34 2014 +0530
> @@ -494,7 +494,6 @@
>          cmd, args = args[0], args[1:]
>          aliases, entry = cmdutil.findcmd(cmd, commands.table,
>                                           ui.configbool("ui", "strict"))
> -        cmd = aliases[0]
>          args = aliasargs(entry[0], args)
>          defaults = ui.config("defaults", cmd)
>          if defaults:
> diff -r 99db956b88ab -r 43e4cd31fae7 tests/test-help.t
> --- a/tests/test-help.t Sun Jun 01 16:01:01 2014 -0700
> +++ b/tests/test-help.t Tue Jul 01 22:33:34 2014 +0530
> @@ -2085,3 +2085,41 @@
>    $ "$TESTDIR/killdaemons.py" $DAEMON_PIDS
>
>  #endif
> +
> +
> +Test showconfig help
> +
> +  $ hg showconfig --help
> +  hg showconfig [-u] [NAME]...
> +
> +  aliases: config, debugconfig
> +
> +  show combined config settings from all hgrc files
> +
> +      With no arguments, print names and values of all config items.
> +
> +      With one argument of the form section.name, print just the value
> of that
> +      config item.
> +
> +      With multiple arguments, print names and values of all config items
> with
> +      matching section names.
> +
> +      With --edit, start an editor on the user-level config file. With
> --global,
> +      edit the system-wide config file. With --local, edit the
> repository-level
> +      config file.
> +
> +      With --debug, the source (filename and line number) is printed for
> each
> +      config item.
> +
> +      See "hg help config" for more information about config files.
> +
> +      Returns 0 on success.
> +
> +  options:
> +
> +   -u --untrusted show untrusted configuration options
> +   -e --edit      edit user config
> +   -l --local     edit repository config
> +   -g --global    edit global config
> +
> +  use "hg -v help showconfig" to show the global options
>
Augie Fackler - July 9, 2014, 1:43 a.m.
On Tue, Jul 01, 2014 at 10:35:55PM +0530, Prabhu Gnana Sundar wrote:
> # HG changeset patch
> # User Prabhu Gnana Sundar <pprabhugs@gmail.com>
> # Date 1404234214 -19800
> #      Tue Jul 01 22:33:34 2014 +0530
> # Node ID 43e4cd31fae70005b4680ccb53b51f46b962e5b6
> # Parent  99db956b88ab699644c99095fecadbc4c83adbfc
> dispatch: fix so that --help more reliably shows command help (issue4240)

Queued after spending smoe time meditating on the dispatch code again.

>
> After hg 3.0, "hg showconfig --help" was showing the configuration man page
> instead of the 'hg help -c showconfig' output.
>
> This patch fixes the 'hg showconfig --help' regression issue by removing an
> unwanted assignement of aliases[0] to cmd and shows the correct command
> in the first line of help description.
> Also, added a test case to test 'hg showconfig --help'.
>
> diff -r 99db956b88ab -r 43e4cd31fae7 mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py	Sun Jun 01 16:01:01 2014 -0700
> +++ b/mercurial/cmdutil.py	Tue Jul 01 22:33:34 2014 +0530
> @@ -39,11 +39,13 @@
>          if cmd in aliases:
>              found = cmd
>          elif not strict:
> -            for a in aliases:
> -                if a.startswith(cmd):
> -                    found = a
> +            for alias in aliases:
> +                if alias.startswith(cmd):
> +                    found = alias
>                      break
>          if found is not None:
> +            aliases = [alias for alias in aliases if alias != cmd]
> +            aliases.insert(0, cmd)
>              if aliases[0].startswith("debug") or found.startswith("debug"):
>                  debugchoice[found] = (aliases, table[e])
>              else:
> diff -r 99db956b88ab -r 43e4cd31fae7 mercurial/dispatch.py
> --- a/mercurial/dispatch.py	Sun Jun 01 16:01:01 2014 -0700
> +++ b/mercurial/dispatch.py	Tue Jul 01 22:33:34 2014 +0530
> @@ -494,7 +494,6 @@
>          cmd, args = args[0], args[1:]
>          aliases, entry = cmdutil.findcmd(cmd, commands.table,
>                                           ui.configbool("ui", "strict"))
> -        cmd = aliases[0]
>          args = aliasargs(entry[0], args)
>          defaults = ui.config("defaults", cmd)
>          if defaults:
> diff -r 99db956b88ab -r 43e4cd31fae7 tests/test-help.t
> --- a/tests/test-help.t	Sun Jun 01 16:01:01 2014 -0700
> +++ b/tests/test-help.t	Tue Jul 01 22:33:34 2014 +0530
> @@ -2085,3 +2085,41 @@
>    $ "$TESTDIR/killdaemons.py" $DAEMON_PIDS
>
>  #endif
> +
> +
> +Test showconfig help
> +
> +  $ hg showconfig --help
> +  hg showconfig [-u] [NAME]...
> +
> +  aliases: config, debugconfig
> +
> +  show combined config settings from all hgrc files
> +
> +      With no arguments, print names and values of all config items.
> +
> +      With one argument of the form section.name, print just the value of that
> +      config item.
> +
> +      With multiple arguments, print names and values of all config items with
> +      matching section names.
> +
> +      With --edit, start an editor on the user-level config file. With --global,
> +      edit the system-wide config file. With --local, edit the repository-level
> +      config file.
> +
> +      With --debug, the source (filename and line number) is printed for each
> +      config item.
> +
> +      See "hg help config" for more information about config files.
> +
> +      Returns 0 on success.
> +
> +  options:
> +
> +   -u --untrusted show untrusted configuration options
> +   -e --edit      edit user config
> +   -l --local     edit repository config
> +   -g --global    edit global config
> +
> +  use "hg -v help showconfig" to show the global options
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
Augie Fackler - July 9, 2014, 2:23 a.m.
On Tue, Jul 01, 2014 at 10:35:55PM +0530, Prabhu Gnana Sundar wrote:
> # HG changeset patch
> # User Prabhu Gnana Sundar <pprabhugs@gmail.com>
> # Date 1404234214 -19800
> #      Tue Jul 01 22:33:34 2014 +0530
> # Node ID 43e4cd31fae70005b4680ccb53b51f46b962e5b6
> # Parent  99db956b88ab699644c99095fecadbc4c83adbfc
> dispatch: fix so that --help more reliably shows command help (issue4240)

After running tests, I'm dropping this. Please take a look at the
output of 'make test-execute-bit.t' (among many other breakages).

>
> After hg 3.0, "hg showconfig --help" was showing the configuration man page
> instead of the 'hg help -c showconfig' output.
>
> This patch fixes the 'hg showconfig --help' regression issue by removing an
> unwanted assignement of aliases[0] to cmd and shows the correct command
> in the first line of help description.
> Also, added a test case to test 'hg showconfig --help'.
>
> diff -r 99db956b88ab -r 43e4cd31fae7 mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py	Sun Jun 01 16:01:01 2014 -0700
> +++ b/mercurial/cmdutil.py	Tue Jul 01 22:33:34 2014 +0530
> @@ -39,11 +39,13 @@
>          if cmd in aliases:
>              found = cmd
>          elif not strict:
> -            for a in aliases:
> -                if a.startswith(cmd):
> -                    found = a
> +            for alias in aliases:
> +                if alias.startswith(cmd):
> +                    found = alias
>                      break
>          if found is not None:
> +            aliases = [alias for alias in aliases if alias != cmd]
> +            aliases.insert(0, cmd)
>              if aliases[0].startswith("debug") or found.startswith("debug"):
>                  debugchoice[found] = (aliases, table[e])
>              else:
> diff -r 99db956b88ab -r 43e4cd31fae7 mercurial/dispatch.py
> --- a/mercurial/dispatch.py	Sun Jun 01 16:01:01 2014 -0700
> +++ b/mercurial/dispatch.py	Tue Jul 01 22:33:34 2014 +0530
> @@ -494,7 +494,6 @@
>          cmd, args = args[0], args[1:]
>          aliases, entry = cmdutil.findcmd(cmd, commands.table,
>                                           ui.configbool("ui", "strict"))
> -        cmd = aliases[0]
>          args = aliasargs(entry[0], args)
>          defaults = ui.config("defaults", cmd)
>          if defaults:
> diff -r 99db956b88ab -r 43e4cd31fae7 tests/test-help.t
> --- a/tests/test-help.t	Sun Jun 01 16:01:01 2014 -0700
> +++ b/tests/test-help.t	Tue Jul 01 22:33:34 2014 +0530
> @@ -2085,3 +2085,41 @@
>    $ "$TESTDIR/killdaemons.py" $DAEMON_PIDS
>
>  #endif
> +
> +
> +Test showconfig help
> +
> +  $ hg showconfig --help
> +  hg showconfig [-u] [NAME]...
> +
> +  aliases: config, debugconfig
> +
> +  show combined config settings from all hgrc files
> +
> +      With no arguments, print names and values of all config items.
> +
> +      With one argument of the form section.name, print just the value of that
> +      config item.
> +
> +      With multiple arguments, print names and values of all config items with
> +      matching section names.
> +
> +      With --edit, start an editor on the user-level config file. With --global,
> +      edit the system-wide config file. With --local, edit the repository-level
> +      config file.
> +
> +      With --debug, the source (filename and line number) is printed for each
> +      config item.
> +
> +      See "hg help config" for more information about config files.
> +
> +      Returns 0 on success.
> +
> +  options:
> +
> +   -u --untrusted show untrusted configuration options
> +   -e --edit      edit user config
> +   -l --local     edit repository config
> +   -g --global    edit global config
> +
> +  use "hg -v help showconfig" to show the global options
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff -r 99db956b88ab -r 43e4cd31fae7 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Sun Jun 01 16:01:01 2014 -0700
+++ b/mercurial/cmdutil.py	Tue Jul 01 22:33:34 2014 +0530
@@ -39,11 +39,13 @@ 
         if cmd in aliases:
             found = cmd
         elif not strict:
-            for a in aliases:
-                if a.startswith(cmd):
-                    found = a
+            for alias in aliases:
+                if alias.startswith(cmd):
+                    found = alias
                     break
         if found is not None:
+            aliases = [alias for alias in aliases if alias != cmd]
+            aliases.insert(0, cmd)
             if aliases[0].startswith("debug") or found.startswith("debug"):
                 debugchoice[found] = (aliases, table[e])
             else:
diff -r 99db956b88ab -r 43e4cd31fae7 mercurial/dispatch.py
--- a/mercurial/dispatch.py	Sun Jun 01 16:01:01 2014 -0700
+++ b/mercurial/dispatch.py	Tue Jul 01 22:33:34 2014 +0530
@@ -494,7 +494,6 @@ 
         cmd, args = args[0], args[1:]
         aliases, entry = cmdutil.findcmd(cmd, commands.table,
                                          ui.configbool("ui", "strict"))
-        cmd = aliases[0]
         args = aliasargs(entry[0], args)
         defaults = ui.config("defaults", cmd)
         if defaults:
diff -r 99db956b88ab -r 43e4cd31fae7 tests/test-help.t
--- a/tests/test-help.t	Sun Jun 01 16:01:01 2014 -0700
+++ b/tests/test-help.t	Tue Jul 01 22:33:34 2014 +0530
@@ -2085,3 +2085,41 @@ 
   $ "$TESTDIR/killdaemons.py" $DAEMON_PIDS
 
 #endif
+
+
+Test showconfig help
+
+  $ hg showconfig --help
+  hg showconfig [-u] [NAME]...
+  
+  aliases: config, debugconfig
+  
+  show combined config settings from all hgrc files
+  
+      With no arguments, print names and values of all config items.
+  
+      With one argument of the form section.name, print just the value of that
+      config item.
+  
+      With multiple arguments, print names and values of all config items with
+      matching section names.
+  
+      With --edit, start an editor on the user-level config file. With --global,
+      edit the system-wide config file. With --local, edit the repository-level
+      config file.
+  
+      With --debug, the source (filename and line number) is printed for each
+      config item.
+  
+      See "hg help config" for more information about config files.
+  
+      Returns 0 on success.
+  
+  options:
+  
+   -u --untrusted show untrusted configuration options
+   -e --edit      edit user config
+   -l --local     edit repository config
+   -g --global    edit global config
+  
+  use "hg -v help showconfig" to show the global options