D2758: transaction: add a name and a __str__ implementation (API)

2018-03-09 Thread martinvonz (Martin von Zweigbergk)
martinvonz updated this revision to Diff 6791.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2758?vs=6790=6791

REVISION DETAIL
  https://phab.mercurial-scm.org/D2758

AFFECTED FILES
  mercurial/localrepo.py
  mercurial/transaction.py

CHANGE DETAILS

diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -105,7 +105,7 @@
 class transaction(util.transactional):
 def __init__(self, report, opener, vfsmap, journalname, undoname=None,
  after=None, createmode=None, validator=None, releasefn=None,
- checkambigfiles=None):
+ checkambigfiles=None, name=r''):
 """Begin a new transaction
 
 Begins a new transaction that allows rolling back writes in the event 
of
@@ -149,6 +149,8 @@
 if checkambigfiles:
 self.checkambigfiles.update(checkambigfiles)
 
+self.names = [name]
+
 # A dict dedicated to precisely tracking the changes introduced in the
 # transaction.
 self.changes = {}
@@ -186,6 +188,11 @@
 # holds callbacks to call during abort
 self._abortcallback = {}
 
+def __repr__(self):
+name = r'/'.join(self.names)
+return (r'' %
+(name, self.count, self.usages))
+
 def __del__(self):
 if self.journal:
 self._abort()
@@ -365,14 +372,17 @@
 self.file.flush()
 
 @active
-def nest(self):
+def nest(self, name=r''):
 self.count += 1
 self.usages += 1
+self.names.append(name)
 return self
 
 def release(self):
 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:
 self._abort()
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1177,7 +1177,7 @@
 raise error.ProgrammingError('transaction requires locking')
 tr = self.currenttransaction()
 if tr is not None:
-return tr.nest()
+return tr.nest(name=desc)
 
 # abort here if the journal already exists
 if self.svfs.exists("journal"):
@@ -1316,7 +1316,8 @@
  self.store.createmode,
  validator=validate,
  releasefn=releasefn,
- checkambigfiles=_cachedfiles)
+ checkambigfiles=_cachedfiles,
+ name=desc)
 tr.changes['revs'] = xrange(0, 0)
 tr.changes['obsmarkers'] = set()
 tr.changes['phases'] = {}



To: martinvonz, #hg-reviewers
Cc: durin42, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2758: transaction: add a name and a __str__ implementation (API)

2018-03-09 Thread martinvonz (Martin von Zweigbergk)
martinvonz added a comment.


  Done

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2758

To: martinvonz, #hg-reviewers
Cc: durin42, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2758: transaction: add a name and a __str__ implementation (API)

2018-03-09 Thread martinvonz (Martin von Zweigbergk)
martinvonz updated this revision to Diff 6790.
martinvonz marked an inline comment as done.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2758?vs=6769=6790

REVISION DETAIL
  https://phab.mercurial-scm.org/D2758

AFFECTED FILES
  mercurial/localrepo.py
  mercurial/transaction.py

CHANGE DETAILS

diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -105,7 +105,7 @@
 class transaction(util.transactional):
 def __init__(self, report, opener, vfsmap, journalname, undoname=None,
  after=None, createmode=None, validator=None, releasefn=None,
- checkambigfiles=None):
+ checkambigfiles=None, name=''):
 """Begin a new transaction
 
 Begins a new transaction that allows rolling back writes in the event 
of
@@ -149,6 +149,8 @@
 if checkambigfiles:
 self.checkambigfiles.update(checkambigfiles)
 
+self.names = [name]
+
 # A dict dedicated to precisely tracking the changes introduced in the
 # transaction.
 self.changes = {}
@@ -186,6 +188,11 @@
 # holds callbacks to call during abort
 self._abortcallback = {}
 
+def __repr__(self):
+name = r'/'.join(self.names)
+return (r'' %
+(name, self.count, self.usages))
+
 def __del__(self):
 if self.journal:
 self._abort()
@@ -365,14 +372,17 @@
 self.file.flush()
 
 @active
-def nest(self):
+def nest(self, name=''):
 self.count += 1
 self.usages += 1
+self.names.append(name)
 return self
 
 def release(self):
 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:
 self._abort()
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1177,7 +1177,7 @@
 raise error.ProgrammingError('transaction requires locking')
 tr = self.currenttransaction()
 if tr is not None:
-return tr.nest()
+return tr.nest(name=desc)
 
 # abort here if the journal already exists
 if self.svfs.exists("journal"):
@@ -1316,7 +1316,8 @@
  self.store.createmode,
  validator=validate,
  releasefn=releasefn,
- checkambigfiles=_cachedfiles)
+ checkambigfiles=_cachedfiles,
+ name=desc)
 tr.changes['revs'] = xrange(0, 0)
 tr.changes['obsmarkers'] = set()
 tr.changes['phases'] = {}



To: martinvonz, #hg-reviewers
Cc: durin42, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2758: transaction: add a name and a __str__ implementation (API)

2018-03-09 Thread durin42 (Augie Fackler)
durin42 added a comment.


  Either way, you should make sure this always returns a sysstr, otherwise 
you'll cause pretty terrible python3 breakage. Look around for other __repr__ 
instances for examples.

INLINE COMMENTS

> transaction.py:191
>  
> +def __str__(self):
> +name = '/'.join(self.names)

nit: I think this would make more sense as a __repr__ than a __str__.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2758

To: martinvonz, #hg-reviewers
Cc: durin42, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2758: transaction: add a name and a __str__ implementation (API)

2018-03-09 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This has been useful for me for debugging.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2758

AFFECTED FILES
  mercurial/localrepo.py
  mercurial/transaction.py

CHANGE DETAILS

diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -105,7 +105,7 @@
 class transaction(util.transactional):
 def __init__(self, report, opener, vfsmap, journalname, undoname=None,
  after=None, createmode=None, validator=None, releasefn=None,
- checkambigfiles=None):
+ checkambigfiles=None, name=''):
 """Begin a new transaction
 
 Begins a new transaction that allows rolling back writes in the event 
of
@@ -149,6 +149,8 @@
 if checkambigfiles:
 self.checkambigfiles.update(checkambigfiles)
 
+self.names = [name]
+
 # A dict dedicated to precisely tracking the changes introduced in the
 # transaction.
 self.changes = {}
@@ -186,6 +188,11 @@
 # holds callbacks to call during abort
 self._abortcallback = {}
 
+def __str__(self):
+name = '/'.join(self.names)
+return ('' %
+(name, self.count, self.usages))
+
 def __del__(self):
 if self.journal:
 self._abort()
@@ -365,14 +372,17 @@
 self.file.flush()
 
 @active
-def nest(self):
+def nest(self, name=''):
 self.count += 1
 self.usages += 1
+self.names.append(name)
 return self
 
 def release(self):
 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:
 self._abort()
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1177,7 +1177,7 @@
 raise error.ProgrammingError('transaction requires locking')
 tr = self.currenttransaction()
 if tr is not None:
-return tr.nest()
+return tr.nest(name=desc)
 
 # abort here if the journal already exists
 if self.svfs.exists("journal"):
@@ -1316,7 +1316,8 @@
  self.store.createmode,
  validator=validate,
  releasefn=releasefn,
- checkambigfiles=_cachedfiles)
+ checkambigfiles=_cachedfiles,
+ name=desc)
 tr.changes['revs'] = xrange(0, 0)
 tr.changes['obsmarkers'] = set()
 tr.changes['phases'] = {}



To: martinvonz, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel