Patchwork [4,of,9] bundle-ng: move gengroup into bundler

login
register
mail settings
Submitter Sune Foldager
Date Feb. 14, 2013, 7:40 p.m.
Message ID <1107b6c3ba5652700eca.1360870814@firefly.edlund.dk>
Download mbox | patch
Permalink /patch/988/
State Superseded
Headers show

Comments

Sune Foldager - Feb. 14, 2013, 7:40 p.m.
# HG changeset patch
# User Sune Foldager <cryo@cyanite.org>
# Date 1360455164 -3600
# Node ID 1107b6c3ba5652700ecaa0184d00490f81d2b063
# Parent  ad5a6d13a57e28c75167facacc2811cefc014155
bundle-ng: move gengroup into bundler

Patch

diff -r ad5a6d13a57e -r 1107b6c3ba56 mercurial/changegroup.py
--- a/mercurial/changegroup.py	Sat Feb 09 23:42:03 2013 +0100
+++ b/mercurial/changegroup.py	Sun Feb 10 01:12:44 2013 +0100
@@ -6,7 +6,7 @@ 
 # GNU General Public License version 2 or any later version.
 
 from i18n import _
-from node import nullrev
+from node import nullrev, hex
 import mdiff, util, dagutil
 import struct, os, bz2, zlib, tempfile
 
@@ -225,11 +225,24 @@ 
 
 class bundle10(object):
     deltaheader = _BUNDLE10_DELTA_HEADER
-    def __init__(self, bundlecaps=None):
+    def __init__(self, bundlecaps=None, repo=None):
         # Set of capabilities we can use to build the bundle.
         if bundlecaps is None:
             bundlecaps = set()
         self._bundlecaps = bundlecaps
+        if repo is not None:
+            self._changelog = repo.changelog
+            self._manifest = repo.manifest
+            reorder = repo.ui.config('bundle', 'reorder', 'auto')
+            if reorder == 'auto':
+                reorder = None
+            else:
+                reorder = util.parsebool(reorder)
+        else:
+            reorder = False
+        self._repo = repo
+        self._reorder = reorder
+        self.count = [0, 0]
     def start(self, lookup):
         self._lookup = lookup
     def close(self):
@@ -276,6 +289,43 @@ 
 
         yield self.close()
 
+    def generate(self, clnodes, getmfnodes, getfiles, getfilenodes, source):
+        '''yield a sequence of changegroup chunks (strings)'''
+        repo = self._repo
+        cl = self._changelog
+        mf = self._manifest
+        reorder = self._reorder
+        progress = repo.ui.progress
+        count = self.count
+        _bundling = _('bundling')
+
+        count[:] = [0, len(clnodes)]
+        for chunk in self.group(clnodes, cl, reorder=reorder):
+            yield chunk
+        progress(_bundling, None)
+
+        for chunk in self.group(getmfnodes(), mf, reorder=reorder):
+            yield chunk
+        progress(_bundling, None)
+
+        changedfiles = getfiles()
+        count[:] = [0, len(changedfiles)]
+        for fname in sorted(changedfiles):
+            filerevlog = repo.file(fname)
+            if not len(filerevlog):
+                raise util.Abort(_("empty or missing revlog for %s")
+                                 % fname)
+            nodelist = getfilenodes(fname, filerevlog)
+            if nodelist:
+                count[0] += 1
+                yield self.fileheader(fname)
+                for chunk in self.group(nodelist, filerevlog, reorder):
+                    yield chunk
+        yield self.close()
+        progress(_bundling, None)
+
+        if clnodes:
+            repo.hook('outgoing', node=hex(clnodes[0]), source=source)
 
     def revchunk(self, revlog, rev, prev):
         node = revlog.node(rev)