##// END OF EJS Templates
hook: add a generic hook right before we commit a transaction...
Pierre-Yves David -
r24284:ff14b26f default
parent child Browse files
Show More
@@ -813,15 +813,23 b' variables it is passed are listed with n'
813 transaction will be in ``$HG_TXNNAME``. A non-zero status will
813 transaction will be in ``$HG_TXNNAME``. A non-zero status will
814 prevent the transaction from being opened.
814 prevent the transaction from being opened.
815
815
816 ``pretxnclose``
817 Run right before the transaction is actually finalized. Any
818 repository change will be visible to the hook program. This lets you
819 validate the transaction content or change it. Exit status 0 allows
820 the commit to proceed. Non-zero status will cause the transaction to
821 be rolled back. The reason for the transaction opening will be in
822 ``$HG_TXNNAME``. The rest of the available data will vary according
823 the transaction type. New changesets will add
824 ``$HG_NODE`` (id of the first added changeset), ``$HG_URL`` and
825 ``$HG_SOURCE`` variables, bookmarks and phases changes will set
826 ``HG_BOOKMARK_MOVED`` and ``HG_PHASES_MOVED`` to ``1``, etc.
827
816 ``txnclose``
828 ``txnclose``
817 Run after any repository transaction has been commited. At this
829 Run after any repository transaction has been commited. At this
818 point, the transaction can no longer be rolled back. The hook will run
830 point, the transaction can no longer be rolled back. The hook will run
819 after the lock is released. The reason for the transaction will
831 after the lock is released. see ``pretxnclose`` docs for details about
820 be in ``$HG_TXNNAME``. The rest of the available data will vary
832 available variables.
821 according the event that happened during the transaction. New changesets
822 will add ``$HG_NODE`` (id of the first added changeset), ``$HG_URL``
823 and ``$HG_SOURCE`` variables, bookmarks and phases changes will set
824 ``HG_BOOKMARK_MOVED`` and ``HG_PHASES_MOVED`` to ``1``, etc.
825
833
826 ``pretxnchangegroup``
834 ``pretxnchangegroup``
827 Run after a changegroup has been added via push, pull or unbundle,
835 Run after a changegroup has been added via push, pull or unbundle,
@@ -915,17 +915,24 b' class localrepository(object):'
915 renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()]
915 renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()]
916 rp = report and report or self.ui.warn
916 rp = report and report or self.ui.warn
917 vfsmap = {'plain': self.vfs} # root of .hg/
917 vfsmap = {'plain': self.vfs} # root of .hg/
918 tr = transaction.transaction(rp, self.svfs, vfsmap,
918 # we must avoid cyclic reference between repo and transaction.
919 reporef = weakref.ref(self)
920 def validate(tr):
921 """will run pre-closing hooks"""
922 pending = lambda: tr.writepending() and self.root or ""
923 reporef().hook('pretxnclose', throw=True, pending=pending,
924 xnname=desc)
925
926 tr = transaction.transaction(rp, self.sopener, vfsmap,
919 "journal",
927 "journal",
920 "undo",
928 "undo",
921 aftertrans(renames),
929 aftertrans(renames),
922 self.store.createmode)
930 self.store.createmode,
931 validator=validate)
923 # note: writing the fncache only during finalize mean that the file is
932 # note: writing the fncache only during finalize mean that the file is
924 # outdated when running hooks. As fncache is used for streaming clone,
933 # outdated when running hooks. As fncache is used for streaming clone,
925 # this is not expected to break anything that happen during the hooks.
934 # this is not expected to break anything that happen during the hooks.
926 tr.addfinalize('flush-fncache', self.store.write)
935 tr.addfinalize('flush-fncache', self.store.write)
927 # we must avoid cyclic reference between repo and transaction.
928 reporef = weakref.ref(self)
929 def txnclosehook(tr2):
936 def txnclosehook(tr2):
930 """To be run if transaction is successful, will schedule a hook run
937 """To be run if transaction is successful, will schedule a hook run
931 """
938 """
@@ -13,6 +13,7 b' commit hooks can see env vars'
13 > pre-cat = python "$TESTDIR/printenv.py" pre-cat
13 > pre-cat = python "$TESTDIR/printenv.py" pre-cat
14 > post-cat = python "$TESTDIR/printenv.py" post-cat
14 > post-cat = python "$TESTDIR/printenv.py" post-cat
15 > pretxnopen = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" pretxnopen"
15 > pretxnopen = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" pretxnopen"
16 > pretxnclose = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" pretxnclose"
16 > txnclose = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" txnclose"
17 > txnclose = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" txnclose"
17 > EOF
18 > EOF
18 $ echo a > a
19 $ echo a > a
@@ -22,6 +23,7 b' commit hooks can see env vars'
22 pretxnopen hook: HG_TXNNAME=commit
23 pretxnopen hook: HG_TXNNAME=commit
23 pretxncommit hook: HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PARENT1=0000000000000000000000000000000000000000 HG_PENDING=$TESTTMP/a
24 pretxncommit hook: HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PARENT1=0000000000000000000000000000000000000000 HG_PENDING=$TESTTMP/a
24 0:cb9a9f314b8b
25 0:cb9a9f314b8b
26 pretxnclose hook: HG_PENDING=$TESTTMP/a HG_XNNAME=commit
25 txnclose hook: HG_PHASES_MOVED=1 HG_TXNNAME=commit
27 txnclose hook: HG_PHASES_MOVED=1 HG_TXNNAME=commit
26 commit hook: HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PARENT1=0000000000000000000000000000000000000000
28 commit hook: HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PARENT1=0000000000000000000000000000000000000000
27 commit.b hook: HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PARENT1=0000000000000000000000000000000000000000
29 commit.b hook: HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PARENT1=0000000000000000000000000000000000000000
@@ -49,6 +51,7 b' pretxncommit and commit hooks can see bo'
49 pretxnopen hook: HG_TXNNAME=commit
51 pretxnopen hook: HG_TXNNAME=commit
50 pretxncommit hook: HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PENDING=$TESTTMP/a
52 pretxncommit hook: HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PENDING=$TESTTMP/a
51 1:ab228980c14d
53 1:ab228980c14d
54 pretxnclose hook: HG_PENDING=$TESTTMP/a HG_XNNAME=commit
52 txnclose hook: HG_TXNNAME=commit
55 txnclose hook: HG_TXNNAME=commit
53 commit hook: HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
56 commit hook: HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
54 commit.b hook: HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
57 commit.b hook: HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
@@ -61,6 +64,7 b' pretxncommit and commit hooks can see bo'
61 pretxnopen hook: HG_TXNNAME=commit
64 pretxnopen hook: HG_TXNNAME=commit
62 pretxncommit hook: HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PENDING=$TESTTMP/a
65 pretxncommit hook: HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PENDING=$TESTTMP/a
63 2:ee9deb46ab31
66 2:ee9deb46ab31
67 pretxnclose hook: HG_PENDING=$TESTTMP/a HG_XNNAME=commit
64 txnclose hook: HG_TXNNAME=commit
68 txnclose hook: HG_TXNNAME=commit
65 commit hook: HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
69 commit hook: HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
66 commit.b hook: HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
70 commit.b hook: HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
@@ -73,6 +77,7 b' pretxncommit and commit hooks can see bo'
73 pretxnopen hook: HG_TXNNAME=commit
77 pretxnopen hook: HG_TXNNAME=commit
74 pretxncommit hook: HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd HG_PENDING=$TESTTMP/a
78 pretxncommit hook: HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd HG_PENDING=$TESTTMP/a
75 3:07f3376c1e65
79 3:07f3376c1e65
80 pretxnclose hook: HG_PENDING=$TESTTMP/a HG_XNNAME=commit
76 txnclose hook: HG_TXNNAME=commit
81 txnclose hook: HG_TXNNAME=commit
77 commit hook: HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd
82 commit hook: HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd
78 commit.b hook: HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd
83 commit.b hook: HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd
@@ -116,6 +121,7 b' tag hooks can see env vars'
116 pretxnopen hook: HG_TXNNAME=commit
121 pretxnopen hook: HG_TXNNAME=commit
117 pretxncommit hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PENDING=$TESTTMP/a
122 pretxncommit hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PENDING=$TESTTMP/a
118 4:539e4b31b6dc
123 4:539e4b31b6dc
124 pretxnclose hook: HG_PENDING=$TESTTMP/a HG_XNNAME=commit
119 tag hook: HG_LOCAL=0 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_TAG=a
125 tag hook: HG_LOCAL=0 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_TAG=a
120 txnclose hook: HG_TXNNAME=commit
126 txnclose hook: HG_TXNNAME=commit
121 commit hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2
127 commit hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2
@@ -212,6 +218,7 b' pushkey hook'
212 searching for changes
218 searching for changes
213 no changes found
219 no changes found
214 pretxnopen hook: HG_TXNNAME=bookmarks
220 pretxnopen hook: HG_TXNNAME=bookmarks
221 pretxnclose hook: HG_PENDING=$TESTTMP/a HG_XNNAME=bookmarks
215 txnclose hook: HG_BOOKMARK_MOVED=1 HG_TXNNAME=bookmarks
222 txnclose hook: HG_BOOKMARK_MOVED=1 HG_TXNNAME=bookmarks
216 pushkey hook: HG_KEY=foo HG_NAMESPACE=bookmarks HG_NEW=0000000000000000000000000000000000000000 HG_RET=1
223 pushkey hook: HG_KEY=foo HG_NAMESPACE=bookmarks HG_NEW=0000000000000000000000000000000000000000 HG_RET=1
217 exporting bookmark foo
224 exporting bookmark foo
General Comments 0
You need to be logged in to leave comments. Login now