Mercurial > hg
changeset 32346:73e67c4386ec
dirstate: introduce new context manager for marking dirstate parent changes
author | Augie Fackler <augie@google.com> |
---|---|
date | Thu, 18 May 2017 17:10:30 -0400 |
parents | a438f5a3bc09 |
children | f4aee989ebec |
files | mercurial/dirstate.py |
diffstat | 1 files changed, 18 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/dirstate.py Fri May 19 17:01:34 2017 -0700 +++ b/mercurial/dirstate.py Thu May 18 17:10:30 2017 -0400 @@ -8,6 +8,7 @@ from __future__ import absolute_import import collections +import contextlib import errno import os import stat @@ -99,6 +100,23 @@ # for consistent view between _pl() and _read() invocations self._pendingmode = None + @contextlib.contextmanager + def parentchange(self): + '''Context manager for handling dirstate parents. + + If an exception occurs in the scope of the context manager, + the incoherent dirstate won't be written when wlock is + released. + ''' + self._parentwriters += 1 + yield + # Typically we want the "undo" step of a context manager in a + # finally block so it happens even when an exception + # occurs. In this case, however, we only want to decrement + # parentwriters if the code in the with statement exits + # normally, so we don't have a try/finally here on purpose. + self._parentwriters -= 1 + def beginparentchange(self): '''Marks the beginning of a set of changes that involve changing the dirstate parents. If there is an exception during this time,