[PATCH 3 of 4 V2] changegroup: refactor addchangegroup to do files in a seperate function

Augie Fackler raf at durin42.com
Tue May 7 10:28:26 CDT 2013


On Mon, May 06, 2013 at 08:14:49PM -0700, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham at fb.com>
> # Date 1367430651 25200
> #      Wed May 01 10:50:51 2013 -0700
> # Node ID dbdfdfcc9b14728cee940dd9f96398561bed0802
> # Parent  9557401c5bab0a37d2e6eceb1fd13c66a75463f0
> 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.

This strikes me as a little bit of a bummer, because in abstract I'd
like to see the notion of a filelog hidden from localrepo so that you
could have a RepositoryStore that wasn't at all revlog backed, but
this certainly isn't worse than what we have.

>
> 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:
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list