comparison mercurial/context.py @ 37857:9231148ea599

context: convert to hex for error message only for 20-byte changeid Now that 20-byte strings unambiguously mean binary (or a bug), we can specialize the conversion to hex for that case. Differential Revision: https://phab.mercurial-scm.org/D3452
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 06 Apr 2018 12:55:32 -0700
parents bb8e93b332a7
children c0f8fa74d8c2
comparison
equal deleted inserted replaced
37856:bb8e93b332a7 37857:9231148ea599
8 from __future__ import absolute_import 8 from __future__ import absolute_import
9 9
10 import errno 10 import errno
11 import filecmp 11 import filecmp
12 import os 12 import os
13 import re
14 import stat 13 import stat
15 14
16 from .i18n import _ 15 from .i18n import _
17 from .node import ( 16 from .node import (
18 addednodeid, 17 addednodeid,
48 dateutil, 47 dateutil,
49 stringutil, 48 stringutil,
50 ) 49 )
51 50
52 propertycache = util.propertycache 51 propertycache = util.propertycache
53
54 nonascii = re.compile(br'[^\x21-\x7f]').search
55 52
56 class basectx(object): 53 class basectx(object):
57 """A basectx object represents the common logic for its children: 54 """A basectx object represents the common logic for its children:
58 changectx: read-only context that is already present in the repo, 55 changectx: read-only context that is already present in the repo,
59 workingctx: a context that represents the working directory and can 56 workingctx: a context that represents the working directory and can
418 # exception for filtered changeset access 415 # exception for filtered changeset access
419 if (repo.local() 416 if (repo.local()
420 and changeid in repo.unfiltered().dirstate.parents()): 417 and changeid in repo.unfiltered().dirstate.parents()):
421 msg = _("working directory has unknown parent '%s'!") 418 msg = _("working directory has unknown parent '%s'!")
422 raise error.Abort(msg % short(changeid)) 419 raise error.Abort(msg % short(changeid))
420 changeid = hex(changeid) # for the error message
423 421
424 elif len(changeid) == 40: 422 elif len(changeid) == 40:
425 try: 423 try:
426 self._node = bin(changeid) 424 self._node = bin(changeid)
427 self._rev = repo.changelog.rev(self._node) 425 self._rev = repo.changelog.rev(self._node)
430 raise 428 raise
431 except (TypeError, LookupError): 429 except (TypeError, LookupError):
432 pass 430 pass
433 431
434 # lookup failed 432 # lookup failed
435 try:
436 if len(changeid) == 20 and nonascii(changeid):
437 changeid = hex(changeid)
438 except TypeError:
439 pass
440 except (error.FilteredIndexError, error.FilteredLookupError): 433 except (error.FilteredIndexError, error.FilteredLookupError):
441 raise error.FilteredRepoLookupError(_("filtered revision '%s'") 434 raise error.FilteredRepoLookupError(_("filtered revision '%s'")
442 % changeid) 435 % changeid)
443 except error.FilteredRepoLookupError: 436 except error.FilteredRepoLookupError:
444 raise 437 raise