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 48455 5763216ba3117627a4835a5c9724faf625b03415
parent 48454 52e6171ec822165d07cd8fdad3dd10aa8af8990f
child 48456 11d3cd3f0ae5a1e8d354461a0e76e81885605aef
push id884
push usergszorc@mozilla.com
push dateTue, 28 Aug 2018 23:22:35 +0000
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
+++ b/mercurial/changelog.py
@@ -540,24 +540,8 @@ class changelog(revlog.revlog):
 
     def branchinfo(self, rev):
         """return the branch name and open/close state of a revision
 
         This function exists because creating a changectx object
         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
+++ b/mercurial/localrepo.py
@@ -1388,17 +1388,17 @@ class localrepository(object):
                                      "journal",
                                      "undo",
                                      aftertrans(renames),
                                      self.store.createmode,
                                      validator=validate,
                                      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'] = {}
 
         tr.hookargs['txnid'] = txnid
         # note: writing the fncache only during finalize mean that the file is
         # outdated when running hooks. As fncache is used for streaming clone,
         # this is not expected to break anything that happen during the hooks.
@@ -1606,17 +1606,17 @@ class localrepository(object):
         If 'full' is set, make sure all caches the function knows about have
         up-to-date data. Even the ones usually loaded more lazily.
         """
         if tr is not None and tr.hookargs.get('source') == 'strip':
             # During strip, many caches are invalid but
             # 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'))
 
         if full:
             rbc = self.revbranchcache()
             for r in self.changelog:
                 rbc.branchinfo(r)
--- a/mercurial/obsutil.py
+++ b/mercurial/obsutil.py
@@ -460,23 +460,23 @@ def geteffectflag(relation):
 
 def getobsoleted(repo, tr):
     """return the set of pre-existing revisions obsoleted by a transaction"""
     torev = repo.unfiltered().changelog.nodemap.get
     phase = repo._phasecache.phase
     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:
             continue
         if set(succsmarkers(node) or []).issubset(addedmarkers):
             obsoleted.add(rev)
     return obsoleted
 
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -1613,46 +1613,46 @@ def registersummarycallback(repo, otr, t
                 msg = getinstabilitymessage(delta, instability)
                 if msg:
                     repo.ui.warn(msg)
 
     if txmatch(_reportnewcssource):
         @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
             minrev, maxrev = repo[revs.min()], repo[revs.max()]
 
             if minrev == maxrev:
                 revrange = minrev
             else:
                 revrange = '%s:%s' % (minrev, maxrev)
             repo.ui.status(_('new changesets %s\n') % revrange)
 
         @reportsummary
         def reportphasechanges(repo, tr):
             """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
             repo.ui.status(_('%d local changesets published\n')
                            % len(published))
 
 def getinstabilitymessage(delta, instability):
     """function to return the message to show warning about new instabilities
--- a/tests/test-clone-uncompressed.t
+++ b/tests/test-clone-uncompressed.t
@@ -242,16 +242,17 @@ Clone with background file closing enabl
   $ hg --debug --config worker.backgroundclose=true --config worker.backgroundcloseminfilecount=1 clone --stream -U http://localhost:$HGPORT clone-background | grep -v adding
   using http://localhost:$HGPORT/
   sending capabilities command
   sending branchmap command
   streaming all changes
   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
   searching for changes
   all remote heads known locally
   no changes found
   sending getbundle command
   bundle2-input-bundle: with-transaction
@@ -270,16 +271,17 @@ Clone with background file closing enabl
   streaming all changes
   sending getbundle command
   bundle2-input-bundle: with-transaction
   bundle2-input-part: "stream2" (params: 3 mandatory) supported
   applying stream bundle
   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
   bundle2-input-bundle: 1 parts total
   checking for updated bookmarks
 #endif
 
 Cannot stream clone when there are secret changesets
--- a/tests/test-stream-bundle-v2.t
+++ b/tests/test-stream-bundle-v2.t
@@ -83,16 +83,17 @@ Test that we can apply the bundle as a s
   adding [s] 00changelog.i (595 bytes)
   adding [s] phaseroots (43 bytes)
   adding [c] branch2-served (94 bytes)
   adding [c] rbc-names-v1 (7 bytes)
   adding [c] rbc-revs-v1 (40 bytes)
   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
   searching for changes
   all remote heads known locally
   no changes found
   sending getbundle command
   bundle2-input-bundle: with-transaction
@@ -137,16 +138,17 @@ Test that we can apply the bundle as a s
   adding [s] 00changelog.i (595 bytes)
   adding [s] phaseroots (43 bytes)
   adding [c] branch2-served (94 bytes)
   adding [c] rbc-names-v1 (7 bytes)
   adding [c] rbc-revs-v1 (40 bytes)
   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
   searching for changes
   all remote heads known locally
   no changes found
   sending getbundle command
   bundle2-input-bundle: with-transaction