import: use dirstateguard instead of dirstate.invalidate
Before this patch, "commands.import()" uses "dirstate.invalidate()" as
a kind of "restore .hg/dirstate to the original status" during a failure.
But it just discards changes in memory, and doesn't actually restore
".hg/dirstate". Then, it can't work as expected, if "dirstate.write()"
is executed while processing.
This patch uses "dirstateguard" instead of "dirstate.invalidate()" to
restore ".hg/dirstate" at failure even if "dirstate.write()" is
executed before failure.
This patch also removes "beginparentchage()" and "endparentchange()",
because "dirstateguard" makes them useless, too.
This is a part of preparations to fix the issue that the recent (in
memory) dirstate isn't visible to external process (e.g. "precommit"
hook).
--- a/mercurial/commands.py Thu May 07 12:07:10 2015 +0900
+++ b/mercurial/commands.py Thu May 07 12:07:10 2015 +0900
@@ -4213,7 +4213,7 @@
cmdutil.bailifchanged(repo)
base = opts["base"]
- wlock = lock = tr = None
+ wlock = dsguard = lock = tr = None
msgs = []
ret = 0
@@ -4221,7 +4221,7 @@
try:
try:
wlock = repo.wlock()
- repo.dirstate.beginparentchange()
+ dsguard = cmdutil.dirstateguard(repo, 'import')
if not opts.get('no_commit'):
lock = repo.lock()
tr = repo.transaction('import')
@@ -4262,18 +4262,16 @@
tr.close()
if msgs:
repo.savecommitmessage('\n* * *\n'.join(msgs))
- repo.dirstate.endparentchange()
+ dsguard.close()
return ret
- except: # re-raises
- # wlock.release() indirectly calls dirstate.write(): since
- # we're crashing, we do not want to change the working dir
- # parent after all, so make sure it writes nothing
- repo.dirstate.invalidate()
- raise
+ finally:
+ # TODO: get rid of this meaningless try/finally enclosing.
+ # this is kept only to reduce changes in a patch.
+ pass
finally:
if tr:
tr.release()
- release(lock, wlock)
+ release(lock, dsguard, wlock)
@command('incoming|in',
[('f', 'force', None,