Mercurial > hg
changeset 39674:3e8952c0cb45
transaction: make count and usages private attributes
I want to formalize the interface for transactions. As part of
doing that, let's take the opportunity to make some attributes
non-public.
"count" and "usages" track how many times the transaction has
been opened/nested/closed/released. This is internal state and
doesn't need to be part of the public API.
Differential Revision: https://phab.mercurial-scm.org/D4622
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 17 Sep 2018 15:51:19 -0700 |
parents | f1844a10ee19 |
children | da9ce63bfa9b |
files | mercurial/transaction.py |
diffstat | 1 files changed, 15 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/transaction.py Tue Sep 18 13:41:16 2018 +0300 +++ b/mercurial/transaction.py Mon Sep 17 15:51:19 2018 -0700 @@ -38,7 +38,7 @@ def active(func): def _active(self, *args, **kwds): - if self.count == 0: + if self._count == 0: raise error.Abort(_( 'cannot use transaction when it is already committed/aborted')) return func(self, *args, **kwds) @@ -119,8 +119,8 @@ which determine whether file stat ambiguity should be avoided for corresponded files. """ - self.count = 1 - self.usages = 1 + self._count = 1 + self._usages = 1 self.report = report # a vfs to the store content self.opener = opener @@ -191,7 +191,7 @@ def __repr__(self): name = r'/'.join(self.names) return (r'<transaction name=%s, count=%d, usages=%d>' % - (name, self.count, self.usages)) + (name, self._count, self._usages)) def __del__(self): if self.journal: @@ -373,22 +373,22 @@ @active def nest(self, name=r'<unnamed>'): - self.count += 1 - self.usages += 1 + self._count += 1 + self._usages += 1 self.names.append(name) return self def release(self): - if self.count > 0: - self.usages -= 1 + if self._count > 0: + self._usages -= 1 if self.names: self.names.pop() # if the transaction scopes are left without being closed, fail - if self.count > 0 and self.usages == 0: + if self._count > 0 and self._usages == 0: self._abort() def running(self): - return self.count > 0 + return self._count > 0 def addpending(self, category, callback): """add a callback to be called when the transaction is pending @@ -454,7 +454,7 @@ @active def close(self): '''commit the transaction''' - if self.count == 1: + if self._count == 1: self.validator(self) # will raise exception if needed self.validator = None # Help prevent cycles. self._generatefiles(group=gengroupprefinalize) @@ -465,8 +465,8 @@ self._finalizecallback = None self._generatefiles(group=gengrouppostfinalize) - self.count -= 1 - if self.count != 0: + self._count -= 1 + if self._count != 0: return self.file.close() self._backupsfile.close() @@ -557,8 +557,8 @@ def _abort(self): - self.count = 0 - self.usages = 0 + self._count = 0 + self._usages = 0 self.file.close() self._backupsfile.close()