Patchwork [1,of,4,reviewed,by,Augie] bundle2: lazily generate the changegroup part in exchange.getbundle

login
register
mail settings
Submitter Pierre-Yves David
Date April 12, 2014, 9:27 p.m.
Message ID <dda41da069a49b7dc68b.1397338039@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4299/
State Accepted
Headers show

Comments

Pierre-Yves David - April 12, 2014, 9:27 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1397329015 14400
#      Sat Apr 12 14:56:55 2014 -0400
# Node ID dda41da069a49b7dc68b7fe8d01c3b58ba315ff6
# Parent  c93bb6a08fa1e9bba6e3b38a368c5961b77f0ebe
bundle2: lazily generate the changegroup part in exchange.getbundle

Now that we have lazy generation of parts, let's use it.
Pierre-Yves David - May 7, 2014, 12:19 a.m.
On 04/12/2014 02:27 PM, pierre-yves.david@ens-lyon.org wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1397329015 14400
> #      Sat Apr 12 14:56:55 2014 -0400
> # Node ID dda41da069a49b7dc68b7fe8d01c3b58ba315ff6
> # Parent  c93bb6a08fa1e9bba6e3b38a368c5961b77f0ebe
> bundle2: lazily generate the changegroup part in exchange.getbundle

This series was Queued long time ago

(waving at augies review patchbot)

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -599,13 +599,15 @@  def getbundle(repo, source, heads=None, 
     if bundlecaps is None or 'HG20' not in bundlecaps:
         return cg
     # very crude first implementation,
     # the bundle API will change and the generation will be done lazily.
     bundler = bundle2.bundle20(repo.ui)
-    tempname = changegroup.writebundle(cg, None, 'HG10UN')
-    data = open(tempname).read()
-    part = bundle2.part('changegroup', data=data)
+    def cgchunks(cg=cg):
+        yield 'HG10UN'
+        for c in cg.getchunks():
+            yield c
+    part = bundle2.part('changegroup', data=cgchunks())
     bundler.addpart(part)
     temp = cStringIO.StringIO()
     for c in bundler.getchunks():
         temp.write(c)
     temp.seek(0)