[PATCH 1 of 3 ctx-cleanup] context: inline makememctx (API)

Augie Fackler raf at durin42.com
Thu Jun 1 14:23:27 UTC 2017


On Wed, May 31, 2017 at 05:22:06PM -0700, Sean Farley wrote:
> # HG changeset patch
> # User Sean Farley <sean at farley.io>
> # Date 1494536055 25200
> #      Thu May 11 13:54:15 2017 -0700
> # Branch wctxds
> # Node ID 9879720e90cf13e445d17fc22f53c071a22322d9
> # Parent  60b3e8946da728c377a3a6aadb785ae308084614
> context: inline makememctx (API)
>

[...]

> -    def __init__(self, repo, parents, text, files, filectxfn, user=None,
> -                 date=None, extra=None, editor=False):
> +    def __init__(self, repo, parents, text, files, filectxfn=None, user=None,
> +                 date=None, extra=None, branch=None, editor=False):
>          super(memctx, self).__init__(repo, text, user, date, extra)
>          self._rev = None
>          self._node = None
>          parents = [(p or nullid) for p in parents]
>          p1, p2 = parents
>          self._parents = [changectx(self._repo, p) for p in (p1, p2)]
>          files = sorted(set(files))
>          self._files = files
> +        if branch is not None:
> +            self._extra['branch'] = encoding.fromlocal(branch)
>          self.substate = {}
>
> -        # if store is not callable, wrap it in a function
> -        if not callable(filectxfn):
> +        if filectxfn is not None and isinstance(filectxfn, patch.filestore):
> +            def getfilectx(repo, memctx, path):

nit: I don't think this function need be nested. Could you send a
followup that moves it to be something like _defaultgetfilectx at
module level if I'm right?

> +                data, mode, copied = filectxfn.getfile(path)
> +                if data is None:
> +                    return None
> +                islink, isexec = mode
> +                return memfilectx(repo, path, data, islink=islink,
> +                                  isexec=isexec, copied=copied,
> +                                  memctx=memctx)
> +            self._filectxfn = getfilectx
> +        elif not callable(filectxfn):
> +            # if store is not callable, wrap it in a function
>              def getfilectx(repo, memctx, path):
>                  fctx = filectxfn[path]
>                  # this is weird but apparently we only keep track of one parent
>                  # (why not only store that instead of a tuple?)
>                  copied = fctx.renamed()
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list