[PATCH 3 of 4 V2] changegroup: move changegroup file adding to a separate function

Durham Goode durham at fb.com
Tue Jun 4 14:59:29 CDT 2013


# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1369967216 25200
#      Thu May 30 19:26:56 2013 -0700
# Node ID a1a98fba2858dab9aa58431f4e4991f3d91649ab
# Parent  63f78f1c82bbc55d73589a4efba50b5e320794d3
changegroup: move changegroup file adding to a separate function

Moving the logic that adds files to a changegroup to a different function
allows extensions to override it and customize the way filelogs are added
to changegroups.

No logic is changed.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -2143,41 +2143,10 @@
             pr.total = efiles
             source.callback = None
 
-            while True:
-                chunkdata = source.filelogheader()
-                if not chunkdata:
-                    break
-                f = chunkdata["filename"]
-                self.ui.debug("adding %s revisions\n" % f)
-                pr()
-                fl = self.file(f)
-                o = len(fl)
-                if not fl.addgroup(source, revmap, trp):
-                    raise util.Abort(_("received file revlog group is empty"))
-                revisions += len(fl) - o
-                files += 1
-                if f in needfiles:
-                    needs = needfiles[f]
-                    for new in xrange(o, len(fl)):
-                        n = fl.node(new)
-                        if n in needs:
-                            needs.remove(n)
-                        else:
-                            raise util.Abort(
-                                _("received spurious file revlog entry"))
-                    if not needs:
-                        del needfiles[f]
-            self.ui.progress(_('files'), None)
-
-            for f, needs in needfiles.iteritems():
-                fl = self.file(f)
-                for n in needs:
-                    try:
-                        fl.rev(n)
-                    except error.LookupError:
-                        raise util.Abort(
-                            _('missing file data for %s:%s - run hg verify') %
-                            (f, hex(n)))
+            newrevs, newfiles = self.addchangegroupfiles(source, revmap, trp,
+                                                         pr, needfiles)
+            revisions += newrevs
+            files += newfiles
 
             dh = 0
             if oldheads:
@@ -2257,6 +2226,47 @@
         else:
             return dh + 1
 
+    def addchangegroupfiles(self, source, revmap, trp, pr, needfiles):
+        revisions = 0
+        files = 0
+        while True:
+            chunkdata = source.filelogheader()
+            if not chunkdata:
+                break
+            f = chunkdata["filename"]
+            self.ui.debug("adding %s revisions\n" % f)
+            pr()
+            fl = self.file(f)
+            o = len(fl)
+            if not fl.addgroup(source, revmap, trp):
+                raise util.Abort(_("received file revlog group is empty"))
+            revisions += len(fl) - o
+            files += 1
+            if f in needfiles:
+                needs = needfiles[f]
+                for new in xrange(o, len(fl)):
+                    n = fl.node(new)
+                    if n in needs:
+                        needs.remove(n)
+                    else:
+                        raise util.Abort(
+                            _("received spurious file revlog entry"))
+                if not needs:
+                    del needfiles[f]
+        self.ui.progress(_('files'), None)
+
+        for f, needs in needfiles.iteritems():
+            fl = self.file(f)
+            for n in needs:
+                try:
+                    fl.rev(n)
+                except error.LookupError:
+                    raise util.Abort(
+                        _('missing file data for %s:%s - run hg verify') %
+                        (f, hex(n)))
+
+        return revisions, files
+
     def stream_in(self, remote, requirements):
         lock = self.lock()
         try:


More information about the Mercurial-devel mailing list