Patchwork [7,of,8] changegroup: refactor addchangegroup to do files in a seperate function

login
register
mail settings
Submitter Durham Goode
Date May 6, 2013, 7:36 p.m.
Message ID <458839210a11d4add9bf.1367869017@dev350.prn1.facebook.com>
Download mbox | patch
Permalink /patch/1563/
State Superseded, archived
Headers show

Comments

Durham Goode - May 6, 2013, 7:36 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1367430651 25200
#      Wed May 01 10:50:51 2013 -0700
# Node ID 458839210a11d4add9bf077318f357e19d6d9810
# Parent  db6c92c7889d32205be64ac43f5cba35f28850f2
changegroup: refactor addchangegroup to do files in a seperate function

This moves the filelog portion of addchangegroup to a separate function.
This allows extensions to override just the file portion of addchangegroup.
For example, if an extension allows a repo to not have all of the file history
this wrap point lets it change how the repo accepts incoming file revisions.

No logic is changed in this commit.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -2318,41 +2318,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:
@@ -2432,6 +2401,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: