[PATCH 3 of 5] bookmark: add a dedicated pretxnclose-bookmark hook
Denis Laxalde
denis at laxalde.org
Mon Oct 9 15:07:17 EDT 2017
Boris Feld a écrit :
> # HG changeset patch
> # User Boris Feld <boris.feld at octobus.net>
> # Date 1507481414 -7200
> # Sun Oct 08 18:50:14 2017 +0200
> # Node ID c7b1a3b41823e4e4969e17feefaaede4c89fe48c
> # Parent 7a2a2f58094560b307ba7980904dd4fc0087eddb
> # EXP-Topic b2.phases.hooks
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> # hg pull https://bitbucket.org/octobus/mercurial-devel/ -r c7b1a3b41823
> bookmark: add a dedicated pretxnclose-bookmark hook
>
> This new hook mirror the newly introduced 'txnclose-bookmark' but can abort the
> transaction.
>
> diff -r 7a2a2f580945 -r c7b1a3b41823 mercurial/localrepo.py
> --- a/mercurial/localrepo.py Sun Oct 08 18:32:49 2017 +0200
> +++ b/mercurial/localrepo.py Sun Oct 08 18:50:14 2017 +0200
> @@ -1235,8 +1235,23 @@
> # This will have to be fixed before we remove the experimental
> # gating.
> tracktags(tr2)
> - reporef().hook('pretxnclose', throw=True,
> - txnname=desc, **pycompat.strkwargs(tr.hookargs))
> + repo = reporef()
> + if hook.hashook(repo.ui, 'pretxnclose-bookmark'):
> + for name, (old, new) in sorted(tr.changes['bookmarks'].items()):
> + if new is None:
> + new = ''
> + if old is None:
> + old = ''
> + args = tr.hookargs.copy()
> + args['bookmark'] = name
> + args['node'] = hex(new)
> + args['oldnode'] = hex(old)
> + repo.hook('pretxnclose-bookmark', throw=True,
> + txnname=desc,
> + **pycompat.strkwargs(args))
> +
> + repo.hook('pretxnclose', throw=True,
> + txnname=desc, **pycompat.strkwargs(tr.hookargs))
This code is very similar to the one added in the previous patch (only
the hook event changes). Maybe factor things out?
Same goes for "phase" hooks in next patches.
> def releasefn(tr, success):
> repo = reporef()
> if success:
More information about the Mercurial-devel
mailing list