<div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 15, 2019 at 6:11 PM Raphaël Gomès <<a href="mailto:raphael.gomes@octobus.net">raphael.gomes@octobus.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"># HG changeset patch<br>
# User Raphaël Gomès <<a href="mailto:rgomes@octobus.net" target="_blank">rgomes@octobus.net</a>><br>
# Date 1550068454 -3600<br>
#      Wed Feb 13 15:34:14 2019 +0100<br>
# Node ID f850e5c85eeee47df95cd4bcb38b4ade5b5af955<br>
# Parent  91701785c2c56a3ee395038488758ad2e1865265<br>
# EXP-Topic cmd-test<br>
cmdtest: add a new command that checks revset matching<br>
<br>
This command is meant to ease scripting that need to check revsets validity<br>
on a repository. Right now, doing such revset testing requires abuse of `hg log`<br>
output parsing, and is less than ideal.<br>
<br>
It mirrors the `test` shell builtin which is used in almost every shell script<br>
for branching.<br>
<br>
This is a first draft of this command, there is of room for adjustement and evolution,<br>
like fileset matching or other arguments.<br></blockquote><div><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">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.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><a href="https://phab.mercurial-scm.org/rHG8185c8abce87b305920bca9ec26ccbfd11279436">https://phab.mercurial-scm.org/rHG8185c8abce87b305920bca9ec26ccbfd11279436</a></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
diff -r 91701785c2c5 -r f850e5c85eee mercurial/commands.py<br>
--- a/mercurial/commands.py     Mon Feb 11 11:18:37 2019 -0500<br>
+++ b/mercurial/commands.py     Wed Feb 13 15:34:14 2019 +0100<br>
@@ -5942,6 +5942,22 @@<br>
         fm.plain('\n')<br>
     fm.end()<br>
<br>
+@command('test', [], _('REVS'), helpcategory=command.CATEGORY_MISC)<br>
+def cmdtest(ui, repo, *revs):<br>
+    """check if revset match anything<br>
+<br>
+    Helper command that mirrors the shell builtin of the same name.<br>
+    If revset match anything, exits with 0, else exits with 1.<br>
+    """<br>
+    # XXX if `hg test` is used in scripting, using user aliases may<br>
+    # XXX be a security issue.<br>
+    revs = scmutil.revrange(repo, revs)<br>
+<br>
+    if revs:<br>
+        return 0<br>
+    else:<br>
+        return 1<br>
+<br>
 @command('tip',<br>
     [('p', 'patch', None, _('show patch')),<br>
     ('g', 'git', None, _('use git extended diff format')),<br>
diff -r 91701785c2c5 -r f850e5c85eee tests/test-cmdtest.t<br>
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000<br>
+++ b/tests/test-cmdtest.t      Wed Feb 13 15:34:14 2019 +0100<br>
@@ -0,0 +1,31 @@<br>
+================================<br>
+Testing of the `hg test` command<br>
+================================<br>
+<br>
+Initial setup<br>
+=============<br>
+<br>
+  $ hg init cmdtest<br>
+  $ cd cmdtest<br>
+  $ hg debugbuilddag .+10<br>
+<br>
+<br>
+Basic expression<br>
+================<br>
+<br>
+Simple successful<br>
+<br>
+  $ hg test 0<br>
+<br>
+Simple empty revset<br>
+<br>
+  $ hg test "(0 and 1)"<br>
+  [1]<br>
+<br>
+Simple invalid revset<br>
+<br>
+  $ hg test "(0"<br>
+  hg: parse error at 2: unexpected token: end<br>
+  ((0<br>
+     ^ here)<br>
+  [255]<br>
diff -r 91701785c2c5 -r f850e5c85eee tests/test-completion.t<br>
--- a/tests/test-completion.t   Mon Feb 11 11:18:37 2019 -0500<br>
+++ b/tests/test-completion.t   Wed Feb 13 15:34:14 2019 +0100<br>
@@ -49,6 +49,7 @@<br>
   summary<br>
   tag<br>
   tags<br>
+  test<br>
   tip<br>
   unbundle<br>
   update<br>
@@ -340,6 +341,7 @@<br>
   summary: remote<br>
   tag: force, local, rev, remove, edit, message, date, user<br>
   tags: template<br>
+  test: <br>
   tip: patch, git, style, template<br>
   unbundle: update<br>
   update: clean, check, merge, date, rev, tool<br>
diff -r 91701785c2c5 -r f850e5c85eee tests/test-globalopts.t<br>
--- a/tests/test-globalopts.t   Mon Feb 11 11:18:37 2019 -0500<br>
+++ b/tests/test-globalopts.t   Wed Feb 13 15:34:14 2019 +0100<br>
@@ -380,6 +380,10 @@<br>
    help          show help for a given topic or a help overview<br>
    version       output version and copyright information<br>
<br>
+  Miscellaneous commands:<br>
+  <br>
+   test          check if revset match anything<br>
+  <br>
   additional help topics:<br>
<br>
   Mercurial identifiers:<br>
@@ -510,6 +514,10 @@<br>
    help          show help for a given topic or a help overview<br>
    version       output version and copyright information<br>
<br>
+  Miscellaneous commands:<br>
+  <br>
+   test          check if revset match anything<br>
+  <br>
   additional help topics:<br>
<br>
   Mercurial identifiers:<br>
diff -r 91701785c2c5 -r f850e5c85eee tests/test-help-hide.t<br>
--- a/tests/test-help-hide.t    Mon Feb 11 11:18:37 2019 -0500<br>
+++ b/tests/test-help-hide.t    Wed Feb 13 15:34:14 2019 +0100<br>
@@ -84,6 +84,10 @@<br>
    help          show help for a given topic or a help overview<br>
    version       output version and copyright information<br>
<br>
+  Miscellaneous commands:<br>
+  <br>
+   test          check if revset match anything<br>
+  <br>
   additional help topics:<br>
<br>
   Mercurial identifiers:<br>
@@ -218,6 +222,10 @@<br>
    help          show help for a given topic or a help overview<br>
    version       output version and copyright information<br>
<br>
+  Miscellaneous commands:<br>
+  <br>
+   test          check if revset match anything<br>
+  <br>
   additional help topics:<br>
<br>
   Mercurial identifiers:<br>
diff -r 91701785c2c5 -r f850e5c85eee tests/test-help.t<br>
--- a/tests/test-help.t Mon Feb 11 11:18:37 2019 -0500<br>
+++ b/tests/test-help.t Wed Feb 13 15:34:14 2019 +0100<br>
@@ -136,6 +136,10 @@<br>
    help          show help for a given topic or a help overview<br>
    version       output version and copyright information<br>
<br>
+  Miscellaneous commands:<br>
+  <br>
+   test          check if revset match anything<br>
+  <br>
   additional help topics:<br>
<br>
   Mercurial identifiers:<br>
@@ -262,6 +266,10 @@<br>
    help          show help for a given topic or a help overview<br>
    version       output version and copyright information<br>
<br>
+  Miscellaneous commands:<br>
+  <br>
+   test          check if revset match anything<br>
+  <br>
   additional help topics:<br>
<br>
   Mercurial identifiers:<br>
@@ -2698,6 +2706,13 @@<br>
   list repository tags<br>
   </td></tr><br>
   <tr><td><br>
+  <a href="/help/test"><br>
+  test<br>
+  </a><br>
+  </td><td><br>
+  check if revset match anything<br>
+  </td></tr><br>
+  <tr><td><br>
   <a href="/help/unbundle"><br>
   unbundle<br>
   </a><br>
diff -r 91701785c2c5 -r f850e5c85eee tests/test-hgweb-json.t<br>
--- a/tests/test-hgweb-json.t   Mon Feb 11 11:18:37 2019 -0500<br>
+++ b/tests/test-hgweb-json.t   Wed Feb 13 15:34:14 2019 +0100<br>
@@ -2065,6 +2065,10 @@<br>
         "topic": "tags"<br>
       },<br>
       {<br>
+        "summary": "check if revset match anything",<br>
+        "topic": "test"<br>
+      },<br>
+      {<br>
         "summary": "apply one or more bundle files",<br>
         "topic": "unbundle"<br>
       },<br>
_______________________________________________<br>
Mercurial-devel mailing list<br>
<a href="mailto:Mercurial-devel@mercurial-scm.org" target="_blank">Mercurial-devel@mercurial-scm.org</a><br>
<a href="https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel" rel="noreferrer" target="_blank">https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel</a><br>
</blockquote></div></div></div>