Show More
@@ -84,7 +84,7 b' def _playback(journal, report, opener, v' | |||||
84 |
|
84 | |||
85 | class transaction(object): |
|
85 | class transaction(object): | |
86 | def __init__(self, report, opener, vfsmap, journal, after=None, |
|
86 | def __init__(self, report, opener, vfsmap, journal, after=None, | |
87 |
createmode |
|
87 | createmode=None, onabort=None): | |
88 | """Begin a new transaction |
|
88 | """Begin a new transaction | |
89 |
|
89 | |||
90 | Begins a new transaction that allows rolling back writes in the event of |
|
90 | Begins a new transaction that allows rolling back writes in the event of | |
@@ -92,8 +92,6 b' class transaction(object):' | |||||
92 |
|
92 | |||
93 | * `after`: called after the transaction has been committed |
|
93 | * `after`: called after the transaction has been committed | |
94 | * `createmode`: the mode of the journal file that will be created |
|
94 | * `createmode`: the mode of the journal file that will be created | |
95 | * `onclose`: called as the transaction is closing, but before it is |
|
|||
96 | closed |
|
|||
97 | * `onabort`: called as the transaction is aborting, but before any files |
|
95 | * `onabort`: called as the transaction is aborting, but before any files | |
98 | have been truncated |
|
96 | have been truncated | |
99 | """ |
|
97 | """ | |
@@ -107,7 +105,6 b' class transaction(object):' | |||||
107 | vfsmap[''] = opener # set default value |
|
105 | vfsmap[''] = opener # set default value | |
108 | self._vfsmap = vfsmap |
|
106 | self._vfsmap = vfsmap | |
109 | self.after = after |
|
107 | self.after = after | |
110 | self.onclose = onclose |
|
|||
111 | self.onabort = onabort |
|
108 | self.onabort = onabort | |
112 | self.entries = [] |
|
109 | self.entries = [] | |
113 | self.map = {} |
|
110 | self.map = {} | |
@@ -375,8 +372,6 b' class transaction(object):' | |||||
375 | categories = sorted(self._finalizecallback) |
|
372 | categories = sorted(self._finalizecallback) | |
376 | for cat in categories: |
|
373 | for cat in categories: | |
377 | self._finalizecallback[cat](self) |
|
374 | self._finalizecallback[cat](self) | |
378 | if self.onclose is not None: |
|
|||
379 | self.onclose() |
|
|||
380 |
|
375 | |||
381 | self.count -= 1 |
|
376 | self.count -= 1 | |
382 | if self.count != 0: |
|
377 | if self.count != 0: |
@@ -241,22 +241,22 b' Aborted transactions can be recovered la' | |||||
241 |
|
241 | |||
242 | $ cat > ../exceptionext.py <<EOF |
|
242 | $ cat > ../exceptionext.py <<EOF | |
243 | > import os |
|
243 | > import os | |
244 | > from mercurial import commands, util, transaction |
|
244 | > from mercurial import commands, util, transaction, localrepo | |
245 | > from mercurial.extensions import wrapfunction |
|
245 | > from mercurial.extensions import wrapfunction | |
246 | > |
|
246 | > | |
247 |
> def |
|
247 | > def trwrapper(orig, self, *args, **kwargs): | |
248 | > origonclose = self.onclose |
|
248 | > tr = orig(self, *args, **kwargs) | |
249 |
> def |
|
249 | > def fail(tr): | |
250 | > origonclose() |
|
|||
251 | > raise util.Abort("forced transaction failure") |
|
250 | > raise util.Abort("forced transaction failure") | |
252 | > self.onclose = onclose |
|
251 | > # zzz prefix to ensure it sorted after store.write | |
253 | > return orig(self, *args, **kwargs) |
|
252 | > tr.addfinalize('zzz-forcefails', fail) | |
|
253 | > return tr | |||
254 | > |
|
254 | > | |
255 | > def abortwrapper(orig, self, *args, **kwargs): |
|
255 | > def abortwrapper(orig, self, *args, **kwargs): | |
256 | > raise util.Abort("forced transaction failure") |
|
256 | > raise util.Abort("forced transaction failure") | |
257 | > |
|
257 | > | |
258 | > def uisetup(ui): |
|
258 | > def uisetup(ui): | |
259 |
> wrapfunction( |
|
259 | > wrapfunction(localrepo.localrepository, 'transaction', trwrapper) | |
260 | > wrapfunction(transaction.transaction, '_abort', abortwrapper) |
|
260 | > wrapfunction(transaction.transaction, '_abort', abortwrapper) | |
261 | > |
|
261 | > | |
262 | > cmdtable = {} |
|
262 | > cmdtable = {} |
General Comments 0
You need to be logged in to leave comments.
Login now