changeset 37532:8475c9bf096d

context: add deprecation warnings for deprecated types of changeids It's close to code freeze, and dropping support for repo['123'] and repo ['my-bookmark'] and repo['deadbeef'] is pretty dispruptive, so this just adds deprecation warnings so extensions can easily find the places they need to fix. Differential Revision: https://phab.mercurial-scm.org/D3197
author Martin von Zweigbergk <martinvonz@google.com>
date Sun, 08 Apr 2018 09:45:45 -0700
parents 6639ac97ec3b
children df4985497986
files mercurial/context.py
diffstat 1 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/context.py	Sun Apr 08 09:28:08 2018 -0700
+++ b/mercurial/context.py	Sun Apr 08 09:45:45 2018 -0700
@@ -377,6 +377,30 @@
 
         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.resolvepartialhexnodeid(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 source "
+                       "for details", "4.6")
+
 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
@@ -426,6 +450,7 @@
                     raise ValueError
                 self._rev = r
                 self._node = repo.changelog.node(r)
+                changectxdeprecwarn(repo)
                 return
             except error.FilteredIndexError:
                 raise
@@ -446,6 +471,7 @@
             try:
                 self._node = repo.names.singlenode(repo, changeid)
                 self._rev = repo.changelog.rev(self._node)
+                changectxdeprecwarn(repo)
                 return
             except KeyError:
                 pass
@@ -453,6 +479,7 @@
             self._node = scmutil.resolvepartialhexnodeid(repo, changeid)
             if self._node is not None:
                 self._rev = repo.changelog.rev(self._node)
+                changectxdeprecwarn(repo)
                 return
 
             # lookup failed