##// END OF EJS Templates
context: write dirstate out explicitly after marking files as clean...
context: write dirstate out explicitly after marking files as clean To detect change of a file without redundant comparison of file content, dirstate recognizes a file as certainly clean, if: (1) it is already known as "normal", (2) dirstate entry for it has valid (= not "-1") timestamp, and (3) mode, size and timestamp of it on the filesystem are as same as ones expected in dirstate This works as expected in many cases, but doesn't in the corner case that changing a file keeps mode, size and timestamp of it on the filesystem. The timetable below shows steps in one of typical such situations: ---- ----------------------------------- ---------------- timestamp of "f" ---------------- dirstate file- time action mem file system ---- ----------------------------------- ---- ----- ----- N -1 *** - make file "f" clean N - execute 'hg foobar' - instantiate 'dirstate' -1 -1 - 'dirstate.normal("f")' N -1 (e.g. via dirty check) - change "f", but keep size N N+1 - release wlock - 'dirstate.write()' N N - 'hg status' shows "f" as "clean" N N N ---- ----------------------------------- ---- ----- ----- The most important point is that 'dirstate.write()' is executed at N+1 or later. This causes writing dirstate timestamp N of "f" out successfully. If it is executed at N, 'parsers.pack_dirstate()' replaces timestamp N with "-1" before actual writing dirstate out. Occasional test failure for unexpected file status is typical example of this corner case. Batch execution with small working directory is finished in no time, and rarely satisfies condition (2) above. This issue can occur in cases below; - 'hg revert --rev REV' for revisions other than the parent - failure of 'merge.update()' before 'merge.recordupdates()' The root cause of this issue is that files are changed without flushing in-memory dirstate changes via 'repo.commit()' (even though omitting 'dirstate.normallookup()' on changed files also causes this issue). To detect changes of files correctly, this patch writes in-memory dirstate changes out explicitly after marking files as clean in 'workingctx._checklookup()', which is invoked via 'repo.status()'. After this change, timetable is changed as below: ---- ----------------------------------- ---------------- timestamp of "f" ---------------- dirstate file- time action mem file system ---- ----------------------------------- ---- ----- ----- N -1 *** - make file "f" clean N - execute 'hg foobar' - instantiate 'dirstate' -1 -1 - 'dirstate.normal("f")' N -1 (e.g. via dirty check) ----------------------------------- ---- ----- ----- - 'dirsttate.write()' -1 -1 ----------------------------------- ---- ----- ----- - change "f", but keep size N N+1 - release wlock - 'dirstate.write()' -1 -1 - 'hg status' -1 -1 N ---- ----------------------------------- ---- ----- ----- To reproduce this issue in tests certainly, this patch emulates some timing critical actions as below: - timestamp of "f" in '.hg/dirstate' is -1 at the beginning 'hg debugrebuildstate' before command invocation ensures it. - make file "f" clean at N - change "f" at N 'touch -t 200001010000' before and after command invocation changes mtime of "f" to "2000-01-01 00:00" (= N). - invoke 'dirstate.write()' via 'repo.status()' at N 'fakedirstatewritetime.py' forces 'pack_dirstate()' to use "2000-01-01 00:00" as "now", only if 'pack_dirstate()' is invoked via 'workingctx._checklookup()'. - invoke 'dirstate.write()' via releasing wlock at N+1 (or "not at N") 'pack_dirstate()' via releasing wlock uses actual timestamp at runtime as "now", and it should be different from the "2000-01-01 00:00" of "f". BTW, this patch also changes 'test-largefiles-misc.t', because adding 'dirstate.write()' makes recent dirstate changes visible to external process.

File last commit:

r25484:a5192774 default
r25753:fe03f522 default
Show More
error.py
186 lines | 5.5 KiB | text/x-python | PythonLexer
# error.py - Mercurial exceptions
#
# Copyright 2005-2008 Matt Mackall <mpm@selenic.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
"""Mercurial exceptions.
This allows us to catch exceptions at higher levels without forcing
imports.
"""
# Do not import anything here, please
class HintException(Exception):
def __init__(self, *args, **kw):
Exception.__init__(self, *args)
self.hint = kw.get('hint')
class RevlogError(HintException):
pass
class FilteredIndexError(IndexError):
pass
class LookupError(RevlogError, KeyError):
def __init__(self, name, index, message):
self.name = name
self.index = index
# this can't be called 'message' because at least some installs of
# Python 2.6+ complain about the 'message' property being deprecated
self.lookupmessage = message
if isinstance(name, str) and len(name) == 20:
from node import short
name = short(name)
RevlogError.__init__(self, '%s@%s: %s' % (index, name, message))
def __str__(self):
return RevlogError.__str__(self)
class FilteredLookupError(LookupError):
pass
class ManifestLookupError(LookupError):
pass
class CommandError(Exception):
"""Exception raised on errors in parsing the command line."""
class InterventionRequired(Exception):
"""Exception raised when a command requires human intervention."""
class Abort(HintException):
"""Raised if a command needs to print an error and exit."""
pass
class HookAbort(Abort):
"""raised when a validation hook fails, aborting an operation
Exists to allow more specialized catching."""
pass
class ConfigError(Abort):
"""Exception raised when parsing config files"""
class OutOfBandError(Exception):
"""Exception raised when a remote repo reports failure"""
def __init__(self, *args, **kw):
Exception.__init__(self, *args)
self.hint = kw.get('hint')
class ParseError(Exception):
"""Raised when parsing config files and {rev,file}sets (msg[, pos])"""
class UnknownIdentifier(ParseError):
"""Exception raised when a {rev,file}set references an unknown identifier"""
def __init__(self, function, symbols):
from i18n import _
ParseError.__init__(self, _("unknown identifier: %s") % function)
self.function = function
self.symbols = symbols
class RepoError(HintException):
pass
class RepoLookupError(RepoError):
pass
class FilteredRepoLookupError(RepoLookupError):
pass
class CapabilityError(RepoError):
pass
class RequirementError(RepoError):
"""Exception raised if .hg/requires has an unknown entry."""
pass
class LockError(IOError):
def __init__(self, errno, strerror, filename, desc):
IOError.__init__(self, errno, strerror, filename)
self.desc = desc
class LockHeld(LockError):
def __init__(self, errno, filename, desc, locker):
LockError.__init__(self, errno, 'Lock held', filename, desc)
self.locker = locker
class LockUnavailable(LockError):
pass
class ResponseError(Exception):
"""Raised to print an error with part of output and exit."""
class UnknownCommand(Exception):
"""Exception raised if command is not in the command table."""
class AmbiguousCommand(Exception):
"""Exception raised if command shortcut matches more than one command."""
# derived from KeyboardInterrupt to simplify some breakout code
class SignalInterrupt(KeyboardInterrupt):
"""Exception raised on SIGTERM and SIGHUP."""
class SignatureError(Exception):
pass
class PushRaced(RuntimeError):
"""An exception raised during unbundling that indicate a push race"""
# bundle2 related errors
class BundleValueError(ValueError):
"""error raised when bundle2 cannot be processed"""
class UnsupportedPartError(BundleValueError):
def __init__(self, parttype=None, params=()):
self.parttype = parttype
self.params = params
if self.parttype is None:
msg = 'Stream Parameter'
else:
msg = parttype
if self.params:
msg = '%s - %s' % (msg, ', '.join(self.params))
ValueError.__init__(self, msg)
class ReadOnlyPartError(RuntimeError):
"""error raised when code tries to alter a part being generated"""
pass
class PushkeyFailed(Abort):
"""error raised when a pushkey part failed to update a value"""
def __init__(self, partid, namespace=None, key=None, new=None, old=None,
ret=None):
self.partid = partid
self.namespace = namespace
self.key = key
self.new = new
self.old = old
self.ret = ret
# no i18n expected to be processed into a better message
Abort.__init__(self, 'failed to update value for "%s/%s"'
% (namespace, key))
class CensoredNodeError(RevlogError):
"""error raised when content verification fails on a censored node
Also contains the tombstone data substituted for the uncensored data.
"""
def __init__(self, filename, node, tombstone):
from node import short
RevlogError.__init__(self, '%s:%s' % (filename, short(node)))
self.tombstone = tombstone
class CensoredBaseError(RevlogError):
"""error raised when a delta is rejected because its base is censored
A delta based on a censored revision must be formed as single patch
operation which replaces the entire base with new content. This ensures
the delta may be applied by clones which have not censored the base.
"""