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

2019-02-19 Thread Yuya Nishihara
On Tue, 19 Feb 2019 19:17:03 +0100, Boris FELD wrote:
> On 19/02/2019 13:52, Pulkit Goyal wrote:
> >
> >
> > On Fri, Feb 15, 2019 at 6:11 PM Raphaël Gomès
> > mailto:raphael.go...@octobus.net>> wrote:
> >
> > # HG changeset patch
> > # User Raphaël Gomès mailto:rgo...@octobus.net>>
> > # Date 1550068454 -3600
> > #      Wed Feb 13 15:34:14 2019 +0100
> > # Node ID f850e5c8547df95cd4bcb38b4ade5b5af955
> > # 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.
> The expectsize revset is less flexible, and provide an ambiguous return
> code when it does not match (same return as an invalid revset). The
> revset seems useful in itself, but having a clear and extensible command
> will make scripting simpler, clearer and less error-prone.

Maybe add some flag to debugrevspec command to disambiguate RepoLookupError
from the other errors?

I don't know what kind of other features the script would need, but
inspecting revset/filset syntax would belong to debugrevspec/fileset commands.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


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

2019-02-19 Thread Boris FELD
On 19/02/2019 13:52, Pulkit Goyal wrote:
>
>
> On Fri, Feb 15, 2019 at 6:11 PM Raphaël Gomès
> mailto:raphael.go...@octobus.net>> wrote:
>
> # HG changeset patch
> # User Raphaël Gomès mailto:rgo...@octobus.net>>
> # Date 1550068454 -3600
> #      Wed Feb 13 15:34:14 2019 +0100
> # Node ID f850e5c8547df95cd4bcb38b4ade5b5af955
> # 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.
The expectsize revset is less flexible, and provide an ambiguous return
code when it does not match (same return as an invalid revset). The
revset seems useful in itself, but having a clear and extensible command
will make scripting simpler, clearer and less error-prone.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


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

2019-02-19 Thread Pulkit Goyal
On Fri, Feb 15, 2019 at 6:11 PM Raphaël Gomès 
wrote:

> # HG changeset patch
> # User Raphaël Gomès 
> # Date 1550068454 -3600
> #  Wed Feb 13 15:34:14 2019 +0100
> # Node ID f850e5c8547df95cd4bcb38b4ade5b5af955
> # 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()
>
> +@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 +
> +++ 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.tMon Feb 11 11:18:37 2019 -0500
> +++ b/tests/test-help-hide.tWed 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 

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

2019-02-15 Thread Raphaël Gomès
# HG changeset patch
# User Raphaël Gomès 
# Date 1550068454 -3600
#  Wed Feb 13 15:34:14 2019 +0100
# Node ID f850e5c8547df95cd4bcb38b4ade5b5af955
# 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.

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()
 
+@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 +
+++ 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.tMon Feb 11 11:18:37 2019 -0500
+++ b/tests/test-help-hide.tWed 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