changeset 20932:0ac83e4e4f7c

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.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Tue, 01 Apr 2014 15:21:56 -0700
parents de60ca3a390e
children d3775db748a0
files mercurial/changegroup.py mercurial/localrepo.py
diffstat 2 files changed, 47 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/changegroup.py	Tue Apr 01 15:08:27 2014 -0700
+++ b/mercurial/changegroup.py	Tue Apr 01 15:21:56 2014 -0700
@@ -9,7 +9,7 @@
 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"
 
@@ -514,3 +514,43 @@
     # 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
--- a/mercurial/localrepo.py	Tue Apr 01 15:08:27 2014 -0700
+++ b/mercurial/localrepo.py	Tue Apr 01 15:21:56 2014 -0700
@@ -1775,8 +1775,12 @@
             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
 
@@ -1864,46 +1868,6 @@
         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()