transaction: remember original len(repo) instead of tracking added revs (API)
authorYuya Nishihara <yuya@tcha.org>
Sat, 25 Aug 2018 15:28:48 +0900
changeset 39301 5763216ba311
parent 39300 52e6171ec822
child 39302 11d3cd3f0ae5
transaction: remember original len(repo) instead of tracking added revs (API) It's silly to keep updating xrange(len(changelog), len(changelog) + 1) for each added revision. Instead, let's simply remember the first revision to be added. The test output slightly changed as the branch cache is also warmed up by stream clone, which seems more consistent. .. api:: ``tr.changes['revs']`` is replaced by ``tr.changes['origrepolen']`` which is the first revision number to be added.
mercurial/changelog.py
mercurial/localrepo.py
mercurial/obsutil.py
mercurial/scmutil.py
tests/test-clone-uncompressed.t
tests/test-stream-bundle-v2.t
--- a/mercurial/changelog.py	Sat Aug 25 15:19:43 2018 +0900
+++ b/mercurial/changelog.py	Sat Aug 25 15:28:48 2018 +0900
@@ -545,19 +545,3 @@
         just to access this is costly."""
         extra = self.read(rev)[5]
         return encoding.tolocal(extra.get("branch")), 'close' in extra
-
-    def _addrevision(self, node, rawtext, transaction, *args, **kwargs):
-        # overlay over the standard revlog._addrevision to track the new
-        # revision on the transaction.
-        rev = len(self)
-        node = super(changelog, self)._addrevision(node, rawtext, transaction,
-                                                   *args, **kwargs)
-        revs = transaction.changes.get('revs')
-        if revs is not None:
-            if revs:
-                assert revs[-1] + 1 == rev
-                revs = pycompat.membershiprange(revs[0], rev + 1)
-            else:
-                revs = pycompat.membershiprange(rev, rev + 1)
-            transaction.changes['revs'] = revs
-        return node
--- a/mercurial/localrepo.py	Sat Aug 25 15:19:43 2018 +0900
+++ b/mercurial/localrepo.py	Sat Aug 25 15:28:48 2018 +0900
@@ -1393,7 +1393,7 @@
                                      releasefn=releasefn,
                                      checkambigfiles=_cachedfiles,
                                      name=desc)
-        tr.changes['revs'] = pycompat.xrange(0, 0)
+        tr.changes['origrepolen'] = len(self)
         tr.changes['obsmarkers'] = set()
         tr.changes['phases'] = {}
         tr.changes['bookmarks'] = {}
@@ -1611,7 +1611,7 @@
             # later call to `destroyed` will refresh them.
             return
 
-        if tr is None or tr.changes['revs']:
+        if tr is None or tr.changes['origrepolen'] < len(self):
             # updating the unfiltered branchmap should refresh all the others,
             self.ui.debug('updating the branch cache\n')
             branchmap.updatecache(self.filtered('served'))
--- a/mercurial/obsutil.py	Sat Aug 25 15:19:43 2018 +0900
+++ b/mercurial/obsutil.py	Sat Aug 25 15:28:48 2018 +0900
@@ -465,13 +465,13 @@
     succsmarkers = repo.obsstore.successors.get
     public = phases.public
     addedmarkers = tr.changes.get('obsmarkers')
-    addedrevs = tr.changes['revs']
+    origrepolen = tr.changes['origrepolen']
     seenrevs = set()
     obsoleted = set()
     for mark in addedmarkers:
         node = mark[0]
         rev = torev(node)
-        if rev is None or rev in seenrevs or rev in addedrevs:
+        if rev is None or rev in seenrevs or rev >= origrepolen:
             continue
         seenrevs.add(rev)
         if phase(repo, rev) == public:
--- a/mercurial/scmutil.py	Sat Aug 25 15:19:43 2018 +0900
+++ b/mercurial/scmutil.py	Sat Aug 25 15:28:48 2018 +0900
@@ -1618,13 +1618,13 @@
         @reportsummary
         def reportnewcs(repo, tr):
             """Report the range of new revisions pulled/unbundled."""
-            newrevs = tr.changes.get('revs', pycompat.xrange(0, 0))
-            if not newrevs:
+            origrepolen = tr.changes.get('origrepolen', len(repo))
+            if origrepolen >= len(repo):
                 return
 
             # Compute the bounds of new revisions' range, excluding obsoletes.
             unfi = repo.unfiltered()
-            revs = unfi.revs('%ld and not obsolete()', newrevs)
+            revs = unfi.revs('%d: and not obsolete()', origrepolen)
             if not revs:
                 # Got only obsoletes.
                 return
@@ -1641,13 +1641,13 @@
             """Report statistics of phase changes for changesets pre-existing
             pull/unbundle.
             """
-            newrevs = tr.changes.get('revs', pycompat.xrange(0, 0))
+            origrepolen = tr.changes.get('origrepolen', len(repo))
             phasetracking = tr.changes.get('phases', {})
             if not phasetracking:
                 return
             published = [
                 rev for rev, (old, new) in phasetracking.iteritems()
-                if new == phases.public and rev not in newrevs
+                if new == phases.public and rev < origrepolen
             ]
             if not published:
                 return
--- a/tests/test-clone-uncompressed.t	Sat Aug 25 15:19:43 2018 +0900
+++ b/tests/test-clone-uncompressed.t	Sat Aug 25 15:28:48 2018 +0900
@@ -247,6 +247,7 @@
   sending stream_out command
   1027 files to transfer, 96.3 KB of data
   starting 4 threads for background file closing
+  updating the branch cache
   transferred 96.3 KB in * seconds (*/sec) (glob)
   query 1; heads
   sending batch command
@@ -275,6 +276,7 @@
   1030 files to transfer, 96.4 KB of data
   starting 4 threads for background file closing
   starting 4 threads for background file closing
+  updating the branch cache
   transferred 96.4 KB in * seconds (* */sec) (glob)
   bundle2-input-part: total payload size 112077
   bundle2-input-part: "listkeys" (params: 1 mandatory) supported
--- a/tests/test-stream-bundle-v2.t	Sat Aug 25 15:19:43 2018 +0900
+++ b/tests/test-stream-bundle-v2.t	Sat Aug 25 15:28:48 2018 +0900
@@ -88,6 +88,7 @@
   transferred 1.65 KB in \d\.\d seconds \(.*/sec\) (re)
   bundle2-input-part: total payload size 1840
   bundle2-input-bundle: 0 parts total
+  updating the branch cache
   finished applying clone bundle
   query 1; heads
   sending batch command
@@ -142,6 +143,7 @@
   transferred 1.65 KB in *.* seconds (*/sec) (glob)
   bundle2-input-part: total payload size 1840
   bundle2-input-bundle: 0 parts total
+  updating the branch cache
   finished applying clone bundle
   query 1; heads
   sending batch command