context: drop support for looking up context by ambiguous changeid (API)
authorMartin von Zweigbergk <martinvonz@google.com>
Sat, 28 Apr 2018 23:16:41 -0700
changeset 37898 8b86acc7aa64
parent 37897 8327fd79adf8
child 37899 fdd8da79eb85
context: drop support for looking up context by ambiguous changeid (API) This removes support for using the changectx constructor (and thereby repo[x]) for looking up contexts by a stringified int, a namespace key (e.g. a bookmark), or a partial hex nodeid. This means that e.g. repo[<hex nodeid>] will now fail even if a bookmark with the same name exists (which is a good thing IMO). It also means that doing repo[<non-existent node>] no longer ends up loading namespaces (which was a surprising side-effect of creating of failing to create a context object that I recently ran into while debugging something unrelated to this series). Differential Revision: https://phab.mercurial-scm.org/D3449
mercurial/context.py
--- a/mercurial/context.py	Sat Apr 28 23:54:07 2018 -0700
+++ b/mercurial/context.py	Sat Apr 28 23:16:41 2018 -0700
@@ -24,7 +24,6 @@
     short,
     wdirfilenodeids,
     wdirid,
-    wdirrev,
 )
 from . import (
     dagop,
@@ -377,31 +376,6 @@
 
         return r
 
-def changectxdeprecwarn(repo):
-    # changectx's constructor will soon lose support for these forms of
-    # changeids:
-    #  * stringinfied ints
-    #  * bookmarks, tags, branches, and other namespace identifiers
-    #  * hex nodeid prefixes
-    #
-    # Depending on your use case, replace repo[x] by one of these:
-    #  * If you want to support general revsets, use scmutil.revsingle(x)
-    #  * If you know that "x" is a stringified int, use repo[int(x)]
-    #  * If you know that "x" is a bookmark, use repo._bookmarks.changectx(x)
-    #  * If you know that "x" is a tag, use repo[repo.tags()[x]]
-    #  * If you know that "x" is a branch or in some other namespace,
-    #    use the appropriate mechanism for that namespace
-    #  * If you know that "x" is a hex nodeid prefix, use
-    #    repo[scmutil.resolvehexnodeidprefix(repo, x)]
-    #  * If "x" is a string that can be any of the above, but you don't want
-    #    to allow general revsets (perhaps because "x" may come from a remote
-    #    user and the revset may be too costly), use scmutil.revsymbol(repo, x)
-    #  * If "x" can be a mix of the above, you'll have to figure it out
-    #    yourself
-    repo.ui.deprecwarn("changectx.__init__ is getting more limited, see "
-                       "context.changectxdeprecwarn() for details", "4.6",
-                       stacklevel=4)
-
 class changectx(basectx):
     """A changecontext object makes access to data related to a particular
     changeset convenient. It represents a read-only context already present in
@@ -440,24 +414,6 @@
                 except LookupError:
                     pass
 
-            try:
-                r = int(changeid)
-                if '%d' % r != changeid:
-                    raise ValueError
-                l = len(repo.changelog)
-                if r < 0:
-                    r += l
-                if r < 0 or r >= l and r != wdirrev:
-                    raise ValueError
-                self._rev = r
-                self._node = repo.changelog.node(r)
-                changectxdeprecwarn(repo)
-                return
-            except error.FilteredIndexError:
-                raise
-            except (ValueError, OverflowError, IndexError):
-                pass
-
             if len(changeid) == 40:
                 try:
                     self._node = bin(changeid)
@@ -468,21 +424,6 @@
                 except (TypeError, LookupError):
                     pass
 
-            # lookup bookmarks through the name interface
-            try:
-                self._node = repo.names.singlenode(repo, changeid)
-                self._rev = repo.changelog.rev(self._node)
-                changectxdeprecwarn(repo)
-                return
-            except KeyError:
-                pass
-
-            self._node = scmutil.resolvehexnodeidprefix(repo, changeid)
-            if self._node is not None:
-                self._rev = repo.changelog.rev(self._node)
-                changectxdeprecwarn(repo)
-                return
-
             # lookup failed
             # check if it might have come from damaged dirstate
             #