##// END OF EJS Templates
phase: add a dedicated pretxnclose-phase hook...
Boris Feld -
r34712:f6d17075 default
parent child Browse files
Show More
@@ -1002,6 +1002,17 be ``$HG_HOOKTYPE=incoming`` and ``$HG_H
1002 ``$HG_TXNNAME``, and a unique identifier for the transaction will be in
1002 ``$HG_TXNNAME``, and a unique identifier for the transaction will be in
1003 ``HG_TXNID``.
1003 ``HG_TXNID``.
1004
1004
1005 ``pretxnclose-phase``
1006 Run right before a phase change is actually finalized. Any repository change
1007 will be visible to the hook program. This lets you validate the transaction
1008 content or change it. Exit status 0 allows the commit to proceed. A non-zero
1009 status will cause the transaction to be rolled back.
1010 The affected node is available in ``$HG_NODE``, the phase in ``$HG_PHASE``
1011 while the previous ``$HG_OLDPHASE``. In case of new node, ``$HG_OLDPHASE``
1012 will be empty. In addition, the reason for the transaction opening will be in
1013 ``$HG_TXNNAME``, and a unique identifier for the transaction will be in
1014 ``HG_TXNID``.
1015
1005 ``txnclose``
1016 ``txnclose``
1006 Run after any repository transaction has been committed. At this
1017 Run after any repository transaction has been committed. At this
1007 point, the transaction can no longer be rolled back. The hook will run
1018 point, the transaction can no longer be rolled back. The hook will run
@@ -1017,12 +1028,8 be ``$HG_HOOKTYPE=incoming`` and ``$HG_H
1017 ``txnclose-phase``
1028 ``txnclose-phase``
1018 Run after any phase change has been committed. At this point, the
1029 Run after any phase change has been committed. At this point, the
1019 transaction can no longer be rolled back. The hook will run after the lock
1030 transaction can no longer be rolled back. The hook will run after the lock
1020 is released.
1031 is released. See :hg:`help config.hooks.pretxnclose-phase` for details about
1021 The affected node is available in ``$HG_NODE``, the new phase will be
1032 available variables.
1022 available in ``$HG_PHASE`` while the previous phase will be available in
1023 ``$HG_OLDPHASE``. In case of new node, ``$HG_OLDPHASE`` will be empty. In
1024 addition, the reason for the transaction opening will be in ``$HG_TXNNAME``,
1025 and a unique identifier for the transaction will be in ``HG_TXNID``.
1026
1033
1027 ``txnabort``
1034 ``txnabort``
1028 Run when a transaction is aborted. See :hg:`help config.hooks.pretxnclose`
1035 Run when a transaction is aborted. See :hg:`help config.hooks.pretxnclose`
@@ -1243,6 +1243,14 class localrepository(object):
1243 repo.hook('pretxnclose-bookmark', throw=True,
1243 repo.hook('pretxnclose-bookmark', throw=True,
1244 txnname=desc,
1244 txnname=desc,
1245 **pycompat.strkwargs(args))
1245 **pycompat.strkwargs(args))
1246 if hook.hashook(repo.ui, 'pretxnclose-phase'):
1247 cl = repo.unfiltered().changelog
1248 for rev, (old, new) in tr.changes['phases'].items():
1249 args = tr.hookargs.copy()
1250 node = hex(cl.node(rev))
1251 args.update(phases.preparehookargs(node, old, new))
1252 repo.hook('pretxnclose-phase', throw=True, txnname=desc,
1253 **pycompat.strkwargs(args))
1246
1254
1247 repo.hook('pretxnclose', throw=True,
1255 repo.hook('pretxnclose', throw=True,
1248 txnname=desc, **pycompat.strkwargs(tr.hookargs))
1256 txnname=desc, **pycompat.strkwargs(tr.hookargs))
@@ -732,3 +732,94 repositories visible to an external hook
732 rollback completed
732 rollback completed
733 abort: pretxnclose hook exited with status 1
733 abort: pretxnclose hook exited with status 1
734 [255]
734 [255]
735
736 Check that pretxnclose-phase hook can control phase movement
737
738 $ hg phase --force b3325c91a4d9 --secret
739 test-debug-phase: move rev 3: 0 -> 2
740 test-debug-phase: move rev 4: 0 -> 2
741 test-debug-phase: move rev 5: 1 -> 2
742 test-debug-phase: move rev 7: 0 -> 2
743 test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e: 0 -> 2
744 test-hook-close-phase: a603bfb5a83e312131cebcd05353c217d4d21dde: 0 -> 2
745 test-hook-close-phase: a030c6be5127abc010fcbff1851536552e6951a8: 1 -> 2
746 test-hook-close-phase: 17a481b3bccb796c0521ae97903d81c52bfee4af: 0 -> 2
747 $ hg log -G -T phases
748 @ changeset: 7:17a481b3bccb
749 |\ tag: tip
750 | | phase: secret
751 | | parent: 6:cf9fe039dfd6
752 | | parent: 4:a603bfb5a83e
753 | | user: test
754 | | date: Thu Jan 01 00:00:00 1970 +0000
755 | | summary: merge B' and E
756 | |
757 | o changeset: 6:cf9fe039dfd6
758 | | phase: public
759 | | parent: 1:27547f69f254
760 | | user: test
761 | | date: Thu Jan 01 00:00:00 1970 +0000
762 | | summary: B'
763 | |
764 o | changeset: 4:a603bfb5a83e
765 | | phase: secret
766 | | user: test
767 | | date: Thu Jan 01 00:00:00 1970 +0000
768 | | summary: E
769 | |
770 o | changeset: 3:b3325c91a4d9
771 | | phase: secret
772 | | user: test
773 | | date: Thu Jan 01 00:00:00 1970 +0000
774 | | summary: D
775 | |
776 o | changeset: 2:f838bfaca5c7
777 |/ phase: public
778 | user: test
779 | date: Thu Jan 01 00:00:00 1970 +0000
780 | summary: C
781 |
782 o changeset: 1:27547f69f254
783 | phase: public
784 | user: test
785 | date: Thu Jan 01 00:00:00 1970 +0000
786 | summary: B
787 |
788 o changeset: 0:4a2df7238c3b
789 phase: public
790 user: test
791 date: Thu Jan 01 00:00:00 1970 +0000
792 summary: A
793
794
795 Install a hook that prevent b3325c91a4d9 to become public
796
797 $ cat >> .hg/hgrc << EOF
798 > [hooks]
799 > pretxnclose-phase.nopublish_D = (echo \$HG_NODE| grep -v b3325c91a4d9>/dev/null) || [ 0 -lt \$HG_PHASE ]
800 > EOF
801
802 Try various actions. only the draft move should succeed
803
804 $ hg phase --public b3325c91a4d9
805 transaction abort!
806 rollback completed
807 abort: pretxnclose-phase.nopublish_D hook exited with status 1
808 [255]
809 $ hg phase --public a603bfb5a83e
810 transaction abort!
811 rollback completed
812 abort: pretxnclose-phase.nopublish_D hook exited with status 1
813 [255]
814 $ hg phase --draft 17a481b3bccb
815 test-debug-phase: move rev 3: 2 -> 1
816 test-debug-phase: move rev 4: 2 -> 1
817 test-debug-phase: move rev 7: 2 -> 1
818 test-hook-close-phase: b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e: 2 -> 1
819 test-hook-close-phase: a603bfb5a83e312131cebcd05353c217d4d21dde: 2 -> 1
820 test-hook-close-phase: 17a481b3bccb796c0521ae97903d81c52bfee4af: 2 -> 1
821 $ hg phase --public 17a481b3bccb
822 transaction abort!
823 rollback completed
824 abort: pretxnclose-phase.nopublish_D hook exited with status 1
825 [255]
General Comments 0
You need to be logged in to leave comments. Login now