[PATCH 4 of 9 V2] import: use dirstateguard instead of dirstate.invalidate
FUJIWARA Katsunori
foozy at lares.dti.ne.jp
Sat May 2 15:59:39 UTC 2015
# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1430582197 -32400
# Sun May 03 00:56:37 2015 +0900
# Node ID f0826bbe149010938a73288e8cfe12a012728f54
# Parent 80a0f16dcf3cbce2ea50db0d6408f848bc1a75e2
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" at 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 recent (in
memory) dirstate isn't visible to external process (e.g. "precommit"
hook).
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -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,
More information about the Mercurial-devel
mailing list