##// END OF EJS Templates
transaction: add a name and a __repr__ implementation (API)...
Martin von Zweigbergk -
r36837:aff5996f default
parent child Browse files
Show More
@@ -1177,7 +1177,7 class localrepository(object):
1177 1177 raise error.ProgrammingError('transaction requires locking')
1178 1178 tr = self.currenttransaction()
1179 1179 if tr is not None:
1180 return tr.nest()
1180 return tr.nest(name=desc)
1181 1181
1182 1182 # abort here if the journal already exists
1183 1183 if self.svfs.exists("journal"):
@@ -1316,7 +1316,8 class localrepository(object):
1316 1316 self.store.createmode,
1317 1317 validator=validate,
1318 1318 releasefn=releasefn,
1319 checkambigfiles=_cachedfiles)
1319 checkambigfiles=_cachedfiles,
1320 name=desc)
1320 1321 tr.changes['revs'] = xrange(0, 0)
1321 1322 tr.changes['obsmarkers'] = set()
1322 1323 tr.changes['phases'] = {}
@@ -105,7 +105,7 def _playback(journal, report, opener, v
105 105 class transaction(util.transactional):
106 106 def __init__(self, report, opener, vfsmap, journalname, undoname=None,
107 107 after=None, createmode=None, validator=None, releasefn=None,
108 checkambigfiles=None):
108 checkambigfiles=None, name=r'<unnamed>'):
109 109 """Begin a new transaction
110 110
111 111 Begins a new transaction that allows rolling back writes in the event of
@@ -149,6 +149,8 class transaction(util.transactional):
149 149 if checkambigfiles:
150 150 self.checkambigfiles.update(checkambigfiles)
151 151
152 self.names = [name]
153
152 154 # A dict dedicated to precisely tracking the changes introduced in the
153 155 # transaction.
154 156 self.changes = {}
@@ -186,6 +188,11 class transaction(util.transactional):
186 188 # holds callbacks to call during abort
187 189 self._abortcallback = {}
188 190
191 def __repr__(self):
192 name = r'/'.join(self.names)
193 return (r'<transaction name=%s, count=%d, usages=%d>' %
194 (name, self.count, self.usages))
195
189 196 def __del__(self):
190 197 if self.journal:
191 198 self._abort()
@@ -365,14 +372,17 class transaction(util.transactional):
365 372 self.file.flush()
366 373
367 374 @active
368 def nest(self):
375 def nest(self, name=r'<unnamed>'):
369 376 self.count += 1
370 377 self.usages += 1
378 self.names.append(name)
371 379 return self
372 380
373 381 def release(self):
374 382 if self.count > 0:
375 383 self.usages -= 1
384 if self.names:
385 self.names.pop()
376 386 # if the transaction scopes are left without being closed, fail
377 387 if self.count > 0 and self.usages == 0:
378 388 self._abort()
General Comments 0
You need to be logged in to leave comments. Login now