[PATCH] memctx: allow the memctx to reuse the manifest node

Augie Fackler raf at durin42.com
Thu Nov 17 10:29:03 EST 2016


On Wed, Nov 16, 2016 at 08:15:28PM +0000, Mateusz Kwapich wrote:
> # HG changeset patch
> # User Mateusz Kwapich <mitrandir at fb.com>
> # Date 1479327311 0
> #      Wed Nov 16 20:15:11 2016 +0000
> # Node ID 0fd8175aa4e8a3a0cd6f637b34bfa25a103c454e
> # Parent  c27614f2dec1405db606d1ef871dfabf72cc0737
> memctx: allow the memctx to reuse the manifest node
>
> When we have a lot of files writing a new manifest revision can be expensive.
> This commit adds a possibility for memctx to reuse a manifest from a different
> commit. This can be beneficial for commands that are creating metadata changes
> without any actual files changed like "hg metaedit" in evolve extension.
>
> I will send the change for evolve that leverages this once this is accepted.
>
> diff --git a/mercurial/context.py b/mercurial/context.py
> --- a/mercurial/context.py
> +++ b/mercurial/context.py
> @@ -1160,6 +1160,7 @@
>                   changes=None):
>          self._repo = repo
>          self._rev = None
> +        self._manifestnode = None
>          self._node = None
>          self._text = text
>          if date:
> @@ -1268,7 +1269,8 @@
>          return None
>
>      def manifestnode(self):
> -        return None
> +        return self._manifestnode
> +
>      def user(self):
>          return self._user or self._repo.ui.username()
>      def date(self):
> @@ -1833,11 +1835,12 @@
>      # this field to determine what to do in filectxfn.
>      _returnnoneformissingfiles = True
>
> -    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, editor=False, manifestnode=None):
>          super(memctx, self).__init__(repo, text, user, date, extra)
>          self._rev = None
>          self._node = None
> +        self._manifestnode = manifestnode
>          parents = [(p or nullid) for p in parents]
>          p1, p2 = parents
>          self._parents = [changectx(self._repo, p) for p in (p1, p2)]
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -1695,7 +1695,11 @@
>              tr = self.transaction("commit")
>              trp = weakref.proxy(tr)
>
> -            if ctx.files():
> +            if ctx.manifestnode():

As-is, this puts a very sharp edge on the API. Please add an assert
that the files list is empty if a manifestnode is passed in the ctor.

Thanks!

> +                # reuse an existing manifest revision
> +                mn = ctx.manifestnode()
> +                files = ctx.files()
> +            elif ctx.files():
>                  m1ctx = p1.manifestctx()
>                  m2ctx = p2.manifestctx()
>                  mctx = m1ctx.copy()
> _______________________________________________
> 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