comparison mercurial/cmdutil.py @ 24993:be58bd30a478

amend: use dirstateguard instead of dirstate.invalidate Before this patch, "cmdutil.amend()" 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 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).
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Thu, 07 May 2015 12:07:10 +0900
parents 4169a4f83548
children 0579b0c2ea2b
comparison
equal deleted inserted replaced
24992:7df090c9c9fe 24993:be58bd30a478
2462 ui.username() # raise exception if username not set 2462 ui.username() # raise exception if username not set
2463 2463
2464 ui.note(_('amending changeset %s\n') % old) 2464 ui.note(_('amending changeset %s\n') % old)
2465 base = old.p1() 2465 base = old.p1()
2466 2466
2467 wlock = lock = newid = None 2467 wlock = dsguard = lock = newid = None
2468 try: 2468 try:
2469 wlock = repo.wlock() 2469 wlock = repo.wlock()
2470 dsguard = dirstateguard(repo, 'amend')
2470 lock = repo.lock() 2471 lock = repo.lock()
2471 tr = repo.transaction('amend') 2472 tr = repo.transaction('amend')
2472 try: 2473 try:
2473 # See if we got a message from -m or -l, if not, open the editor 2474 # See if we got a message from -m or -l, if not, open the editor
2474 # with the message of the changeset to amend 2475 # with the message of the changeset to amend
2635 2636
2636 obsolete.createmarkers(repo, obs) 2637 obsolete.createmarkers(repo, obs)
2637 tr.close() 2638 tr.close()
2638 finally: 2639 finally:
2639 tr.release() 2640 tr.release()
2641 dsguard.close()
2640 if not createmarkers and newid != old.node(): 2642 if not createmarkers and newid != old.node():
2641 # Strip the intermediate commit (if there was one) and the amended 2643 # Strip the intermediate commit (if there was one) and the amended
2642 # commit 2644 # commit
2643 if node: 2645 if node:
2644 ui.note(_('stripping intermediate changeset %s\n') % ctx) 2646 ui.note(_('stripping intermediate changeset %s\n') % ctx)
2645 ui.note(_('stripping amended changeset %s\n') % old) 2647 ui.note(_('stripping amended changeset %s\n') % old)
2646 repair.strip(ui, repo, old.node(), topic='amend-backup') 2648 repair.strip(ui, repo, old.node(), topic='amend-backup')
2647 finally: 2649 finally:
2648 if newid is None: 2650 lockmod.release(lock, dsguard, wlock)
2649 repo.dirstate.invalidate()
2650 lockmod.release(lock, wlock)
2651 return newid 2651 return newid
2652 2652
2653 def commiteditor(repo, ctx, subs, editform=''): 2653 def commiteditor(repo, ctx, subs, editform=''):
2654 if ctx.description(): 2654 if ctx.description():
2655 return ctx.description() 2655 return ctx.description()