[PATCH 1 of 5] localrepo: add usercommitctx() wrapper

Greg Ward greg-hg at gerg.ca
Wed Jul 14 08:17:28 CDT 2010


On Tue, Jul 13, 2010 at 8:16 AM, Dan Villiom Podlaski Christiansen
<danchr at gmail.com> wrote:
> # HG changeset patch
> # User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
> # Date 1279022291 -7200
> # Node ID 84ae201bac7b69c5ea9148cfedb306db19c860f5
> # Parent  bb274fd59bf52843e916fa4971a7016c09e62a29
> localrepo: add usercommitctx() wrapper.
>
> This wrapper allows extensions to safely wrap commitctx() for
> user-initiated commits only.
>
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -890,7 +890,7 @@ class localrepository(repo.repository):
>             hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '')
>             try:
>                 self.hook("precommit", throw=True, parent1=hookp1, parent2=hookp2)
> -                ret = self.commitctx(cctx, True)
> +                ret = self.usercommitctx(cctx, True)
>             except:
>                 if edited:
>                     msgfn = self.pathto(msgfile.name[len(self.root)+1:])
> @@ -911,9 +911,23 @@ class localrepository(repo.repository):
>         self.hook("commit", node=hex(ret), parent1=hookp1, parent2=hookp2)
>         return ret
>
> +    def usercommitctx(self, ctx, error=False):
> +        """
> +        Wrapper for commitctx() method indicating a user-initiated commit.
> +
> +        This method is primarily intended for wrapping or specializing.
> +        Extensions can safely wrap it, without interfering with other uses of
> +        commitctx(), such as for conversion extensions.
> +        """
> +        return self.commitctx(ctx, error)
> +
>     def commitctx(self, ctx, error=False):
>         """Add a new revision to current repository.
>         Revision information is passed via the context argument.
> +
> +        Please note that this method shouldn't be wrapped or specialized by
> +        extensions. This method may be used part of a conversion where it's
> +        important that `ctx' is committed to the repository as-is.
>         """

Good idea, but I'm not sure it's completely safe for stable.  All of a
sudden my extensions that work with 1.6 will be breaking the
documented rules.  They'll still *work*, but in a narrow-minded
pinheaded bureaucratic sense, they will suddenly become "wrong".

Also, it means that there could exist extensions that work with
Mercurial 1.6.1 but not with 1.6.

But I'm just being conservative.  It looks like a great idea.

Greg


More information about the Mercurial-devel mailing list