# HG changeset patch # User Matt Mackall # Date 2010-11-22 18:43:31 # Node ID e41e2b79883dc7638809f3c841e1fcbb56417f4b # Parent 3da456d0c8852d448064c4cbb1fdb234e1b406b9 dirstate: warn on invalid parents rather than aborting This allows more graceful recovery from some mangled dirstates diff --git a/hgext/bookmarks.py b/hgext/bookmarks.py --- a/hgext/bookmarks.py +++ b/hgext/bookmarks.py @@ -348,14 +348,12 @@ def reposetup(ui, repo): return result def addchangegroup(self, *args, **kwargs): - parents = self.dirstate.parents() - result = super(bookmark_repo, self).addchangegroup(*args, **kwargs) if result > 1: # We have more heads than before return result node = self.changelog.tip() - + parents = self.dirstate.parents() self._bookmarksupdate(parents, node) return result diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py --- a/mercurial/dirstate.py +++ b/mercurial/dirstate.py @@ -36,7 +36,7 @@ def _decdirs(dirs, path): class dirstate(object): - def __init__(self, opener, ui, root): + def __init__(self, opener, ui, root, validate): '''Create a new dirstate object. opener is an open()-like callable that can be used to open the @@ -44,6 +44,7 @@ class dirstate(object): the dirstate. ''' self._opener = opener + self._validate = validate self._root = root self._rootdir = os.path.join(root, '') self._dirty = False @@ -197,7 +198,7 @@ class dirstate(object): yield x def parents(self): - return self._pl + return [self._validate(p) for p in self._pl] def branch(self): return self._branch diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -178,7 +178,19 @@ class localrepository(repo.repository): @propertycache def dirstate(self): - return dirstate.dirstate(self.opener, self.ui, self.root) + warned = [0] + def validate(node): + try: + r = self.changelog.rev(node) + return node + except error.LookupError: + if not warned[0]: + warned[0] = True + self.ui.warn(_("warning: ignoring unknown" + " working parent %s!\n" % short(node))) + return nullid + + return dirstate.dirstate(self.opener, self.ui, self.root, validate) def __getitem__(self, changeid): if changeid is None: