##// END OF EJS Templates
histedit: extract InterventionRequired transaction handling to utils...
Martin von Zweigbergk -
r33446:fad6852c default
parent child Browse files
Show More
@@ -1122,7 +1122,7 b' def _continuehistedit(ui, repo, state):'
1122 # and reopen a transaction. For example, if the action executes an
1122 # and reopen a transaction. For example, if the action executes an
1123 # external process it may choose to commit the transaction first.
1123 # external process it may choose to commit the transaction first.
1124 tr = repo.transaction('histedit')
1124 tr = repo.transaction('histedit')
1125 try:
1125 with util.acceptintervention(tr):
1126 while state.actions:
1126 while state.actions:
1127 state.write(tr=tr)
1127 state.write(tr=tr)
1128 actobj = state.actions[0]
1128 actobj = state.actions[0]
@@ -1136,17 +1136,6 b' def _continuehistedit(ui, repo, state):'
1136 state.replacements.extend(replacement_)
1136 state.replacements.extend(replacement_)
1137 state.actions.pop(0)
1137 state.actions.pop(0)
1138
1138
1139 if tr is not None:
1140 tr.close()
1141 except error.InterventionRequired:
1142 if tr is not None:
1143 tr.close()
1144 raise
1145 except Exception:
1146 if tr is not None:
1147 tr.abort()
1148 raise
1149
1150 state.write()
1139 state.write()
1151 ui.progress(_("editing"), None)
1140 ui.progress(_("editing"), None)
1152
1141
@@ -19,6 +19,7 b' import bz2'
19 import calendar
19 import calendar
20 import codecs
20 import codecs
21 import collections
21 import collections
22 import contextlib
22 import datetime
23 import datetime
23 import errno
24 import errno
24 import gc
25 import gc
@@ -589,6 +590,24 b' class sortdict(collections.OrderedDict):'
589 del self[key]
590 del self[key]
590 super(sortdict, self).__setitem__(key, value)
591 super(sortdict, self).__setitem__(key, value)
591
592
593 @contextlib.contextmanager
594 def acceptintervention(tr=None):
595 """A context manager that closes the transaction on InterventionRequired
596
597 If no transaction was provided, this simply runs the body and returns
598 """
599 if not tr:
600 yield
601 return
602 try:
603 yield
604 tr.close()
605 except error.InterventionRequired:
606 tr.close()
607 raise
608 finally:
609 tr.release()
610
592 class _lrucachenode(object):
611 class _lrucachenode(object):
593 """A node in a doubly linked list.
612 """A node in a doubly linked list.
594
613
General Comments 0
You need to be logged in to leave comments. Login now