Patchwork [4,of,5,V3] changegroup: refactor addchangegroup to do files in a seperate function

login
register
mail settings
Submitter Durham Goode
Date May 8, 2013, 11:24 p.m.
Message ID <62fe0920af1b247ea4df.1368055459@dev350.prn1.facebook.com>
Download mbox | patch
Permalink /patch/1599/
State Rejected, archived
Headers show

Comments

Durham Goode - May 8, 2013, 11:24 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1367430651 25200
#      Wed May 01 10:50:51 2013 -0700
# Node ID 62fe0920af1b247ea4df68398b92784f6efb6f25
# Parent  c5b0310e180cd2dc8a6f681b9df5ee877b35cbd6
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.
Matt Mackall - May 9, 2013, 10:18 p.m.
On Wed, 2013-05-08 at 16:24 -0700, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1367430651 25200
> #      Wed May 01 10:50:51 2013 -0700
> # Node ID 62fe0920af1b247ea4df68398b92784f6efb6f25
> # Parent  c5b0310e180cd2dc8a6f681b9df5ee877b35cbd6
> changegroup: refactor addchangegroup to do files in a seperate function

I've queued the first three patches. But there are three sets of patches
that want to fiddle with addchangegroup right now:

- the bundle2 work from Sune/Benoit that's waiting on some minor review
comments
- Pierre's move-it-to-a-different-file work that I pushed off to
post-2.6
- this

Please, talk to each other.

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: