transaction-summary: display the summary for all transactions
authorBoris Feld <boris.feld@octobus.net>
Sun, 16 Jul 2017 02:20:06 +0200
changeset 33541 b47fef6d2365
parent 33540 e07c5740eaaa
child 33542 b11e8c67fb0f
transaction-summary: display the summary for all transactions Now that we records "all" changes happening in a transaction (in tr.changes) we will be able to provide better report on various changes (phases turned public, changeset obsoleted, branch merged or created, etc..) This is far too late in the cycle to play with this, but having this existing method called more widely will help extensions to play around with various options during the 4.4 cycle. Instead of calling registersummarycallback only for transactions we want, we always call it and use the transaction name to decide when to report (eg: we do not want `hg amend` to report new obsoleted changesets). Filtering on transaction name does not seems great, but seems good enough for the moment. We can change the API during the next cycle. The previous manual call during unbundling of the bundle2 "obsmarkers" part is no longer necessary and has been dropped.
mercurial/bundle2.py
mercurial/localrepo.py
mercurial/scmutil.py
--- a/mercurial/bundle2.py	Sun Jul 16 02:38:14 2017 +0200
+++ b/mercurial/bundle2.py	Sun Jul 16 02:20:06 2017 +0200
@@ -161,7 +161,6 @@
     phases,
     pushkey,
     pycompat,
-    scmutil,
     tags,
     url,
     util,
@@ -1814,7 +1813,6 @@
     if new:
         op.repo.ui.status(_('%i new obsolescence markers\n') % new)
     op.records.add('obsmarkers', {'new': new})
-    scmutil.registersummarycallback(op.repo, tr)
     if op.reply is not None:
         rpart = op.reply.newpart('reply:obsmarkers')
         rpart.addparam('in-reply-to', str(inpart.id), mandatory=False)
--- a/mercurial/localrepo.py	Sun Jul 16 02:38:14 2017 +0200
+++ b/mercurial/localrepo.py	Sun Jul 16 02:20:06 2017 +0200
@@ -1099,6 +1099,7 @@
                 raise error.ProgrammingError('transaction requires locking')
         tr = self.currenttransaction()
         if tr is not None:
+            scmutil.registersummarycallback(self, tr, desc)
             return tr.nest()
 
         # abort here if the journal already exists
@@ -1255,6 +1256,7 @@
         # to stored data if transaction has no error.
         tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats)
         self._transref = weakref.ref(tr)
+        scmutil.registersummarycallback(self, tr, desc)
         return tr
 
     def _journalfiles(self):
--- a/mercurial/scmutil.py	Sun Jul 16 02:38:14 2017 +0200
+++ b/mercurial/scmutil.py	Sun Jul 16 02:20:06 2017 +0200
@@ -1080,14 +1080,25 @@
         with self.vfs(self.path, mode='wb', atomictemp=True) as fp:
             fp.write(''.join(lines))
 
-def registersummarycallback(repo, otr):
+_reportobsoletedsource = [
+    'pull',
+    'push',
+    'serve',
+    'unbundle',
+]
+
+def registersummarycallback(repo, otr, txnname=''):
     """register a callback to issue a summary after the transaction is closed
     """
-    reporef = weakref.ref(repo)
-    def reportsummary(tr):
-        """the actual callback reporting the summary"""
-        repo = reporef()
-        obsoleted = obsutil.getobsoleted(repo, tr)
-        if obsoleted:
-            repo.ui.status(_('obsoleted %i changesets\n') % len(obsoleted))
-    otr.addpostclose('00-txnreport', reportsummary)
+    for source in _reportobsoletedsource:
+        if txnname.startswith(source):
+            reporef = weakref.ref(repo)
+            def reportsummary(tr):
+                """the actual callback reporting the summary"""
+                repo = reporef()
+                obsoleted = obsutil.getobsoleted(repo, tr)
+                if obsoleted:
+                    repo.ui.status(_('obsoleted %i changesets\n')
+                                   % len(obsoleted))
+            otr.addpostclose('00-txnreport', reportsummary)
+            break