##// END OF EJS Templates
track-tags: introduce first bits of tags tracking during transaction...
Pierre-Yves David -
r31994:b36318e6 default
parent child Browse files
Show More
@@ -1001,8 +1001,54 b' class localrepository(object):'
1001 vfsmap = {'plain': self.vfs} # root of .hg/
1001 vfsmap = {'plain': self.vfs} # root of .hg/
1002 # we must avoid cyclic reference between repo and transaction.
1002 # we must avoid cyclic reference between repo and transaction.
1003 reporef = weakref.ref(self)
1003 reporef = weakref.ref(self)
1004 def validate(tr):
1004 # Code to track tag movement
1005 #
1006 # Since tags are all handled as file content, it is actually quite hard
1007 # to track these movement from a code perspective. So we fallback to a
1008 # tracking at the repository level. One could envision to track changes
1009 # to the '.hgtags' file through changegroup apply but that fails to
1010 # cope with case where transaction expose new heads without changegroup
1011 # being involved (eg: phase movement).
1012 #
1013 # For now, We gate the feature behind a flag since this likely comes
1014 # with performance impacts. The current code run more often than needed
1015 # and do not use caches as much as it could. The current focus is on
1016 # the behavior of the feature so we disable it by default. The flag
1017 # will be removed when we are happy with the performance impact.
1018 tracktags = lambda x: None
1019 # experimental config: experimental.hook-track-tags
1020 shouldtracktags = self.ui.configbool('experimental', 'hook-track-tags',
1021 False)
1022 if desc != 'strip' and shouldtracktags:
1023 oldheads = self.changelog.headrevs()
1024 def tracktags(tr2):
1025 repo = reporef()
1026 oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads)
1027 newheads = repo.changelog.headrevs()
1028 newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads)
1029 # notes: we compare lists here.
1030 # As we do it only once buiding set would not be cheaper
1031 if oldfnodes != newfnodes:
1032 tr2.hookargs['tag_moved'] = '1'
1033 def validate(tr2):
1005 """will run pre-closing hooks"""
1034 """will run pre-closing hooks"""
1035 # XXX the transaction API is a bit lacking here so we take a hacky
1036 # path for now
1037 #
1038 # We cannot add this as a "pending" hooks since the 'tr.hookargs'
1039 # dict is copied before these run. In addition we needs the data
1040 # available to in memory hooks too.
1041 #
1042 # Moreover, we also need to make sure this runs before txnclose
1043 # hooks and there is no "pending" mechanism that would execute
1044 # logic only if hooks are about to run.
1045 #
1046 # Fixing this limitation of the transaction is also needed to track
1047 # other families of changes (bookmarks, phases, obsolescence).
1048 #
1049 # This will have to be fixed before we remove the experimental
1050 # gating.
1051 tracktags(tr2)
1006 reporef().hook('pretxnclose', throw=True,
1052 reporef().hook('pretxnclose', throw=True,
1007 txnname=desc, **pycompat.strkwargs(tr.hookargs))
1053 txnname=desc, **pycompat.strkwargs(tr.hookargs))
1008 def releasefn(tr, success):
1054 def releasefn(tr, success):
@@ -1,3 +1,19 b''
1 $ cat >> $HGRCPATH << EOF
2 > [experimental]
3 > hook-track-tags=1
4 > [hooks]
5 > txnclose.track-tag=${TESTTMP}/taghook.sh
6 > EOF
7
8 $ cat << EOF > taghook.sh
9 > #!/bin/sh
10 > # escape the "$" otherwise the test runner interpret it when writting the
11 > # file...
12 > if [ -n "\$HG_TAG_MOVED" ]; then
13 > echo 'hook: tag changes detected'
14 > fi
15 > EOF
16 $ chmod +x taghook.sh
1 $ hg init test
17 $ hg init test
2 $ cd test
18 $ cd test
3
19
@@ -20,6 +36,7 b''
20 specified)
36 specified)
21
37
22 $ HGEDITOR=cat hg tag "bleah"
38 $ HGEDITOR=cat hg tag "bleah"
39 hook: tag changes detected
23 $ hg history
40 $ hg history
24 changeset: 1:d4f0d2909abc
41 changeset: 1:d4f0d2909abc
25 tag: tip
42 tag: tip
@@ -68,10 +85,14 b' specified)'
68 [255]
85 [255]
69
86
70 $ hg tag -r 0 "bleah0"
87 $ hg tag -r 0 "bleah0"
88 hook: tag changes detected
71 $ hg tag -l -r 1 "bleah1"
89 $ hg tag -l -r 1 "bleah1"
72 $ hg tag gack gawk gorp
90 $ hg tag gack gawk gorp
91 hook: tag changes detected
73 $ hg tag -f gack
92 $ hg tag -f gack
93 hook: tag changes detected
74 $ hg tag --remove gack gorp
94 $ hg tag --remove gack gorp
95 hook: tag changes detected
75
96
76 $ hg tag "bleah "
97 $ hg tag "bleah "
77 abort: tag 'bleah' already exists (use -f to force)
98 abort: tag 'bleah' already exists (use -f to force)
@@ -83,7 +104,9 b' specified)'
83 abort: tag 'bleah' already exists (use -f to force)
104 abort: tag 'bleah' already exists (use -f to force)
84 [255]
105 [255]
85 $ hg tag -r 0 " bleahbleah "
106 $ hg tag -r 0 " bleahbleah "
107 hook: tag changes detected
86 $ hg tag -r 0 " bleah bleah "
108 $ hg tag -r 0 " bleah bleah "
109 hook: tag changes detected
87
110
88 $ cat .hgtags
111 $ cat .hgtags
89 acb14030fe0a21b60322c440ad2d20cf7685a376 bleah
112 acb14030fe0a21b60322c440ad2d20cf7685a376 bleah
@@ -112,6 +135,7 b' tagging on a non-head revision'
112 abort: working directory is not at a branch head (use -f to force)
135 abort: working directory is not at a branch head (use -f to force)
113 [255]
136 [255]
114 $ hg tag -f "foobar"
137 $ hg tag -f "foobar"
138 hook: tag changes detected
115 $ cat .hgtags
139 $ cat .hgtags
116 acb14030fe0a21b60322c440ad2d20cf7685a376 foobar
140 acb14030fe0a21b60322c440ad2d20cf7685a376 foobar
117 $ cat .hg/localtags
141 $ cat .hg/localtags
@@ -169,16 +193,19 b' cloning local tags'
169 summary: Removed tag gack, gorp
193 summary: Removed tag gack, gorp
170
194
171 $ hg clone -q -rbleah1 test test1
195 $ hg clone -q -rbleah1 test test1
196 hook: tag changes detected
172 $ hg -R test1 parents --style=compact
197 $ hg -R test1 parents --style=compact
173 1[tip] d4f0d2909abc 1970-01-01 00:00 +0000 test
198 1[tip] d4f0d2909abc 1970-01-01 00:00 +0000 test
174 Added tag bleah for changeset acb14030fe0a
199 Added tag bleah for changeset acb14030fe0a
175
200
176 $ hg clone -q -r5 test#bleah1 test2
201 $ hg clone -q -r5 test#bleah1 test2
202 hook: tag changes detected
177 $ hg -R test2 parents --style=compact
203 $ hg -R test2 parents --style=compact
178 5[tip] b4bb47aaff09 1970-01-01 00:00 +0000 test
204 5[tip] b4bb47aaff09 1970-01-01 00:00 +0000 test
179 Removed tag gack, gorp
205 Removed tag gack, gorp
180
206
181 $ hg clone -q -U test#bleah1 test3
207 $ hg clone -q -U test#bleah1 test3
208 hook: tag changes detected
182 $ hg -R test3 parents --style=compact
209 $ hg -R test3 parents --style=compact
183
210
184 $ cd test
211 $ cd test
@@ -203,9 +230,11 b" doesn't end with EOL"
203 > f = file('.hgtags', 'w'); f.write(last); f.close()
230 > f = file('.hgtags', 'w'); f.write(last); f.close()
204 > EOF
231 > EOF
205 $ hg ci -m'broken manual edit of .hgtags'
232 $ hg ci -m'broken manual edit of .hgtags'
233 hook: tag changes detected
206 $ cat .hgtags; echo
234 $ cat .hgtags; echo
207 acb14030fe0a21b60322c440ad2d20cf7685a376 foobar
235 acb14030fe0a21b60322c440ad2d20cf7685a376 foobar
208 $ hg tag newline
236 $ hg tag newline
237 hook: tag changes detected
209 $ cat .hgtags; echo
238 $ cat .hgtags; echo
210 acb14030fe0a21b60322c440ad2d20cf7685a376 foobar
239 acb14030fe0a21b60322c440ad2d20cf7685a376 foobar
211 a0eea09de1eeec777b46f2085260a373b2fbc293 newline
240 a0eea09de1eeec777b46f2085260a373b2fbc293 newline
@@ -219,6 +248,7 b' tag and branch using same name'
219 $ hg ci -m"discouraged"
248 $ hg ci -m"discouraged"
220 $ hg tag tag-and-branch-same-name
249 $ hg tag tag-and-branch-same-name
221 warning: tag tag-and-branch-same-name conflicts with existing branch name
250 warning: tag tag-and-branch-same-name conflicts with existing branch name
251 hook: tag changes detected
222
252
223 test custom commit messages
253 test custom commit messages
224
254
@@ -303,6 +333,7 b' then, test custom commit message itself'
303 HG: branch 'tag-and-branch-same-name'
333 HG: branch 'tag-and-branch-same-name'
304 HG: changed .hgtags
334 HG: changed .hgtags
305 ====
335 ====
336 hook: tag changes detected
306 $ hg log -l1 --template "{desc}\n"
337 $ hg log -l1 --template "{desc}\n"
307 custom tag message
338 custom tag message
308 second line
339 second line
@@ -311,6 +342,7 b' then, test custom commit message itself'
311 local tag with .hgtags modified
342 local tag with .hgtags modified
312
343
313 $ hg tag hgtags-modified
344 $ hg tag hgtags-modified
345 hook: tag changes detected
314 $ hg rollback
346 $ hg rollback
315 repository tip rolled back to revision 13 (undo commit)
347 repository tip rolled back to revision 13 (undo commit)
316 working directory now based on revision 13
348 working directory now based on revision 13
@@ -330,9 +362,11 b" tagging when at named-branch-head that's"
330 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
362 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
331 (branch merge, don't forget to commit)
363 (branch merge, don't forget to commit)
332 $ hg ci -m 'merge named branch'
364 $ hg ci -m 'merge named branch'
365 hook: tag changes detected
333 $ hg up 13
366 $ hg up 13
334 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
367 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
335 $ hg tag new-topo-head
368 $ hg tag new-topo-head
369 hook: tag changes detected
336
370
337 tagging on null rev
371 tagging on null rev
338
372
@@ -399,12 +433,14 b' commit hook on tag used to be run withou'
399 > hg push "$TESTTMP/repo-tag-target"
433 > hg push "$TESTTMP/repo-tag-target"
400 > EOF
434 > EOF
401 $ hg -R repo-tag --config hooks.commit="sh ../issue3344.sh" tag tag
435 $ hg -R repo-tag --config hooks.commit="sh ../issue3344.sh" tag tag
436 hook: tag changes detected
402 pushing to $TESTTMP/repo-tag-target (glob)
437 pushing to $TESTTMP/repo-tag-target (glob)
403 searching for changes
438 searching for changes
404 adding changesets
439 adding changesets
405 adding manifests
440 adding manifests
406 adding file changes
441 adding file changes
407 added 2 changesets with 2 changes to 2 files
442 added 2 changesets with 2 changes to 2 files
443 hook: tag changes detected
408
444
409 automatically merge resolvable tag conflicts (i.e. tags that differ in rank)
445 automatically merge resolvable tag conflicts (i.e. tags that differ in rank)
410 create two clones with some different tags as well as some common tags
446 create two clones with some different tags as well as some common tags
@@ -416,6 +452,7 b' check that we can merge tags that differ'
416 $ hg ci -A -m0
452 $ hg ci -A -m0
417 adding f0
453 adding f0
418 $ hg tag tbase
454 $ hg tag tbase
455 hook: tag changes detected
419 $ hg up -qr '.^'
456 $ hg up -qr '.^'
420 $ hg log -r 'wdir()' -T "{latesttagdistance}\n"
457 $ hg log -r 'wdir()' -T "{latesttagdistance}\n"
421 1
458 1
@@ -431,18 +468,23 b' check that we can merge tags that differ'
431 $ hg ci -A -m1
468 $ hg ci -A -m1
432 adding f1
469 adding f1
433 $ hg tag t1 t2 t3
470 $ hg tag t1 t2 t3
471 hook: tag changes detected
434 $ hg tag --remove t2
472 $ hg tag --remove t2
473 hook: tag changes detected
435 $ hg tag t5
474 $ hg tag t5
475 hook: tag changes detected
436 $ echo c2 > f2
476 $ echo c2 > f2
437 $ hg ci -A -m2
477 $ hg ci -A -m2
438 adding f2
478 adding f2
439 $ hg tag -f t3
479 $ hg tag -f t3
480 hook: tag changes detected
440
481
441 $ cd ../repo-automatic-tag-merge
482 $ cd ../repo-automatic-tag-merge
442 $ echo c3 > f3
483 $ echo c3 > f3
443 $ hg ci -A -m3
484 $ hg ci -A -m3
444 adding f3
485 adding f3
445 $ hg tag -f t4 t5 t6
486 $ hg tag -f t4 t5 t6
487 hook: tag changes detected
446
488
447 $ hg up -q '.^'
489 $ hg up -q '.^'
448 $ hg log -r 'wdir()' -T "{changessincelatesttag} changes since {latesttag}\n"
490 $ hg log -r 'wdir()' -T "{changessincelatesttag} changes since {latesttag}\n"
@@ -455,6 +497,7 b' check that we can merge tags that differ'
455 $ hg up -qC
497 $ hg up -qC
456
498
457 $ hg tag --remove t5
499 $ hg tag --remove t5
500 hook: tag changes detected
458 $ echo c4 > f4
501 $ echo c4 > f4
459 $ hg log -r '.' -T "{changessincelatesttag} changes since {latesttag}\n"
502 $ hg log -r '.' -T "{changessincelatesttag} changes since {latesttag}\n"
460 2 changes since t4:t6
503 2 changes since t4:t6
@@ -473,7 +516,9 b' check that we can merge tags that differ'
473 $ hg log -r 'wdir()' -T "{changessincelatesttag} changes since {latesttag}\n"
516 $ hg log -r 'wdir()' -T "{changessincelatesttag} changes since {latesttag}\n"
474 4 changes since t4:t6
517 4 changes since t4:t6
475 $ hg tag t2
518 $ hg tag t2
519 hook: tag changes detected
476 $ hg tag -f t6
520 $ hg tag -f t6
521 hook: tag changes detected
477
522
478 $ cd ../repo-automatic-tag-merge-clone
523 $ cd ../repo-automatic-tag-merge-clone
479 $ hg pull
524 $ hg pull
@@ -483,6 +528,7 b' check that we can merge tags that differ'
483 adding manifests
528 adding manifests
484 adding file changes
529 adding file changes
485 added 6 changesets with 6 changes to 3 files (+1 heads)
530 added 6 changesets with 6 changes to 3 files (+1 heads)
531 hook: tag changes detected
486 (run 'hg heads' to see heads, 'hg merge' to merge)
532 (run 'hg heads' to see heads, 'hg merge' to merge)
487 $ hg merge --tool internal:tagmerge
533 $ hg merge --tool internal:tagmerge
488 merging .hgtags
534 merging .hgtags
@@ -543,10 +589,12 b' detect merge tag conflicts'
543 $ hg update -C -r tip
589 $ hg update -C -r tip
544 3 files updated, 0 files merged, 2 files removed, 0 files unresolved
590 3 files updated, 0 files merged, 2 files removed, 0 files unresolved
545 $ hg tag t7
591 $ hg tag t7
592 hook: tag changes detected
546 $ hg update -C -r 'first(sort(head()))'
593 $ hg update -C -r 'first(sort(head()))'
547 3 files updated, 0 files merged, 2 files removed, 0 files unresolved
594 3 files updated, 0 files merged, 2 files removed, 0 files unresolved
548 $ printf "%s %s\n" `hg log -r . --template "{node} t7"` >> .hgtags
595 $ printf "%s %s\n" `hg log -r . --template "{node} t7"` >> .hgtags
549 $ hg commit -m "manually add conflicting t7 tag"
596 $ hg commit -m "manually add conflicting t7 tag"
597 hook: tag changes detected
550 $ hg merge --tool internal:tagmerge
598 $ hg merge --tool internal:tagmerge
551 merging .hgtags
599 merging .hgtags
552 automatic .hgtags merge failed
600 automatic .hgtags merge failed
@@ -581,11 +629,13 b' handle the loss of tags'
581 $ hg ci -A -m5
629 $ hg ci -A -m5
582 adding f5
630 adding f5
583 $ hg tag -f t7
631 $ hg tag -f t7
632 hook: tag changes detected
584 $ hg update -r 'p1(t7)'
633 $ hg update -r 'p1(t7)'
585 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
634 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
586 $ printf '' > .hgtags
635 $ printf '' > .hgtags
587 $ hg commit -m 'delete all tags'
636 $ hg commit -m 'delete all tags'
588 created new head
637 created new head
638 hook: tag changes detected
589 $ hg log -r 'max(t7::)'
639 $ hg log -r 'max(t7::)'
590 changeset: 17:ffe462b50880
640 changeset: 17:ffe462b50880
591 user: test
641 user: test
General Comments 0
You need to be logged in to leave comments. Login now