[PATCH] help: supports 'hg help config.alias' (issue2804)

yun lee yun.lee.bj at gmail.com
Tue May 24 09:58:19 CDT 2011


I have realised it' better to send series of patches on this topic in
one time instead of one by one. I will do it later. So please ignore
this patch please.

2011/5/24 Yun Lee <yun.lee.bj at gmail.com>:
> # HG changeset patch
> # User Yun Lee <yun.lee.bj at gmail.com>
> # Date 1306248390 -28800
> # Branch stable
> # Node ID 39fc1a69bcd2f80b24c06943360c39eafacd4a52
> # Parent  4ee293cb1e61fe24ed22c75dc1086034053926a4
> help: supports 'hg help config.alias' (issue2804)
>
> diff -r 4ee293cb1e61 -r 39fc1a69bcd2 doc/hgrc.5.txt
> --- a/doc/hgrc.5.txt    Tue May 24 22:07:19 2011 +0800
> +++ b/doc/hgrc.5.txt    Tue May 24 22:46:30 2011 +0800
> @@ -179,47 +179,7 @@
>
>  ``alias``
>  """""""""
> -Defines command aliases.
> -Aliases allow you to define your own commands in terms of other
> -commands (or aliases), optionally including arguments.
> -
> -Alias definitions consist of lines of the form::
> -
> -    <alias> = <command> [<argument]...
> -
> -For example, this definition::
> -
> -    latest = log --limit 5
> -
> -creates a new command ``latest`` that shows only the five most recent
> -changesets. You can define subsequent aliases using earlier ones::
> -
> -    stable5 = latest -b stable
> -
> -.. note:: It is possible to create aliases with the same names as
> -   existing commands, which will then override the original
> -   definitions. This is almost always a bad idea!
> -
> -An alias can start with an exclamation point (``!``) to make it a
> -shell alias. A shell alias is executed with the shell and will let you
> -run arbitrary commands. As an example, ::
> -
> -   echo = !echo
> -
> -will let you do ``hg echo foo`` to have ``foo`` printed in your
> -terminal. A better example might be::
> -
> -   purge = !$HG status --no-status --unknown -0 | xargs -0 rm
> -
> -which will make ``hg purge`` delete all unknown files in the
> -repository in the same manner as the purge extension.
> -
> -Shell aliases are executed in an environment where ``$HG`` expand to
> -the path of the Mercurial that was used to execute the alias. This is
> -useful when you want to call further Mercurial commands in a shell
> -alias, as was done above for the purge alias. In addition,
> -``$HG_ARGS`` expand to the arguments given to Mercurial. In the ``hg
> -echo foo`` call above, ``$HG_ARGS`` would expand to ``echo foo``.
> +.. include:: ../mercurial/help/config/alias.txt
>
>  ``auth``
>  """"""""
> diff -r 4ee293cb1e61 -r 39fc1a69bcd2 mercurial/commands.py
> --- a/mercurial/commands.py     Tue May 24 22:07:19 2011 +0800
> +++ b/mercurial/commands.py     Tue May 24 22:46:30 2011 +0800
> @@ -2083,13 +2083,25 @@
>             addglobalopts(True)
>
>     def helptopic(name):
> +        topicname, subtopicname = (name, None)
> +
> +        if '.' in name:
> +            topicname, subtopicname = name.split('.')
> +
>         for names, header, doc, subtopics in help.helptable:
> -            if name in names:
> +            if topicname in names:
>                 break
>         else:
>             raise error.UnknownCommand(name)
>
> -        # description
> +
> +        if subtopicname:
> +            for name, header, doc in subtopics:
> +                if subtopicname ==name:
> +                    break
> +            else:
> +                raise error.UnknownCommand(name)
> +
>         if not doc:
>             doc = _("(no help text available)")
>         if hasattr(doc, '__call__'):
> @@ -2098,7 +2110,7 @@
>         ui.write("%s\n\n" % header)
>         ui.write("%s\n" % minirst.format(doc, textwidth, indent=4))
>
> -        if subtopics:
> +        if not subtopicname and subtopics:
>             ui.write("\n\nsubtopics:\n\n")
>
>             for subtopic in subtopics:
> diff -r 4ee293cb1e61 -r 39fc1a69bcd2 mercurial/help.py
> --- a/mercurial/help.py Tue May 24 22:07:19 2011 +0800
> +++ b/mercurial/help.py Tue May 24 22:46:30 2011 +0800
> @@ -88,29 +88,29 @@
>
>  helptable = [
>     (["config", "hgrc"], _("Configuration Files"), loaddoc('config'),
> -      [('alias', 'Defines command aliases'),
> -       ('auth', 'Authentication credentials for HTTP authentication'),
> -       ('encode', 'Filters for transforming files on checkin'),
> -       ('decode', 'Filters for transforming files on checkout'),
> -       ('defaults', 'Use the [defaults] section to define command defaults'),
> -       ('diff', 'Settings used when displaying diffs'),
> -       ('email', 'Settings for extensions that send email messages'),
> -       ('extensions', 'Extension mechanism for adding new features'),
> -       ('hostfingerprints', 'Fingerprints of the certificates of known HTTPS servers'),
> -       ('format', 'Configuration for repository format'),
> -       ('merge-patterns', 'Merge tools to associate with particular file patterns'),
> -       ('merge-tools', 'Configures external merge tools to use for file-level merges'),
> -       ('hooks', 'Commands or Python functions'),
> -       ('http_proxy', 'Configuration for access web-based Mercurial repositories through a HTTP proxy'),
> -       ('smtp', 'Configuration for extensions that need to send email messages'),
> -       ('patch', 'Settings used when applying patches'),
> -       ('paths', 'Assigns symbolic names to repositories'),
> -       ('profiling', 'Specifies profiling format and file output'),
> -       ('server', 'Controls generic server settings'),
> -       ('subpaths', 'Defines subrepositories source locations rewriting rules of the form'),
> -       ('trusted', 'specifies what users and groups are trusted'),
> -       ('ui', 'User interface controls'),
> -       ('web', 'Web interface configuration'),
> +      [('alias', 'Defines command aliases', loaddoc('config/alias')),
> +       ('auth', 'Authentication credentials for HTTP authentication', None),
> +       ('encode', 'Filters for transforming files on checkin', None),
> +       ('decode', 'Filters for transforming files on checkout', None),
> +       ('defaults', 'Use the [defaults] section to define command defaults', None),
> +       ('diff', 'Settings used when displaying diffs', None),
> +       ('email', 'Settings for extensions that send email messages', None),
> +       ('extensions', 'Extension mechanism for adding new features', None),
> +       ('hostfingerprints', 'Fingerprints of the certificates of known HTTPS servers', None),
> +       ('format', 'Configuration for repository format', None),
> +       ('merge-patterns', 'Merge tools to associate with particular file patterns', None),
> +       ('merge-tools', 'Configures external merge tools to use for file-level merges', None),
> +       ('hooks', 'Commands or Python functions', None),
> +       ('http_proxy', 'Configuration for access web-based Mercurial repositories through a HTTP proxy', None),
> +       ('smtp', 'Configuration for extensions that need to send email messages', None),
> +       ('patch', 'Settings used when applying patches', None),
> +       ('paths', 'Assigns symbolic names to repositories', None),
> +       ('profiling', 'Specifies profiling format and file output', None),
> +       ('server', 'Controls generic server settings', None),
> +       ('subpaths', 'Defines subrepositories source locations rewriting rules of the form', None),
> +       ('trusted', 'specifies what users and groups are trusted', None),
> +       ('ui', 'User interface controls', None),
> +       ('web', 'Web interface configuration', None),
>        ]),
>     (["dates"], _("Date Formats"), loaddoc('dates'), []),
>     (["patterns"], _("File Name Patterns"), loaddoc('patterns'), []),
> diff -r 4ee293cb1e61 -r 39fc1a69bcd2 setup.py
> --- a/setup.py  Tue May 24 22:07:19 2011 +0800
> +++ b/setup.py  Tue May 24 22:46:30 2011 +0800
> @@ -350,7 +350,7 @@
>         packages.extend(['hgext.inotify', 'hgext.inotify.linux'])
>
>  packagedata = {'mercurial': ['locale/*/LC_MESSAGES/hg.mo',
> -                             'help/*.txt']}
> +                             'help/*.txt', 'help/config/*.txt']}
>
>  def ordinarypath(p):
>     return p and p[0] != '.' and p[-1] != '~'
> diff -r 4ee293cb1e61 -r 39fc1a69bcd2 tests/test-help.t
> --- a/tests/test-help.t Tue May 24 22:07:19 2011 +0800
> +++ b/tests/test-help.t Tue May 24 22:46:30 2011 +0800
> @@ -882,3 +882,55 @@
>     trusted           specifies what users and groups are trusted
>     ui                User interface controls
>     web               Web interface configuration
> +
> +Test 'hg help config.alias'
> +  $ hg help config.alias
> +  Defines command aliases
> +
> +      Defines command aliases. Aliases allow you to define your own commands in
> +      terms of other commands (or aliases), optionally including arguments.
> +
> +      Alias definitions consist of lines of the form:
> +
> +        <alias> = <command> [<argument]...
> +
> +      For example, this definition:
> +
> +        latest = log --limit 5
> +
> +      creates a new command "latest" that shows only the five most recent
> +      changesets. You can define subsequent aliases using earlier ones:
> +
> +        stable5 = latest -b stable
> +
> +      Note:
> +         It is possible to create aliases with the same names as existing
> +         commands, which will then override the original definitions. This is
> +         almost always a bad idea!
> +
> +      An alias can start with an exclamation point ("!") to make it a shell
> +      alias. A shell alias is executed with the shell and will let you run
> +      arbitrary commands. As an example,
> +
> +        echo = !echo
> +
> +      will let you do "hg echo foo" to have "foo" printed in your terminal. A
> +      better example might be:
> +
> +        purge = !$HG status --no-status --unknown -0 | xargs -0 rm
> +
> +      which will make "hg purge" delete all unknown files in the repository in
> +      the same manner as the purge extension.
> +
> +      Shell aliases are executed in an environment where "$HG" expand to the
> +      path of the Mercurial that was used to execute the alias. This is useful
> +      when you want to call further Mercurial commands in a shell alias, as was
> +      done above for the purge alias. In addition, "$HG_ARGS" expand to the
> +      arguments given to Mercurial. In the "hg echo foo" call above, "$HG_ARGS"
> +      would expand to "echo foo".
> +
> +Test 'hg help config.auth'
> +  $ hg help config.auth
> +  Authentication credentials for HTTP authentication
> +
> +      (no help text available)
>



-- 
Yun Lee


More information about the Mercurial-devel mailing list