Patchwork [2,of,2] bundle: move file chunk generation to it's own function

login
register
mail settings
Submitter Durham Goode
Date June 26, 2013, 12:52 a.m.
Message ID <545aed2798c0de5c8232.1372207949@dev350.prn1.facebook.com>
Download mbox | patch
Permalink /patch/1749/
State Accepted
Commit 95a49112e7abc3f3842ca5b74162f3c0d9ab4617
Delegated to: Kevin Bullock
Headers show

Comments

Durham Goode - June 26, 2013, 12:52 a.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1372191792 25200
#      Tue Jun 25 13:23:12 2013 -0700
# Node ID 545aed2798c0de5c82323504f276f51e456ac5e0
# Parent  f63c47a0e5fecc9e2d8825306da5f4585eed1f50
bundle: move file chunk generation to it's own function

Moves the file chunk generation part of bundle creation to it's own function.
This allows extensions to customize the filelog part of bundle generation.

Patch

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -354,14 +354,8 @@ 
         progress(msgbundling, None)
 
         mfs.clear()
-        total = len(changedfiles)
-        # for progress output
-        msgfiles = _('files')
-        for i, fname in enumerate(sorted(changedfiles)):
-            filerevlog = repo.file(fname)
-            if not filerevlog:
-                raise util.Abort(_("empty or missing revlog for %s") % fname)
 
+        def linknodes(filerevlog, fname):
             if fastpathlinkrev:
                 ln, llr = filerevlog.node, filerevlog.linkrev
                 needed = set(cl.rev(x) for x in clnodes)
@@ -371,8 +365,33 @@ 
                         if linkrev in needed:
                             yield filerevlog.node(r), cl.node(linkrev)
                 fnodes[fname] = dict(genfilenodes())
+            return fnodes.get(fname, {})
 
-            linkrevnodes = fnodes.pop(fname, {})
+        for chunk in self.generatefiles(changedfiles, linknodes, commonrevs,
+                                        source):
+            yield chunk
+
+        yield self.close()
+        progress(msgbundling, None)
+
+        if clnodes:
+            repo.hook('outgoing', node=hex(clnodes[0]), source=source)
+
+    def generatefiles(self, changedfiles, linknodes, commonrevs, source):
+        repo = self._repo
+        progress = self._progress
+        reorder = self._reorder
+        msgbundling = _('bundling')
+
+        total = len(changedfiles)
+        # for progress output
+        msgfiles = _('files')
+        for i, fname in enumerate(sorted(changedfiles)):
+            filerevlog = repo.file(fname)
+            if not filerevlog:
+                raise util.Abort(_("empty or missing revlog for %s") % fname)
+
+            linkrevnodes = linknodes(filerevlog, fname)
             # Lookup for filenodes, we collected the linkrev nodes above in the
             # fastpath case and with lookupmf in the slowpath case.
             def lookupfilelog(x):
@@ -386,11 +405,6 @@ 
                 for chunk in self.group(filenodes, filerevlog, lookupfilelog,
                                         reorder=reorder):
                     yield chunk
-        yield self.close()
-        progress(msgbundling, None)
-
-        if clnodes:
-            repo.hook('outgoing', node=hex(clnodes[0]), source=source)
 
     def revchunk(self, revlog, rev, prev, linknode):
         node = revlog.node(rev)