changegroup: track changelog to manifest revision map explicitly
authorGregory Szorc <gregory.szorc@gmail.com>
Tue, 07 Aug 2018 10:55:32 -0700
changeset 38998 40374b4a780f
parent 38997 812eec3f89cb
child 38999 b83e9c503f2f
changegroup: track changelog to manifest revision map explicitly Previously, self._nextclrevtolocalrev was only populated as part of the changelog lookup callback. But cgpacker._close() was looking at self._nextclrevtolocalrev on every invocation. Since self._nextclrevtolocalrev is for communicating the mapping of changelog revisions to manifest revisions, this commit refactors the code to make that explicit. The changelog state now stores this mapping. And after the changelog group is emitted, we update self._clrevtolocalrev with that dict. self._nextclrevtolocalrev is unused and has been deleted. Differential Revision: https://phab.mercurial-scm.org/D4190
mercurial/changegroup.py
--- a/mercurial/changegroup.py	Tue Aug 07 10:49:41 2018 -0700
+++ b/mercurial/changegroup.py	Tue Aug 07 10:55:32 2018 -0700
@@ -661,14 +661,10 @@
         # Maps CL revs to per-revlog revisions. Cleared in close() at
         # the end of each group.
         self._clrevtolocalrev = {}
-        self._nextclrevtolocalrev = {}
 
     def _close(self):
         # Ellipses serving mode.
         self._clrevtolocalrev.clear()
-        if self._nextclrevtolocalrev is not None:
-            self._clrevtolocalrev = self._nextclrevtolocalrev
-            self._nextclrevtolocalrev = None
 
         return closechunk()
 
@@ -784,6 +780,9 @@
         mfs = clstate['mfs']
         changedfiles = clstate['changedfiles']
 
+        if self._ellipses:
+            self._clrevtolocalrev = clstate['clrevtomanifestrev']
+
         # We need to make sure that the linkrev in the changegroup refers to
         # the first changeset that introduced the manifest or file revision.
         # The fastpath is usually safer than the slowpath, because the filelogs
@@ -853,6 +852,7 @@
         # TODO violates storage abstraction.
         mfrevlog = mfl._revlog
         changedfiles = set()
+        clrevtomanifestrev = {}
 
         # Callback for the changelog, used to collect changed files and
         # manifest nodes.
@@ -876,8 +876,7 @@
                     # manifest revnum to look up for this cl revnum. (Part of
                     # mapping changelog ellipsis parents to manifest ellipsis
                     # parents)
-                    self._nextclrevtolocalrev.setdefault(cl.rev(x),
-                                                         mfrevlog.rev(n))
+                    clrevtomanifestrev.setdefault(cl.rev(x), mfrevlog.rev(n))
                 # We can't trust the changed files list in the changeset if the
                 # client requested a shallow clone.
                 if self._isshallow:
@@ -903,6 +902,7 @@
             'clrevorder': clrevorder,
             'mfs': mfs,
             'changedfiles': changedfiles,
+            'clrevtomanifestrev': clrevtomanifestrev,
         }
 
         gen = self.group(revs, cl, True, lookupcl, units=_('changesets'))