Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/context.py @ 37899:fdd8da79eb85
context: only bother looking for broken dirstate for 20-byte changeid
If we fail to look up a changeid in changectx.__init__, we check if it
exactly matches any of the dirstate parents, and if it does, we print
a more specific message ("working directory has unknown parent '...'!"
instead of "unknown revision '...'"). The dirstate parents are always
20 bytes, so there's no need to check for a match when the given
changeid is not 20 bytes. (And now that all the other allowed forms of
changeid have been moved out of the constructor, there's no risk that
a changeid that did match a dirstate parent was actually a valid
bookmark.)
Differential Revision: https://phab.mercurial-scm.org/D3450
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 06 Apr 2018 12:45:08 -0700 |
parents | 8b86acc7aa64 |
children | bb8e93b332a7 |
comparison
equal
deleted
inserted
replaced
37898:8b86acc7aa64 | 37899:fdd8da79eb85 |
---|---|
410 self._rev = repo.changelog.rev(changeid) | 410 self._rev = repo.changelog.rev(changeid) |
411 return | 411 return |
412 except error.FilteredLookupError: | 412 except error.FilteredLookupError: |
413 raise | 413 raise |
414 except LookupError: | 414 except LookupError: |
415 pass | 415 # check if it might have come from damaged dirstate |
416 # | |
417 # XXX we could avoid the unfiltered if we had a recognizable | |
418 # exception for filtered changeset access | |
419 if (repo.local() | |
420 and changeid in repo.unfiltered().dirstate.parents()): | |
421 msg = _("working directory has unknown parent '%s'!") | |
422 raise error.Abort(msg % short(changeid)) | |
416 | 423 |
417 if len(changeid) == 40: | 424 if len(changeid) == 40: |
418 try: | 425 try: |
419 self._node = bin(changeid) | 426 self._node = bin(changeid) |
420 self._rev = repo.changelog.rev(self._node) | 427 self._rev = repo.changelog.rev(self._node) |
423 raise | 430 raise |
424 except (TypeError, LookupError): | 431 except (TypeError, LookupError): |
425 pass | 432 pass |
426 | 433 |
427 # lookup failed | 434 # lookup failed |
428 # check if it might have come from damaged dirstate | |
429 # | |
430 # XXX we could avoid the unfiltered if we had a recognizable | |
431 # exception for filtered changeset access | |
432 if (repo.local() | |
433 and changeid in repo.unfiltered().dirstate.parents()): | |
434 msg = _("working directory has unknown parent '%s'!") | |
435 raise error.Abort(msg % short(changeid)) | |
436 try: | 435 try: |
437 if len(changeid) == 20 and nonascii(changeid): | 436 if len(changeid) == 20 and nonascii(changeid): |
438 changeid = hex(changeid) | 437 changeid = hex(changeid) |
439 except TypeError: | 438 except TypeError: |
440 pass | 439 pass |