[PATCH 4 of 4 v2] changegroup3: move treemanifest support into _unpackmanifests()

Martin von Zweigbergk martinvonz at google.com
Wed Jan 13 12:09:42 CST 2016


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1452298378 28800
#      Fri Jan 08 16:12:58 2016 -0800
# Node ID 42af0ccdbc9ededd770e35f3f7243dbc81ac98df
# Parent  12f845942d02e226575a9185cda3b2ede378fe46
changegroup3: move treemanifest support into _unpackmanifests()

By putting the treemanifest code in _unpackmanifests(),
_addchangegroupfiles() will only be about files again, and we get a
nice symmetry between _packmanifests() and _unpackmanifest(). The
immediate benefit to me is that remotefilelog should not need to be
updated to work with treemanifests. It should also make
server.validate and progress output easier to get right. Probably
bundlerepo too.

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -517,6 +517,20 @@
         node, p1, p2, deltabase, cs, flags = headertuple
         return node, p1, p2, deltabase, cs, flags
 
+    def _unpackmanifests(self, repo, revmap, trp, prog, numchanges):
+        super(cg3unpacker, self)._unpackmanifests(repo, revmap, trp, prog,
+                                                  numchanges)
+        while True:
+            chunkdata = self.filelogheader()
+            if not chunkdata:
+                break
+            # If we get here, there are directory manifests in the changegroup
+            d = chunkdata["filename"]
+            repo.ui.debug("adding %s revisions\n" % d)
+            dirlog = repo.manifest.dirlog(d)
+            if not dirlog.addgroup(self, revmap, trp):
+                raise error.Abort(_("received dir revlog group is empty"))
+
 class headerlessfixup(object):
     def __init__(self, fh, h):
         self._h = h
@@ -1055,32 +1069,22 @@
 def _addchangegroupfiles(repo, source, revmap, trp, pr, needfiles):
     revisions = 0
     files = 0
-    submfsdone = False
     while True:
         chunkdata = source.filelogheader()
         if not chunkdata:
-            if source.version == "03" and not submfsdone:
-                submfsdone = True
-                continue
             break
         f = chunkdata["filename"]
         repo.ui.debug("adding %s revisions\n" % f)
         pr()
-        directory = (f[-1] == '/')
-        if directory:
-            # a directory using treemanifests
-            fl = repo.manifest.dirlog(f)
-        else:
-            fl = repo.file(f)
+        fl = repo.file(f)
         o = len(fl)
         try:
             if not fl.addgroup(source, revmap, trp):
                 raise error.Abort(_("received file revlog group is empty"))
         except error.CensoredBaseError as e:
             raise error.Abort(_("received delta base is censored: %s") % e)
-        if not directory:
-            revisions += len(fl) - o
-            files += 1
+        revisions += len(fl) - o
+        files += 1
         if f in needfiles:
             needs = needfiles[f]
             for new in xrange(o, len(fl)):


More information about the Mercurial-devel mailing list