Mercurial > hg
comparison mercurial/context.py @ 37385:ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
When changectx's constructor runs into various Filtered*Error, it
creates an exception with a hint about using --hidden. This only makes
sense when the revision was provided by the user (if we get e.g. a
FilteredLookupError from repo[p1], then it's instead a programming
error). Thus, I'm moving the handling into revsymbol(). Also changed
"unfilteredrepo[changeid]" to "revsymbol(unfilteredrepo, changeid)" as
part of the move.
Differential Revision: https://phab.mercurial-scm.org/D3143
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 05 Apr 2018 00:04:09 -0700 |
parents | a6014392837e |
children | 167b22a906f3 |
comparison
equal
deleted
inserted
replaced
37384:5c9d0af7b02e | 37385:ecd3f6909184 |
---|---|
31 encoding, | 31 encoding, |
32 error, | 32 error, |
33 fileset, | 33 fileset, |
34 match as matchmod, | 34 match as matchmod, |
35 obsolete as obsmod, | 35 obsolete as obsmod, |
36 obsutil, | |
37 patch, | 36 patch, |
38 pathutil, | 37 pathutil, |
39 phases, | 38 phases, |
40 pycompat, | 39 pycompat, |
41 repoview, | 40 repoview, |
376 for l in r: | 375 for l in r: |
377 l.sort() | 376 l.sort() |
378 | 377 |
379 return r | 378 return r |
380 | 379 |
381 def _filterederror(repo, changeid): | |
382 """build an exception to be raised about a filtered changeid | |
383 | |
384 This is extracted in a function to help extensions (eg: evolve) to | |
385 experiment with various message variants.""" | |
386 if repo.filtername.startswith('visible'): | |
387 | |
388 # Check if the changeset is obsolete | |
389 unfilteredrepo = repo.unfiltered() | |
390 ctx = unfilteredrepo[changeid] | |
391 | |
392 # If the changeset is obsolete, enrich the message with the reason | |
393 # that made this changeset not visible | |
394 if ctx.obsolete(): | |
395 msg = obsutil._getfilteredreason(repo, changeid, ctx) | |
396 else: | |
397 msg = _("hidden revision '%s'") % changeid | |
398 | |
399 hint = _('use --hidden to access hidden revisions') | |
400 | |
401 return error.FilteredRepoLookupError(msg, hint=hint) | |
402 msg = _("filtered revision '%s' (not in '%s' subset)") | |
403 msg %= (changeid, repo.filtername) | |
404 return error.FilteredRepoLookupError(msg) | |
405 | |
406 class changectx(basectx): | 380 class changectx(basectx): |
407 """A changecontext object makes access to data related to a particular | 381 """A changecontext object makes access to data related to a particular |
408 changeset convenient. It represents a read-only context already present in | 382 changeset convenient. It represents a read-only context already present in |
409 the repo.""" | 383 the repo.""" |
410 def __init__(self, repo, changeid='.'): | 384 def __init__(self, repo, changeid='.'): |
499 changeid = hex(changeid) | 473 changeid = hex(changeid) |
500 except TypeError: | 474 except TypeError: |
501 pass | 475 pass |
502 except (error.FilteredIndexError, error.FilteredLookupError, | 476 except (error.FilteredIndexError, error.FilteredLookupError, |
503 error.FilteredRepoLookupError): | 477 error.FilteredRepoLookupError): |
504 raise _filterederror(repo, changeid) | 478 raise |
505 except IndexError: | 479 except IndexError: |
506 pass | 480 pass |
507 raise error.RepoLookupError( | 481 raise error.RepoLookupError( |
508 _("unknown revision '%s'") % changeid) | 482 _("unknown revision '%s'") % changeid) |
509 | 483 |