comparison mercurial/context.py @ 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 901e749ca0e1
children 1764527af92e
comparison
equal deleted inserted replaced
37531:6639ac97ec3b 37532:8475c9bf096d
375 for l in r: 375 for l in r:
376 l.sort() 376 l.sort()
377 377
378 return r 378 return r
379 379
380 def changectxdeprecwarn(repo):
381 # changectx's constructor will soon lose support for these forms of
382 # changeids:
383 # * stringinfied ints
384 # * bookmarks, tags, branches, and other namespace identifiers
385 # * hex nodeid prefixes
386 #
387 # Depending on your use case, replace repo[x] by one of these:
388 # * If you want to support general revsets, use scmutil.revsingle(x)
389 # * If you know that "x" is a stringified int, use repo[int(x)]
390 # * If you know that "x" is a bookmark, use repo._bookmarks.changectx(x)
391 # * If you know that "x" is a tag, use repo[repo.tags()[x]]
392 # * If you know that "x" is a branch or in some other namespace,
393 # use the appropriate mechanism for that namespace
394 # * If you know that "x" is a hex nodeid prefix, use
395 # repo[scmutil.resolvepartialhexnodeid(repo, x)]
396 # * If "x" is a string that can be any of the above, but you don't want
397 # to allow general revsets (perhaps because "x" may come from a remote
398 # user and the revset may be too costly), use scmutil.revsymbol(repo, x)
399 # * If "x" can be a mix of the above, you'll have to figure it out
400 # yourself
401 repo.ui.deprecwarn("changectx.__init__ is getting more limited, see source "
402 "for details", "4.6")
403
380 class changectx(basectx): 404 class changectx(basectx):
381 """A changecontext object makes access to data related to a particular 405 """A changecontext object makes access to data related to a particular
382 changeset convenient. It represents a read-only context already present in 406 changeset convenient. It represents a read-only context already present in
383 the repo.""" 407 the repo."""
384 def __init__(self, repo, changeid='.'): 408 def __init__(self, repo, changeid='.'):
424 r += l 448 r += l
425 if r < 0 or r >= l and r != wdirrev: 449 if r < 0 or r >= l and r != wdirrev:
426 raise ValueError 450 raise ValueError
427 self._rev = r 451 self._rev = r
428 self._node = repo.changelog.node(r) 452 self._node = repo.changelog.node(r)
453 changectxdeprecwarn(repo)
429 return 454 return
430 except error.FilteredIndexError: 455 except error.FilteredIndexError:
431 raise 456 raise
432 except (ValueError, OverflowError, IndexError): 457 except (ValueError, OverflowError, IndexError):
433 pass 458 pass
444 469
445 # lookup bookmarks through the name interface 470 # lookup bookmarks through the name interface
446 try: 471 try:
447 self._node = repo.names.singlenode(repo, changeid) 472 self._node = repo.names.singlenode(repo, changeid)
448 self._rev = repo.changelog.rev(self._node) 473 self._rev = repo.changelog.rev(self._node)
474 changectxdeprecwarn(repo)
449 return 475 return
450 except KeyError: 476 except KeyError:
451 pass 477 pass
452 478
453 self._node = scmutil.resolvepartialhexnodeid(repo, changeid) 479 self._node = scmutil.resolvepartialhexnodeid(repo, changeid)
454 if self._node is not None: 480 if self._node is not None:
455 self._rev = repo.changelog.rev(self._node) 481 self._rev = repo.changelog.rev(self._node)
482 changectxdeprecwarn(repo)
456 return 483 return
457 484
458 # lookup failed 485 # lookup failed
459 # check if it might have come from damaged dirstate 486 # check if it might have come from damaged dirstate
460 # 487 #