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

login
register
mail settings
Submitter Martin von Zweigbergk
Date Jan. 13, 2016, 6:09 p.m.
Message ID <42af0ccdbc9ededd770e.1452708582@waste.org>
Download mbox | patch
Permalink /patch/12751/
State Accepted
Headers show

Comments

Martin von Zweigbergk - Jan. 13, 2016, 6:09 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@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.
Augie Fackler - Jan. 13, 2016, 7:34 p.m.
On Wed, Jan 13, 2016 at 12:09:42PM -0600, Martin von Zweigbergk wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1452298378 28800
> #      Fri Jan 08 16:12:58 2016 -0800
> # Node ID 42af0ccdbc9ededd770e35f3f7243dbc81ac98df
> # Parent  12f845942d02e226575a9185cda3b2ede378fe46
> changegroup3: move treemanifest support into _unpackmanifests()

queued these. In hindsight this new format should have been behind a
flag all along. Sigh.

>
> 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)):
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel

Patch

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)):