diff mercurial/scmutil.py @ 34661:eb586ed5d8ce

transaction-summary: show the range of new revisions upon pull/unbundle (BC) Upon pull or unbundle, we display a message with the range of new revisions fetched. This revision range could readily be used after a pull to look out what's new with 'hg log'. The algorithm takes care of filtering "obsolete" revisions that might be present in transaction's "changes" but should not be displayed to the end user.
author Denis Laxalde <denis.laxalde@logilab.fr>
date Thu, 12 Oct 2017 09:39:50 +0200
parents 75979c8d4572
children 0c06875e7755
line wrap: on
line diff
--- a/mercurial/scmutil.py	Fri Oct 13 21:36:10 2017 +0900
+++ b/mercurial/scmutil.py	Thu Oct 12 09:39:50 2017 +0200
@@ -1200,6 +1200,11 @@
     'unbundle',
 ]
 
+_reportnewcssource = [
+    'pull',
+    'unbundle',
+]
+
 def registersummarycallback(repo, otr, txnname=''):
     """register a callback to issue a summary after the transaction is closed
     """
@@ -1226,3 +1231,34 @@
             if obsoleted:
                 repo.ui.status(_('obsoleted %i changesets\n')
                                % len(obsoleted))
+
+    if txmatch(_reportnewcssource):
+        @reportsummary
+        def reportnewcs(repo, tr):
+            """Report the range of new revisions pulled/unbundled."""
+            newrevs = list(tr.changes.get('revs', set()))
+            if not newrevs:
+                return
+
+            # Compute the bounds of new revisions' range, excluding obsoletes.
+            unfi = repo.unfiltered()
+            minrev, maxrev = None, None
+            newrevs.sort()
+            for r in newrevs:
+                if not unfi[r].obsolete():
+                    minrev = repo[r]
+                    break
+            for r in reversed(newrevs):
+                if not unfi[r].obsolete():
+                    maxrev = repo[r]
+                    break
+
+            if minrev is None or maxrev is None:
+                # Got only obsoletes.
+                return
+
+            if minrev == maxrev:
+                revrange = minrev
+            else:
+                revrange = '%s:%s' % (minrev, maxrev)
+            repo.ui.status(_('new changesets %s\n') % revrange)