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