[PATCH RFC] cmdtest: add a new command that checks revset matching

Pulkit Goyal 7895pulkit at gmail.com
Tue Feb 19 07:52:03 EST 2019


On Fri, Feb 15, 2019 at 6:11 PM Raphaël Gomès <raphael.gomes at octobus.net>
wrote:

> # HG changeset patch
> # User Raphaël Gomès <rgomes at octobus.net>
> # Date 1550068454 -3600
> #      Wed Feb 13 15:34:14 2019 +0100
> # Node ID f850e5c85eeee47df95cd4bcb38b4ade5b5af955
> # Parent  91701785c2c56a3ee395038488758ad2e1865265
> # EXP-Topic cmd-test
> cmdtest: add a new command that checks revset matching
>
> This command is meant to ease scripting that need to check revsets validity
> on a repository. Right now, doing such revset testing requires abuse of
> `hg log`
> output parsing, and is less than ideal.
>
> It mirrors the `test` shell builtin which is used in almost every shell
> script
> for branching.
>
> This is a first draft of this command, there is of room for adjustement
> and evolution,
> like fileset matching or other arguments.
>

You can use the `expectsize()` revset which is recently implemented and
pass the size as 0. So if a revset is empty, the operation will succeed and
you will get 0 as return value. If there are revs in the revset, it will
abort.

https://phab.mercurial-scm.org/rHG8185c8abce87b305920bca9ec26ccbfd11279436

>
> diff -r 91701785c2c5 -r f850e5c85eee mercurial/commands.py
> --- a/mercurial/commands.py     Mon Feb 11 11:18:37 2019 -0500
> +++ b/mercurial/commands.py     Wed Feb 13 15:34:14 2019 +0100
> @@ -5942,6 +5942,22 @@
>          fm.plain('\n')
>      fm.end()
>
> + at command('test', [], _('REVS'), helpcategory=command.CATEGORY_MISC)
> +def cmdtest(ui, repo, *revs):
> +    """check if revset match anything
> +
> +    Helper command that mirrors the shell builtin of the same name.
> +    If revset match anything, exits with 0, else exits with 1.
> +    """
> +    # XXX if `hg test` is used in scripting, using user aliases may
> +    # XXX be a security issue.
> +    revs = scmutil.revrange(repo, revs)
> +
> +    if revs:
> +        return 0
> +    else:
> +        return 1
> +
>  @command('tip',
>      [('p', 'patch', None, _('show patch')),
>      ('g', 'git', None, _('use git extended diff format')),
> diff -r 91701785c2c5 -r f850e5c85eee tests/test-cmdtest.t
> --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
> +++ b/tests/test-cmdtest.t      Wed Feb 13 15:34:14 2019 +0100
> @@ -0,0 +1,31 @@
> +================================
> +Testing of the `hg test` command
> +================================
> +
> +Initial setup
> +=============
> +
> +  $ hg init cmdtest
> +  $ cd cmdtest
> +  $ hg debugbuilddag .+10
> +
> +
> +Basic expression
> +================
> +
> +Simple successful
> +
> +  $ hg test 0
> +
> +Simple empty revset
> +
> +  $ hg test "(0 and 1)"
> +  [1]
> +
> +Simple invalid revset
> +
> +  $ hg test "(0"
> +  hg: parse error at 2: unexpected token: end
> +  ((0
> +     ^ here)
> +  [255]
> diff -r 91701785c2c5 -r f850e5c85eee tests/test-completion.t
> --- a/tests/test-completion.t   Mon Feb 11 11:18:37 2019 -0500
> +++ b/tests/test-completion.t   Wed Feb 13 15:34:14 2019 +0100
> @@ -49,6 +49,7 @@
>    summary
>    tag
>    tags
> +  test
>    tip
>    unbundle
>    update
> @@ -340,6 +341,7 @@
>    summary: remote
>    tag: force, local, rev, remove, edit, message, date, user
>    tags: template
> +  test:
>    tip: patch, git, style, template
>    unbundle: update
>    update: clean, check, merge, date, rev, tool
> diff -r 91701785c2c5 -r f850e5c85eee tests/test-globalopts.t
> --- a/tests/test-globalopts.t   Mon Feb 11 11:18:37 2019 -0500
> +++ b/tests/test-globalopts.t   Wed Feb 13 15:34:14 2019 +0100
> @@ -380,6 +380,10 @@
>     help          show help for a given topic or a help overview
>     version       output version and copyright information
>
> +  Miscellaneous commands:
> +
> +   test          check if revset match anything
> +
>    additional help topics:
>
>    Mercurial identifiers:
> @@ -510,6 +514,10 @@
>     help          show help for a given topic or a help overview
>     version       output version and copyright information
>
> +  Miscellaneous commands:
> +
> +   test          check if revset match anything
> +
>    additional help topics:
>
>    Mercurial identifiers:
> diff -r 91701785c2c5 -r f850e5c85eee tests/test-help-hide.t
> --- a/tests/test-help-hide.t    Mon Feb 11 11:18:37 2019 -0500
> +++ b/tests/test-help-hide.t    Wed Feb 13 15:34:14 2019 +0100
> @@ -84,6 +84,10 @@
>     help          show help for a given topic or a help overview
>     version       output version and copyright information
>
> +  Miscellaneous commands:
> +
> +   test          check if revset match anything
> +
>    additional help topics:
>
>    Mercurial identifiers:
> @@ -218,6 +222,10 @@
>     help          show help for a given topic or a help overview
>     version       output version and copyright information
>
> +  Miscellaneous commands:
> +
> +   test          check if revset match anything
> +
>    additional help topics:
>
>    Mercurial identifiers:
> diff -r 91701785c2c5 -r f850e5c85eee tests/test-help.t
> --- a/tests/test-help.t Mon Feb 11 11:18:37 2019 -0500
> +++ b/tests/test-help.t Wed Feb 13 15:34:14 2019 +0100
> @@ -136,6 +136,10 @@
>     help          show help for a given topic or a help overview
>     version       output version and copyright information
>
> +  Miscellaneous commands:
> +
> +   test          check if revset match anything
> +
>    additional help topics:
>
>    Mercurial identifiers:
> @@ -262,6 +266,10 @@
>     help          show help for a given topic or a help overview
>     version       output version and copyright information
>
> +  Miscellaneous commands:
> +
> +   test          check if revset match anything
> +
>    additional help topics:
>
>    Mercurial identifiers:
> @@ -2698,6 +2706,13 @@
>    list repository tags
>    </td></tr>
>    <tr><td>
> +  <a href="/help/test">
> +  test
> +  </a>
> +  </td><td>
> +  check if revset match anything
> +  </td></tr>
> +  <tr><td>
>    <a href="/help/unbundle">
>    unbundle
>    </a>
> diff -r 91701785c2c5 -r f850e5c85eee tests/test-hgweb-json.t
> --- a/tests/test-hgweb-json.t   Mon Feb 11 11:18:37 2019 -0500
> +++ b/tests/test-hgweb-json.t   Wed Feb 13 15:34:14 2019 +0100
> @@ -2065,6 +2065,10 @@
>          "topic": "tags"
>        },
>        {
> +        "summary": "check if revset match anything",
> +        "topic": "test"
> +      },
> +      {
>          "summary": "apply one or more bundle files",
>          "topic": "unbundle"
>        },
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20190219/b625385a/attachment.html>


More information about the Mercurial-devel mailing list