Patchwork [2,of,2,V2] devel-warn: issue a warning for old style revsets

login
register
mail settings
Submitter Pierre-Yves David
Date June 19, 2015, 6:50 p.m.
Message ID <33f50a0583a7254f0859.1434739843@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/9718/
State Accepted
Headers show

Comments

Pierre-Yves David - June 19, 2015, 6:50 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1434737831 25200
#      Fri Jun 19 11:17:11 2015 -0700
# Node ID 33f50a0583a7254f0859ea058ea74843efd5cbdb
# Parent  a51f19e7f84edf50d1d751d8f55466bb10f4ba05
devel-warn: issue a warning for old style revsets

We have move to smartset class more than a year ago, we now have the tool to
aggressively nudge developer into upgrading their extensions.
Matt Mackall - June 19, 2015, 10:07 p.m.
On Fri, 2015-06-19 at 11:50 -0700, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1434737831 25200
> #      Fri Jun 19 11:17:11 2015 -0700
> # Node ID 33f50a0583a7254f0859ea058ea74843efd5cbdb
> # Parent  a51f19e7f84edf50d1d751d8f55466bb10f4ba05
> devel-warn: issue a warning for old style revsets

These are queued for default, thanks.

But this:

> +    if (repo.ui.configbool('devel', 'all-warnings')
> +            or repo.ui.configbool('devel', 'old-revset')):

..wants to be encapsulated.

Proposal:

# unconditional
ui.develwarn('fast-check', 'stuff is broken')

# conditional with a slowpath
if ui.develwarn('slow-check'):
    if someslowfunc():
        ui.develwarn('slow-check', 'slow thing is broken')

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -319,10 +319,17 @@  def getset(repo, subset, x):
     if not x:
         raise error.ParseError(_("missing argument"))
     s = methods[x[0]](repo, subset, *x[1:])
     if util.safehasattr(s, 'isascending'):
         return s
+    if (repo.ui.configbool('devel', 'all-warnings')
+            or repo.ui.configbool('devel', 'old-revset')):
+        # else case should not happen, because all non-func are internal,
+        # ignoring for now.
+        if x[0] == 'func' and x[1][0] == 'symbol' and x[1][1] in symbols:
+            repo.ui.develwarn('revset "%s" use list instead of smartset, '
+                              '(upgrade your code)' % x[1][1])
     return baseset(s)
 
 def _getrevsource(repo, r):
     extra = repo[r].extra()
     for label in ('source', 'transplant_source', 'rebase_source'):
diff --git a/tests/test-devel-warnings.t b/tests/test-devel-warnings.t
--- a/tests/test-devel-warnings.t
+++ b/tests/test-devel-warnings.t
@@ -1,11 +1,11 @@ 
 
   $ cat << EOF > buggylocking.py
   > """A small extension that acquire locks in the wrong order
   > """
   > 
-  > from mercurial import cmdutil, repair
+  > from mercurial import cmdutil, repair, revset
   > 
   > cmdtable = {}
   > command = cmdutil.command(cmdtable)
   > 
   > @command('buggylocking', [], '')
@@ -45,10 +45,15 @@ 
   >     tr = repo.transaction('foobar')
   >     try:
   >         repair.strip(repo.ui, repo, [repo['.'].node()])
   >     finally:
   >         lo.release()
+  > 
+  > def oldstylerevset(repo, subset, x):
+  >     return list(subset)
+  > 
+  > revset.symbols['oldstyle'] = oldstylerevset
   > EOF
 
   $ cat << EOF >> $HGRCPATH
   > [extensions]
   > buggylocking=$TESTTMP/buggylocking.py
@@ -104,6 +109,10 @@ 
   saved backup bundle to $TESTTMP/lock-checker/.hg/strip-backup/cb9a9f314b8b-cc5ccb0b-backup.hg (glob)
   abort: programming error: cannot strip from inside a transaction
   (contact your extension maintainer)
   [255]
 
+  $ hg log -r "oldstyle()" -T '{rev}\n'
+  devel-warn: revset "oldstyle" use list instead of smartset, (upgrade your code) at: */mercurial/revset.py:* (mfunc) (glob)
+  0
+
   $ cd ..