Show More
@@ -846,3 +846,12 b' def printbookmarks(ui, repo, **opts):' | |||||
846 |
|
846 | |||
847 | bmarks[bmark] = (n, prefix, label) |
|
847 | bmarks[bmark] = (n, prefix, label) | |
848 | _printbookmarks(ui, repo, bmarks, **opts) |
|
848 | _printbookmarks(ui, repo, bmarks, **opts) | |
|
849 | ||||
|
850 | def preparehookargs(name, old, new): | |||
|
851 | if new is None: | |||
|
852 | new = '' | |||
|
853 | if old is None: | |||
|
854 | old = '' | |||
|
855 | return {'bookmark': name, | |||
|
856 | 'node': hex(new), | |||
|
857 | 'oldnode': hex(old)} |
@@ -994,6 +994,18 b' be ``$HG_HOOKTYPE=incoming`` and ``$HG_H' | |||||
994 | after the lock is released. See :hg:`help config.hooks.pretxnclose` for |
|
994 | after the lock is released. See :hg:`help config.hooks.pretxnclose` for | |
995 | details about available variables. |
|
995 | details about available variables. | |
996 |
|
996 | |||
|
997 | ``txnclose-bookmark`` | |||
|
998 | Run after any bookmark change has been committed. At this point, the | |||
|
999 | transaction can no longer be rolled back. The hook will run after the lock | |||
|
1000 | is released. | |||
|
1001 | The name of the bookmark will be available in ``$HG_BOOKMARK``, the new | |||
|
1002 | bookmark location will be available in ``$HG_NODE`` while the previous | |||
|
1003 | location will be available in ``$HG_OLDNODE``. In case of a bookmark | |||
|
1004 | creation ``$HG_OLDNODE`` will be empty. In case of deletion ``$HG_NODE`` | |||
|
1005 | will be empty. In addition, the reason for the transaction opening will be | |||
|
1006 | in ``$HG_TXNNAME``, and a unique identifier for the transaction will be in | |||
|
1007 | ``HG_TXNID``. | |||
|
1008 | ||||
997 | ``txnabort`` |
|
1009 | ``txnabort`` | |
998 | Run when a transaction is aborted. See :hg:`help config.hooks.pretxnclose` |
|
1010 | Run when a transaction is aborted. See :hg:`help config.hooks.pretxnclose` | |
999 | for details about available variables. |
|
1011 | for details about available variables. |
@@ -1280,10 +1280,19 b' class localrepository(object):' | |||||
1280 | # fixes the function accumulation. |
|
1280 | # fixes the function accumulation. | |
1281 | hookargs = tr2.hookargs |
|
1281 | hookargs = tr2.hookargs | |
1282 |
|
1282 | |||
1283 | def hook(): |
|
1283 | def hookfunc(): | |
1284 | reporef().hook('txnclose', throw=False, txnname=desc, |
|
1284 | repo = reporef() | |
1285 | **pycompat.strkwargs(hookargs)) |
|
1285 | if hook.hashook(repo.ui, 'txnclose-bookmark'): | |
1286 | reporef()._afterlock(hook) |
|
1286 | bmchanges = sorted(tr.changes['bookmarks'].items()) | |
|
1287 | for name, (old, new) in bmchanges: | |||
|
1288 | args = tr.hookargs.copy() | |||
|
1289 | args.update(bookmarks.preparehookargs(name, old, new)) | |||
|
1290 | repo.hook('txnclose-bookmark', throw=False, | |||
|
1291 | txnname=desc, **pycompat.strkwargs(args)) | |||
|
1292 | ||||
|
1293 | repo.hook('txnclose', throw=False, txnname=desc, | |||
|
1294 | **pycompat.strkwargs(hookargs)) | |||
|
1295 | reporef()._afterlock(hookfunc) | |||
1287 | tr.addfinalize('txnclose-hook', txnclosehook) |
|
1296 | tr.addfinalize('txnclose-hook', txnclosehook) | |
1288 | tr.addpostclose('warms-cache', self._buildcacheupdater(tr)) |
|
1297 | tr.addpostclose('warms-cache', self._buildcacheupdater(tr)) | |
1289 | def txnaborthook(tr2): |
|
1298 | def txnaborthook(tr2): |
@@ -9,6 +9,8 b'' | |||||
9 | > stabilization=createmarkers,exchange |
|
9 | > stabilization=createmarkers,exchange | |
10 | > EOF |
|
10 | > EOF | |
11 |
|
11 | |||
|
12 | $ TESTHOOK='hooks.txnclose-bookmark.test=echo "test-hook-bookmark: $HG_BOOKMARK: $HG_OLDNODE -> $HG_NODE"' | |||
|
13 | ||||
12 | initialize |
|
14 | initialize | |
13 |
|
15 | |||
14 | $ hg init a |
|
16 | $ hg init a | |
@@ -30,7 +32,7 b' import bookmark by name' | |||||
30 | $ hg book Y |
|
32 | $ hg book Y | |
31 | $ hg book |
|
33 | $ hg book | |
32 | * Y -1:000000000000 |
|
34 | * Y -1:000000000000 | |
33 | $ hg pull ../a |
|
35 | $ hg pull ../a --config "$TESTHOOK" | |
34 | pulling from ../a |
|
36 | pulling from ../a | |
35 | requesting all changes |
|
37 | requesting all changes | |
36 | adding changesets |
|
38 | adding changesets | |
@@ -41,6 +43,9 b' import bookmark by name' | |||||
41 | updating bookmark Y |
|
43 | updating bookmark Y | |
42 | adding remote bookmark Z |
|
44 | adding remote bookmark Z | |
43 | new changesets 4e3505fd9583 |
|
45 | new changesets 4e3505fd9583 | |
|
46 | test-hook-bookmark: X: -> 4e3505fd95835d721066b76e75dbb8cc554d7f77 | |||
|
47 | test-hook-bookmark: Y: 0000000000000000000000000000000000000000 -> 4e3505fd95835d721066b76e75dbb8cc554d7f77 | |||
|
48 | test-hook-bookmark: Z: -> 4e3505fd95835d721066b76e75dbb8cc554d7f77 | |||
44 | (run 'hg update' to get a working copy) |
|
49 | (run 'hg update' to get a working copy) | |
45 | $ hg bookmarks |
|
50 | $ hg bookmarks | |
46 | X 0:4e3505fd9583 |
|
51 | X 0:4e3505fd9583 | |
@@ -94,10 +99,11 b' export bookmark by name' | |||||
94 | delete a remote bookmark |
|
99 | delete a remote bookmark | |
95 |
|
100 | |||
96 | $ hg book -d W |
|
101 | $ hg book -d W | |
97 | $ hg push -B W ../a |
|
102 | $ hg push -B W ../a --config "$TESTHOOK" | |
98 | pushing to ../a |
|
103 | pushing to ../a | |
99 | searching for changes |
|
104 | searching for changes | |
100 | no changes found |
|
105 | no changes found | |
|
106 | test-hook-bookmark: W: 0000000000000000000000000000000000000000 -> | |||
101 | deleting remote bookmark W |
|
107 | deleting remote bookmark W | |
102 | [1] |
|
108 | [1] | |
103 |
|
109 | |||
@@ -165,7 +171,7 b' divergent bookmarks' | |||||
165 | Z 1:0d2164f0ce0d |
|
171 | Z 1:0d2164f0ce0d | |
166 |
|
172 | |||
167 | $ cd ../b |
|
173 | $ cd ../b | |
168 | $ hg up |
|
174 | $ hg up --config | |
169 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
175 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
170 | updating bookmark foobar |
|
176 | updating bookmark foobar | |
171 | $ echo c2 > f2 |
|
177 | $ echo c2 > f2 | |
@@ -181,7 +187,7 b' divergent bookmarks' | |||||
181 | foo -1:000000000000 |
|
187 | foo -1:000000000000 | |
182 | * foobar 1:9b140be10808 |
|
188 | * foobar 1:9b140be10808 | |
183 |
|
189 | |||
184 | $ hg pull --config paths.foo=../a foo |
|
190 | $ hg pull --config paths.foo=../a foo --config "$TESTHOOK" | |
185 | pulling from $TESTTMP/a (glob) |
|
191 | pulling from $TESTTMP/a (glob) | |
186 | searching for changes |
|
192 | searching for changes | |
187 | adding changesets |
|
193 | adding changesets | |
@@ -192,6 +198,9 b' divergent bookmarks' | |||||
192 | divergent bookmark X stored as X@foo |
|
198 | divergent bookmark X stored as X@foo | |
193 | updating bookmark Z |
|
199 | updating bookmark Z | |
194 | new changesets 0d2164f0ce0d |
|
200 | new changesets 0d2164f0ce0d | |
|
201 | test-hook-bookmark: @foo: -> 0d2164f0ce0d8f1d6f94351eba04b794909be66c | |||
|
202 | test-hook-bookmark: X@foo: -> 0d2164f0ce0d8f1d6f94351eba04b794909be66c | |||
|
203 | test-hook-bookmark: Z: 4e3505fd95835d721066b76e75dbb8cc554d7f77 -> 0d2164f0ce0d8f1d6f94351eba04b794909be66c | |||
195 | (run 'hg heads' to see heads, 'hg merge' to merge) |
|
204 | (run 'hg heads' to see heads, 'hg merge' to merge) | |
196 | $ hg book |
|
205 | $ hg book | |
197 | @ 1:9b140be10808 |
|
206 | @ 1:9b140be10808 | |
@@ -254,11 +263,13 b' explicit pull should overwrite the local' | |||||
254 | $ hg update -r X |
|
263 | $ hg update -r X | |
255 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
264 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
256 | (activating bookmark X) |
|
265 | (activating bookmark X) | |
257 | $ hg pull --config paths.foo=../a foo -B . |
|
266 | $ hg pull --config paths.foo=../a foo -B . --config "$TESTHOOK" | |
258 | pulling from $TESTTMP/a (glob) |
|
267 | pulling from $TESTTMP/a (glob) | |
259 | no changes found |
|
268 | no changes found | |
260 | divergent bookmark @ stored as @foo |
|
269 | divergent bookmark @ stored as @foo | |
261 | importing bookmark X |
|
270 | importing bookmark X | |
|
271 | test-hook-bookmark: @foo: 0d2164f0ce0d8f1d6f94351eba04b794909be66c -> 0d2164f0ce0d8f1d6f94351eba04b794909be66c | |||
|
272 | test-hook-bookmark: X: 9b140be1080824d768c5a4691a564088eede71f9 -> 0d2164f0ce0d8f1d6f94351eba04b794909be66c | |||
262 |
|
273 | |||
263 | reinstall state for further testing: |
|
274 | reinstall state for further testing: | |
264 |
|
275 | |||
@@ -283,13 +294,14 b' update a remote bookmark from a non-head' | |||||
283 | $ hg ci -Am3 |
|
294 | $ hg ci -Am3 | |
284 | adding f2 |
|
295 | adding f2 | |
285 | created new head |
|
296 | created new head | |
286 | $ hg push ../a |
|
297 | $ hg push ../a --config "$TESTHOOK" | |
287 | pushing to ../a |
|
298 | pushing to ../a | |
288 | searching for changes |
|
299 | searching for changes | |
289 | adding changesets |
|
300 | adding changesets | |
290 | adding manifests |
|
301 | adding manifests | |
291 | adding file changes |
|
302 | adding file changes | |
292 | added 1 changesets with 1 changes to 1 files (+1 heads) |
|
303 | added 1 changesets with 1 changes to 1 files (+1 heads) | |
|
304 | test-hook-bookmark: Y: 4e3505fd95835d721066b76e75dbb8cc554d7f77 -> f6fc62dde3c0771e29704af56ba4d8af77abcc2f | |||
293 | updating bookmark Y |
|
305 | updating bookmark Y | |
294 | $ hg -R ../a book |
|
306 | $ hg -R ../a book | |
295 | @ 1:0d2164f0ce0d |
|
307 | @ 1:0d2164f0ce0d | |
@@ -314,7 +326,11 b' race conditions' | |||||
314 | > echo committed in pull-race |
|
326 | > echo committed in pull-race | |
315 | > EOF |
|
327 | > EOF | |
316 |
|
328 | |||
317 | $ hg clone -q http://localhost:$HGPORT/ pull-race2 |
|
329 | $ hg clone -q http://localhost:$HGPORT/ pull-race2 --config "$TESTHOOK" | |
|
330 | test-hook-bookmark: @: -> 0d2164f0ce0d8f1d6f94351eba04b794909be66c | |||
|
331 | test-hook-bookmark: X: -> 0d2164f0ce0d8f1d6f94351eba04b794909be66c | |||
|
332 | test-hook-bookmark: Y: -> f6fc62dde3c0771e29704af56ba4d8af77abcc2f | |||
|
333 | test-hook-bookmark: Z: -> 0d2164f0ce0d8f1d6f94351eba04b794909be66c | |||
318 | $ cd pull-race |
|
334 | $ cd pull-race | |
319 | $ hg up -q Y |
|
335 | $ hg up -q Y | |
320 | $ echo c4 > f2 |
|
336 | $ echo c4 > f2 |
@@ -1,6 +1,9 b'' | |||||
|
1 | ||||
1 | $ hg init repo |
|
2 | $ hg init repo | |
2 | $ cd repo |
|
3 | $ cd repo | |
3 |
|
4 | |||
|
5 | $ TESTHOOK='hooks.txnclose-bookmark.test=echo "test-hook-bookmark: $HG_BOOKMARK: $HG_OLDNODE -> $HG_NODE"' | |||
|
6 | ||||
4 | no bookmarks |
|
7 | no bookmarks | |
5 |
|
8 | |||
6 | $ hg bookmarks |
|
9 | $ hg bookmarks | |
@@ -12,7 +15,8 b' no bookmarks' | |||||
12 |
|
15 | |||
13 | bookmark rev -1 |
|
16 | bookmark rev -1 | |
14 |
|
17 | |||
15 | $ hg bookmark X |
|
18 | $ hg bookmark X --config "$TESTHOOK" | |
|
19 | test-hook-bookmark: X: -> 0000000000000000000000000000000000000000 | |||
16 |
|
20 | |||
17 | list bookmarks |
|
21 | list bookmarks | |
18 |
|
22 | |||
@@ -27,7 +31,8 b' list bookmarks with color' | |||||
27 |
|
31 | |||
28 | $ echo a > a |
|
32 | $ echo a > a | |
29 | $ hg add a |
|
33 | $ hg add a | |
30 | $ hg commit -m 0 |
|
34 | $ hg commit -m 0 --config "$TESTHOOK" | |
|
35 | test-hook-bookmark: X: 0000000000000000000000000000000000000000 -> f7b1eb17ad24730a1651fccd46c43826d1bbc2ac | |||
31 |
|
36 | |||
32 | bookmark X moved to rev 0 |
|
37 | bookmark X moved to rev 0 | |
33 |
|
38 | |||
@@ -47,7 +52,8 b' look up bookmark' | |||||
47 |
|
52 | |||
48 | second bookmark for rev 0, command should work even with ui.strict on |
|
53 | second bookmark for rev 0, command should work even with ui.strict on | |
49 |
|
54 | |||
50 | $ hg --config ui.strict=1 bookmark X2 |
|
55 | $ hg --config ui.strict=1 bookmark X2 --config "$TESTHOOK" | |
|
56 | test-hook-bookmark: X2: -> f7b1eb17ad24730a1651fccd46c43826d1bbc2ac | |||
51 |
|
57 | |||
52 | bookmark rev -1 again |
|
58 | bookmark rev -1 again | |
53 |
|
59 | |||
@@ -62,7 +68,8 b' list bookmarks' | |||||
62 |
|
68 | |||
63 | $ echo b > b |
|
69 | $ echo b > b | |
64 | $ hg add b |
|
70 | $ hg add b | |
65 | $ hg commit -m 1 |
|
71 | $ hg commit -m 1 --config "$TESTHOOK" | |
|
72 | test-hook-bookmark: X2: f7b1eb17ad24730a1651fccd46c43826d1bbc2ac -> 925d80f479bb026b0fb3deb27503780b13f74123 | |||
66 |
|
73 | |||
67 |
$ |
|
74 | $ hg bookmarks -Tjson | |
68 | [ |
|
75 | [ | |
@@ -194,14 +201,17 b' force rename to existent bookmark' | |||||
194 | rename bookmark using . |
|
201 | rename bookmark using . | |
195 |
|
202 | |||
196 | $ hg book rename-me |
|
203 | $ hg book rename-me | |
197 | $ hg book -m . renamed |
|
204 | $ hg book -m . renamed --config "$TESTHOOK" | |
|
205 | test-hook-bookmark: rename-me: db815d6d32e69058eadefc8cffbad37675707975 -> | |||
|
206 | test-hook-bookmark: renamed: -> db815d6d32e69058eadefc8cffbad37675707975 | |||
198 | $ hg bookmark |
|
207 | $ hg bookmark | |
199 | X2 1:925d80f479bb |
|
208 | X2 1:925d80f479bb | |
200 | Y 2:db815d6d32e6 |
|
209 | Y 2:db815d6d32e6 | |
201 | Z 0:f7b1eb17ad24 |
|
210 | Z 0:f7b1eb17ad24 | |
202 | * renamed 2:db815d6d32e6 |
|
211 | * renamed 2:db815d6d32e6 | |
203 | $ hg up -q Y |
|
212 | $ hg up -q Y | |
204 | $ hg book -d renamed |
|
213 | $ hg book -d renamed --config "$TESTHOOK" | |
|
214 | test-hook-bookmark: renamed: db815d6d32e69058eadefc8cffbad37675707975 -> | |||
205 |
|
215 | |||
206 | rename bookmark using . with no active bookmark |
|
216 | rename bookmark using . with no active bookmark | |
207 |
|
217 | |||
@@ -354,11 +364,13 b' bookmark with integer name' | |||||
354 | [255] |
|
364 | [255] | |
355 |
|
365 | |||
356 | bookmark with a name that matches a node id |
|
366 | bookmark with a name that matches a node id | |
357 | $ hg bookmark 925d80f479bb db815d6d32e6 |
|
367 | $ hg bookmark 925d80f479bb db815d6d32e6 --config "$TESTHOOK" | |
358 | bookmark 925d80f479bb matches a changeset hash |
|
368 | bookmark 925d80f479bb matches a changeset hash | |
359 | (did you leave a -r out of an 'hg bookmark' command?) |
|
369 | (did you leave a -r out of an 'hg bookmark' command?) | |
360 | bookmark db815d6d32e6 matches a changeset hash |
|
370 | bookmark db815d6d32e6 matches a changeset hash | |
361 | (did you leave a -r out of an 'hg bookmark' command?) |
|
371 | (did you leave a -r out of an 'hg bookmark' command?) | |
|
372 | test-hook-bookmark: 925d80f479bb: -> db815d6d32e69058eadefc8cffbad37675707975 | |||
|
373 | test-hook-bookmark: db815d6d32e6: -> db815d6d32e69058eadefc8cffbad37675707975 | |||
362 | $ hg bookmark -d 925d80f479bb |
|
374 | $ hg bookmark -d 925d80f479bb | |
363 | $ hg bookmark -d db815d6d32e6 |
|
375 | $ hg bookmark -d db815d6d32e6 | |
364 |
|
376 | |||
@@ -406,7 +418,8 b' incompatible options' | |||||
406 |
|
418 | |||
407 | force bookmark with existing name |
|
419 | force bookmark with existing name | |
408 |
|
420 | |||
409 | $ hg bookmark -f X2 |
|
421 | $ hg bookmark -f X2 --config "$TESTHOOK" | |
|
422 | test-hook-bookmark: X2: 925d80f479bb026b0fb3deb27503780b13f74123 -> db815d6d32e69058eadefc8cffbad37675707975 | |||
410 |
|
423 | |||
411 | force bookmark back to where it was, should deactivate it |
|
424 | force bookmark back to where it was, should deactivate it | |
412 |
|
425 |
General Comments 0
You need to be logged in to leave comments.
Login now