Patchwork [3,of,4] localrepo: move the addchangegroupfiles method in changegroup module

login
register
mail settings
Submitter Pierre-Yves David
Date April 3, 2014, 5:45 p.m.
Message ID <b0211a6be1866eeaed28.1396547114@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4209/
State Accepted
Commit 0ac83e4e4f7c5e5fe3fde9b1f91359be66ed72c3
Headers show

Comments

Pierre-Yves David - April 3, 2014, 5:45 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1396390916 25200
#      Tue Apr 01 15:21:56 2014 -0700
# Node ID b0211a6be1866eeaed28de856df4ebacd415a2e8
# Parent  77914531a39fa05a5a2c2f9917dfe4ab1ca40261
localrepo: move the addchangegroupfiles method in changegroup module

This is a gratuitous code move aimed at reducing the localrepo bloatness.

The method had a single caller, far too few for being kept in local repo.

Patch

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -7,11 +7,11 @@ 
 
 from i18n import _
 from node import nullrev, nullid, hex
 import mdiff, util, dagutil
 import struct, os, bz2, zlib, tempfile
-import discovery
+import discovery, error
 
 _BUNDLE10_DELTA_HEADER = "20s20s20s20s"
 
 def readexactly(stream, n):
     '''read n bytes from stream.read and abort if less was available'''
@@ -513,5 +513,45 @@  def getbundle(repo, source, heads=None, 
 
 def changegroup(repo, basenodes, source):
     # to avoid a race we use changegroupsubset() (issue1320)
     return changegroupsubset(repo, basenodes, repo.heads(), source)
 
+def addchangegroupfiles(repo, source, revmap, trp, pr, needfiles):
+    revisions = 0
+    files = 0
+    while True:
+        chunkdata = source.filelogheader()
+        if not chunkdata:
+            break
+        f = chunkdata["filename"]
+        repo.ui.debug("adding %s revisions\n" % f)
+        pr()
+        fl = repo.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]
+    repo.ui.progress(_('files'), None)
+
+    for f, needs in needfiles.iteritems():
+        fl = repo.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
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1773,12 +1773,16 @@  class localrepository(object):
             pr.step = _('files')
             pr.count = 1
             pr.total = efiles
             source.callback = None
 
-            newrevs, newfiles = self.addchangegroupfiles(source, revmap, trp,
-                                                         pr, needfiles)
+            newrevs, newfiles = changegroup.addchangegroupfiles(self,
+                                                                source,
+                                                                revmap,
+                                                                trp,
+                                                                pr,
+                                                                needfiles)
             revisions += newrevs
             files += newfiles
 
             dh = 0
             if oldheads:
@@ -1862,50 +1866,10 @@  class localrepository(object):
         if dh < 0:
             return dh - 1
         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:
             # Save remote branchmap. We will use it later