Debian Codegraph @

tests/test-annotate.t

raw
1 $ cat >> "$HGRCPATH" << EOF
2 > [ui]
3 > merge = :merge3
4 > EOF
5
6 init
7
8 $ hg init repo
9 $ cd repo
10
11 commit
12
13 $ echo 'a' > a
14 $ hg ci -A -m test -u nobody -d '1 0'
15 adding a
16
17 annotate -c
18
19 $ hg annotate -c a
20 8435f90966e4: a
21
22 annotate -cl
23
24 $ hg annotate -cl a
25 8435f90966e4:1: a
26
27 annotate -d
28
29 $ hg annotate -d a
30 Thu Jan 01 00:00:01 1970 +0000: a
31
32 annotate -n
33
34 $ hg annotate -n a
35 0: a
36
37 annotate -nl
38
39 $ hg annotate -nl a
40 0:1: a
41
42 annotate -u
43
44 $ hg annotate -u a
45 nobody: a
46
47 annotate -cdnu
48
49 $ hg annotate -cdnu a
50 nobody 0 8435f90966e4 Thu Jan 01 00:00:01 1970 +0000: a
51
52 annotate -cdnul
53
54 $ hg annotate -cdnul a
55 nobody 0 8435f90966e4 Thu Jan 01 00:00:01 1970 +0000:1: a
56
57 annotate (JSON)
58
59 $ hg annotate -Tjson a
60 [
61 {
62 "lines": [{"line": "a\n", "rev": 0}],
63 "path": "a"
64 }
65 ]
66
67 $ hg annotate -Tjson -cdfnul a
68 [
69 {
70 "lines": [{"date": [1.0, 0], "line": "a\n", "lineno": 1, "node": "8435f90966e442695d2ded29fdade2bac5ad8065", "path": "a", "rev": 0, "user": "nobody"}],
71 "path": "a"
72 }
73 ]
74
75 log-like templating
76
77 $ hg annotate -T'{lines % "{rev} {node|shortest}: {line}"}' a
78 0 8435: a
79
80 '{lineno}' field should be populated as necessary
81
82 $ hg annotate -T'{lines % "{rev}:{lineno}: {line}"}' a
83 0:1: a
84 $ hg annotate -Ta a \
85 > --config templates.a='"{lines % "{rev}:{lineno}: {line}"}"'
86 0:1: a
87
88 $ cat <<EOF >>a
89 > a
90 > a
91 > EOF
92 $ hg ci -ma1 -d '1 0'
93 $ hg cp a b
94 $ hg ci -mb -d '1 0'
95 $ cat <<EOF >> b
96 > b4
97 > b5
98 > b6
99 > EOF
100 $ hg ci -mb2 -d '2 0'
101
102 default output of '{lines}' should be readable
103
104 $ hg annotate -T'{lines}' a
105 0: a
106 1: a
107 1: a
108 $ hg annotate -T'{join(lines, "\n")}' a
109 0: a
110
111 1: a
112
113 1: a
114
115 several filters can be applied to '{lines}'
116
117 $ hg annotate -T'{lines|json}\n' a
118 [{"line": "a\n", "rev": 0}, {"line": "a\n", "rev": 1}, {"line": "a\n", "rev": 1}]
119 $ hg annotate -T'{lines|stringify}' a
120 0: a
121 1: a
122 1: a
123 $ hg annotate -T'{lines|count}\n' a
124 3
125
126 annotate multiple files (JSON)
127
128 $ hg annotate -Tjson a b
129 [
130 {
131 "lines": [{"line": "a\n", "rev": 0}, {"line": "a\n", "rev": 1}, {"line": "a\n", "rev": 1}],
132 "path": "a"
133 },
134 {
135 "lines": [{"line": "a\n", "rev": 0}, {"line": "a\n", "rev": 1}, {"line": "a\n", "rev": 1}, {"line": "b4\n", "rev": 3}, {"line": "b5\n", "rev": 3}, {"line": "b6\n", "rev": 3}],
136 "path": "b"
137 }
138 ]
139
140 annotate multiple files (template)
141
142 $ hg annotate -T'== {path} ==\n{lines % "{rev}: {line}"}' a b
143 == a ==
144 0: a
145 1: a
146 1: a
147 == b ==
148 0: a
149 1: a
150 1: a
151 3: b4
152 3: b5
153 3: b6
154
155 annotate -n b
156
157 $ hg annotate -n b
158 0: a
159 1: a
160 1: a
161 3: b4
162 3: b5
163 3: b6
164
165 annotate --no-follow b
166
167 $ hg annotate --no-follow b
168 2: a
169 2: a
170 2: a
171 3: b4
172 3: b5
173 3: b6
174
175 annotate -nl b
176
177 $ hg annotate -nl b
178 0:1: a
179 1:2: a
180 1:3: a
181 3:4: b4
182 3:5: b5
183 3:6: b6
184
185 annotate -nf b
186
187 $ hg annotate -nf b
188 0 a: a
189 1 a: a
190 1 a: a
191 3 b: b4
192 3 b: b5
193 3 b: b6
194
195 annotate -nlf b
196
197 $ hg annotate -nlf b
198 0 a:1: a
199 1 a:2: a
200 1 a:3: a
201 3 b:4: b4
202 3 b:5: b5
203 3 b:6: b6
204
205 $ hg up -C 2
206 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
207 $ cat <<EOF >> b
208 > b4
209 > c
210 > b5
211 > EOF
212 $ hg ci -mb2.1 -d '2 0'
213 created new head
214 $ hg merge
215 merging b
216 warning: conflicts while merging b! (edit, then use 'hg resolve --mark')
217 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
218 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
219 [1]
220 $ cat b
221 a
222 a
223 a
224 <<<<<<< working copy: 5fbdc1152d97 - test: b2.1
225 b4
226 c
227 b5
228 ||||||| common ancestor: 3086dbafde1c - test: b
229 =======
230 b4
231 b5
232 b6
233 >>>>>>> merge rev: 37ec9f5c3d1f - test: b2
234 $ cat <<EOF > b
235 > a
236 > a
237 > a
238 > b4
239 > c
240 > b5
241 > EOF
242 $ hg resolve --mark -q
243 $ rm b.orig
244 $ hg ci -mmergeb -d '3 0'
245
246 annotate after merge
247
248 $ hg annotate -nf b
249 0 a: a
250 1 a: a
251 1 a: a
252 3 b: b4
253 4 b: c
254 3 b: b5
255
256 annotate after merge with -l
257
258 $ hg annotate -nlf b
259 0 a:1: a
260 1 a:2: a
261 1 a:3: a
262 3 b:4: b4
263 4 b:5: c
264 3 b:5: b5
265
266 $ hg up -C 1
267 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
268 $ hg cp a b
269 $ cat <<EOF > b
270 > a
271 > z
272 > a
273 > EOF
274 $ hg ci -mc -d '3 0'
275 created new head
276 Work around the pure version not resolving the conflict like native code
277 #if pure
278 $ hg merge
279 merging b
280 warning: conflicts while merging b! (edit, then use 'hg resolve --mark')
281 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
282 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
283 [1]
284 $ cat <<EOF > b
285 > a
286 > z
287 > a
288 > b4
289 > c
290 > b5
291 > EOF
292 $ hg resolve -m b
293 (no more unresolved files)
294 $ rm b.orig
295 #else
296 $ hg merge
297 merging b
298 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
299 (branch merge, don't forget to commit)
300 #endif
301 $ echo d >> b
302 $ hg ci -mmerge2 -d '4 0'
303
304 annotate after rename merge
305
306 $ hg annotate -nf b
307 0 a: a
308 6 b: z
309 1 a: a
310 3 b: b4
311 4 b: c
312 3 b: b5
313 7 b: d
314
315 annotate after rename merge with -l
316
317 $ hg annotate -nlf b
318 0 a:1: a
319 6 b:2: z
320 1 a:3: a
321 3 b:4: b4
322 4 b:5: c
323 3 b:5: b5
324 7 b:7: d
325
326 --skip nothing (should be the same as no --skip at all)
327
328 $ hg annotate -nlf b --skip '1::0'
329 0 a:1: a
330 6 b:2: z
331 1 a:3: a
332 3 b:4: b4
333 4 b:5: c
334 3 b:5: b5
335 7 b:7: d
336
337 --skip a modified line. Note a slight behavior difference in pure - this is
338 because the pure code comes up with slightly different deltas internally.
339
340 $ hg annotate -nlf b --skip 6
341 0 a:1: a
342 1 a:2* z (no-pure !)
343 0 a:1* z (pure !)
344 1 a:3: a
345 3 b:4: b4
346 4 b:5: c
347 3 b:5: b5
348 7 b:7: d
349
350 --skip added lines (and test multiple skip)
351
352 $ hg annotate -nlf b --skip 3
353 0 a:1: a
354 6 b:2: z
355 1 a:3: a
356 1 a:3* b4
357 4 b:5: c
358 1 a:3* b5
359 7 b:7: d
360
361 $ hg annotate -nlf b --skip 4
362 0 a:1: a
363 6 b:2: z
364 1 a:3: a
365 3 b:4: b4
366 1 a:3* c
367 3 b:5: b5
368 7 b:7: d
369
370 $ hg annotate -nlf b --skip 3 --skip 4
371 0 a:1: a
372 6 b:2: z
373 1 a:3: a
374 1 a:3* b4
375 1 a:3* c
376 1 a:3* b5
377 7 b:7: d
378
379 $ hg annotate -nlf b --skip 'merge()'
380 0 a:1: a
381 6 b:2: z
382 1 a:3: a
383 3 b:4: b4
384 4 b:5: c
385 3 b:5: b5
386 3 b:5* d
387
388 --skip everything -- use the revision the file was introduced in
389
390 $ hg annotate -nlf b --skip 'all()'
391 0 a:1: a
392 0 a:1* z
393 0 a:1* a
394 0 a:1* b4
395 0 a:1* c
396 0 a:1* b5
397 0 a:1* d
398
399 Issue2807: alignment of line numbers with -l
400
401 $ echo more >> b
402 $ hg ci -mmore -d '5 0'
403 $ echo more >> b
404 $ hg ci -mmore -d '6 0'
405 $ echo more >> b
406 $ hg ci -mmore -d '7 0'
407 $ hg annotate -nlf b
408 0 a: 1: a
409 6 b: 2: z
410 1 a: 3: a
411 3 b: 4: b4
412 4 b: 5: c
413 3 b: 5: b5
414 7 b: 7: d
415 8 b: 8: more
416 9 b: 9: more
417 10 b:10: more
418
419 linkrev vs rev
420
421 $ hg annotate -r tip -n a
422 0: a
423 1: a
424 1: a
425
426 linkrev vs rev with -l
427
428 $ hg annotate -r tip -nl a
429 0:1: a
430 1:2: a
431 1:3: a
432
433 annotate line-range
434
435 $ hg annotate -l -L b,8:10
436 8: 8: more
437 9: 9: more
438 10:10: more
439
440 annotate line-range beyond last line
441
442 $ hg annotate -l -L b,8:13
443 8: 8: more
444 9: 9: more
445 10:10: more
446
447 annotate line-range before first line
448
449 $ hg annotate -l -L b,0:2
450 hg: parse error: fromline must be strictly positive
451 [10]
452
453 annotate line-range with --rev
454 $ hg annotate -l -L b,5:7
455 4:5: c
456 3:5: b5
457 7:7: d
458 $ sed 's/d/x/' b > b.new
459 $ mv b.new b
460 $ hg annotate --rev 'wdir()' -l -L b,5:7
461 4 :5: c
462 3 :5: b5
463 10+:7: x
464 $ hg annotate -l -L b,5:7
465 4:5: c
466 3:5: b5
467 7:7: d
468 $ hg revert --no-backup b
469 $ hg annotate --rev 3 -l b
470 0:1: a
471 1:2: a
472 1:3: a
473 3:4: b4
474 3:5: b5
475 3:6: b6
476 $ hg annotate --rev 3 -l -L b,5:7
477 3:5: b5
478 3:6: b6
479
480 annotate line-range invalid combination of options
481
482 $ hg annotate --no-follow -L b,5:7
483 abort: --line-range is incompatible with --no-follow
484 [10]
485 $ hg annotate -L b,5:7 a
486 abort: cannot combine filename or pattern and --line-range
487 [10]
488
489 annote line-range with glob patterns
490
491 $ hg annotate -l -L glob:b*,5:7
492 4:5: c
493 3:5: b5
494 7:7: d
495
496 Issue589: "undelete" sequence leads to crash
497
498 annotate was crashing when trying to --follow something
499
500 like A -> B -> A
501
502 generate ABA rename configuration
503
504 $ echo foo > foo
505 $ hg add foo
506 $ hg ci -m addfoo
507 $ hg rename foo bar
508 $ hg ci -m renamefoo
509 $ hg rename bar foo
510 $ hg ci -m renamebar
511
512 annotate after ABA with follow
513
514 $ hg annotate --follow foo
515 foo: foo
516
517 missing file
518
519 $ hg annotate nosuchfile
520 abort: nosuchfile: no such file in rev e9e6b4fa872f
521 [255]
522
523 annotate file without '\n' on last line
524
525 $ printf "" > c
526 $ hg ci -A -m test -u nobody -d '1 0'
527 adding c
528 $ hg annotate c
529 $ printf "a\nb" > c
530 $ hg ci -m test
531 $ hg annotate c
532 [0-9]+: a (re)
533 [0-9]+: b (re)
534
535 Issue3841: check annotation of the file of which filelog includes
536 merging between the revision and its ancestor
537
538 to reproduce the situation with recent Mercurial, this script uses (1)
539 "hg debugsetparents" to merge without ancestor check by "hg merge",
540 and (2) the extension to allow filelog merging between the revision
541 and its ancestor by overriding "repo._filecommit".
542
543 $ cat > ../legacyrepo.py <<EOF
544 > from mercurial import commit, error, extensions
545 > def _filecommit(orig, repo, fctx, manifest1, manifest2,
546 > linkrev, tr, includecopymeta, ms):
547 > fname = fctx.path()
548 > text = fctx.data()
549 > flog = repo.file(fname, writable=True)
550 > fparent1 = manifest1.get(fname, repo.nullid)
551 > fparent2 = manifest2.get(fname, repo.nullid)
552 > meta = {}
553 > copy = fctx.copysource()
554 > if copy and copy != fname:
555 > raise error.Abort('copying is not supported')
556 > if fparent2 != repo.nullid:
557 > return flog.add(text, meta, tr, linkrev,
558 > fparent1, fparent2), 'modified'
559 > raise error.Abort('only merging is supported')
560 > def uisetup(ui):
561 > extensions.wrapfunction(commit, '_filecommit', _filecommit)
562 > EOF
563
564 $ cat > baz <<EOF
565 > 1
566 > 2
567 > 3
568 > 4
569 > 5
570 > EOF
571 $ hg add baz
572 $ hg commit -m "baz:0"
573
574 $ cat > baz <<EOF
575 > 1 baz:1
576 > 2
577 > 3
578 > 4
579 > 5
580 > EOF
581 $ hg commit -m "baz:1"
582
583 $ cat > baz <<EOF
584 > 1 baz:1
585 > 2 baz:2
586 > 3
587 > 4
588 > 5
589 > EOF
590 $ hg debugsetparents 17 17
591 $ hg --config extensions.legacyrepo=../legacyrepo.py commit -m "baz:2"
592 $ hg debugindexdot baz
593 digraph G {
594 -1 -> 0
595 0 -> 1
596 1 -> 2
597 1 -> 2
598 }
599 $ hg annotate baz
600 17: 1 baz:1
601 18: 2 baz:2
602 16: 3
603 16: 4
604 16: 5
605
606 $ cat > baz <<EOF
607 > 1 baz:1
608 > 2 baz:2
609 > 3 baz:3
610 > 4
611 > 5
612 > EOF
613 $ hg commit -m "baz:3"
614
615 $ cat > baz <<EOF
616 > 1 baz:1
617 > 2 baz:2
618 > 3 baz:3
619 > 4 baz:4
620 > 5
621 > EOF
622 $ hg debugsetparents 19 18
623 $ hg --config extensions.legacyrepo=../legacyrepo.py commit -m "baz:4"
624 $ hg debugindexdot baz
625 digraph G {
626 -1 -> 0
627 0 -> 1
628 1 -> 2
629 1 -> 2
630 2 -> 3
631 3 -> 4
632 2 -> 4
633 }
634 $ hg annotate baz
635 17: 1 baz:1
636 18: 2 baz:2
637 19: 3 baz:3
638 20: 4 baz:4
639 16: 5
640
641 annotate clean file
642
643 $ hg annotate -ncr "wdir()" foo
644 11 472b18db256d : foo
645
646 annotate modified file
647
648 $ echo foofoo >> foo
649 $ hg annotate -r "wdir()" foo
650 11 : foo
651 20+: foofoo
652
653 $ hg annotate -cr "wdir()" foo
654 472b18db256d : foo
655 b6bedd5477e7+: foofoo
656
657 $ hg annotate -ncr "wdir()" foo
658 11 472b18db256d : foo
659 20 b6bedd5477e7+: foofoo
660
661 $ hg annotate --debug -ncr "wdir()" foo
662 11 472b18db256d1e8282064eab4bfdaf48cbfe83cd : foo
663 20 b6bedd5477e797f25e568a6402d4697f3f895a72+: foofoo
664
665 $ hg annotate -udr "wdir()" foo
666 test Thu Jan 01 00:00:00 1970 +0000: foo
667 test [A-Za-z0-9:+ ]+: foofoo (re)
668
669 $ hg annotate -ncr "wdir()" -Tjson foo
670 [
671 {
672 "lines": [{"line": "foo\n", "node": "472b18db256d1e8282064eab4bfdaf48cbfe83cd", "rev": 11}, {"line": "foofoo\n", "node": "ffffffffffffffffffffffffffffffffffffffff", "rev": 2147483647}],
673 "path": "foo"
674 }
675 ]
676
677 annotate added file
678
679 $ echo bar > bar
680 $ hg add bar
681 $ hg annotate -ncr "wdir()" bar
682 20 b6bedd5477e7+: bar
683
684 annotate renamed file
685
686 $ hg rename foo renamefoo2
687 $ hg annotate -ncr "wdir()" renamefoo2
688 11 472b18db256d : foo
689 20 b6bedd5477e7+: foofoo
690
691 annotate missing file
692
693 $ rm baz
694
695 $ hg annotate -ncr "wdir()" baz
696 abort: baz: $ENOENT$ (rhg !)
697 abort: $TESTTMP\repo/baz: $ENOENT$ (no-rhg windows !)
698 abort: $ENOENT$: '$TESTTMP/repo/baz' (no-rhg no-windows !)
699 [255]
700
701 annotate removed file
702
703 $ hg rm baz
704
705 $ hg annotate -ncr "wdir()" baz
706 abort: baz: $ENOENT$ (rhg !)
707 abort: $TESTTMP\repo/baz: $ENOENT$ (no-rhg windows !)
708 abort: $ENOENT$: '$TESTTMP/repo/baz' (no-rhg no-windows !)
709 [255]
710
711 annotate file neither in repo nor working copy
712
713 $ hg annotate -ncr "wdir()" never_existed
714 abort: never_existed: $ENOENT$
715 [255]
716
717 $ hg revert --all --no-backup --quiet
718 $ hg id -n
719 20
720
721 Test followlines() revset; we usually check both followlines(pat, range) and
722 followlines(pat, range, descend=True) to make sure both give the same result
723 when they should.
724
725 $ echo a >> foo
726 $ hg ci -m 'foo: add a'
727 $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 3:5)'
728 16: baz:0
729 19: baz:3
730 20: baz:4
731 $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 3:5, startrev=20)'
732 16: baz:0
733 19: baz:3
734 20: baz:4
735 $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 3:5, startrev=19)'
736 16: baz:0
737 19: baz:3
738 $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 3:5, startrev=19, descend=True)'
739 19: baz:3
740 20: baz:4
741 $ printf "0\n0\n" | cat - baz > baz1
742 $ mv baz1 baz
743 $ hg ci -m 'added two lines with 0'
744 $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 5:7)'
745 16: baz:0
746 19: baz:3
747 20: baz:4
748 $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 3:5, descend=true, startrev=19)'
749 19: baz:3
750 20: baz:4
751 $ echo 6 >> baz
752 $ hg ci -m 'added line 8'
753 $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 5:7)'
754 16: baz:0
755 19: baz:3
756 20: baz:4
757 $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 3:5, startrev=19, descend=1)'
758 19: baz:3
759 20: baz:4
760 $ sed 's/3/3+/' baz > baz.new
761 $ mv baz.new baz
762 $ hg ci -m 'baz:3->3+'
763 $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 5:7, descend=0)'
764 16: baz:0
765 19: baz:3
766 20: baz:4
767 24: baz:3->3+
768 $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 3:5, startrev=17, descend=True)'
769 19: baz:3
770 20: baz:4
771 24: baz:3->3+
772 $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 1:2, descend=false)'
773 22: added two lines with 0
774
775 file patterns are okay
776 $ hg log -T '{rev}: {desc}\n' -r 'followlines("path:baz", 1:2)'
777 22: added two lines with 0
778
779 renames are followed
780 $ hg mv baz qux
781 $ sed 's/4/4+/' qux > qux.new
782 $ mv qux.new qux
783 $ hg ci -m 'qux:4->4+'
784 $ hg log -T '{rev}: {desc}\n' -r 'followlines(qux, 5:7)'
785 16: baz:0
786 19: baz:3
787 20: baz:4
788 24: baz:3->3+
789 25: qux:4->4+
790
791 but are missed when following children
792 $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 5:7, startrev=22, descend=True)'
793 24: baz:3->3+
794
795 merge
796 $ hg up 24 --quiet
797 $ echo 7 >> baz
798 $ hg ci -m 'one more line, out of line range'
799 created new head
800 $ sed 's/3+/3-/' baz > baz.new
801 $ mv baz.new baz
802 $ hg ci -m 'baz:3+->3-'
803 $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 5:7)'
804 16: baz:0
805 19: baz:3
806 20: baz:4
807 24: baz:3->3+
808 27: baz:3+->3-
809 $ hg merge 25
810 merging baz and qux to qux
811 warning: conflicts while merging qux! (edit, then use 'hg resolve --mark')
812 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
813 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
814 [1]
815 $ cat qux
816 0
817 0
818 1 baz:1
819 2 baz:2
820 <<<<<<< working copy: 863de62655ef - test: baz:3+->3-
821 3- baz:3
822 4 baz:4
823 ||||||| common ancestor: 56fc739c091f - test: baz:3->3+
824 3+ baz:3
825 4 baz:4
826 =======
827 3+ baz:3
828 4+ baz:4
829 >>>>>>> merge rev: cb8df70ae185 - test: qux:4->4+
830 5
831 6
832 7
833 $ cat > qux <<EOF
834 > 0
835 > 0
836 > 1 baz:1
837 > 2 baz:2
838 > 3- baz:3
839 > 4 baz:4
840 > 5
841 > 6
842 > 7
843 > EOF
844 $ hg resolve --mark -q
845 $ rm qux.orig
846 $ hg ci -m merge
847 $ hg log -T '{rev}: {desc}\n' -r 'followlines(qux, 5:7)'
848 16: baz:0
849 19: baz:3
850 20: baz:4
851 24: baz:3->3+
852 25: qux:4->4+
853 27: baz:3+->3-
854 28: merge
855 $ hg up 25 --quiet
856 $ hg merge 27
857 merging qux and baz to qux
858 warning: conflicts while merging qux! (edit, then use 'hg resolve --mark')
859 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
860 use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
861 [1]
862 $ cat qux
863 0
864 0
865 1 baz:1
866 2 baz:2
867 <<<<<<< working copy: cb8df70ae185 - test: qux:4->4+
868 3+ baz:3
869 4+ baz:4
870 ||||||| common ancestor: 56fc739c091f - test: baz:3->3+
871 3+ baz:3
872 4 baz:4
873 =======
874 3- baz:3
875 4 baz:4
876 >>>>>>> merge rev: 863de62655ef - test: baz:3+->3-
877 5
878 6
879 7
880 $ cat > qux <<EOF
881 > 0
882 > 0
883 > 1 baz:1
884 > 2 baz:2
885 > 3+ baz:3
886 > 4+ baz:4
887 > 5
888 > 6
889 > EOF
890 $ hg resolve --mark -q
891 $ rm qux.orig
892 $ hg ci -m 'merge from other side'
893 created new head
894 $ hg log -T '{rev}: {desc}\n' -r 'followlines(qux, 5:7)'
895 16: baz:0
896 19: baz:3
897 20: baz:4
898 24: baz:3->3+
899 25: qux:4->4+
900 27: baz:3+->3-
901 29: merge from other side
902 $ hg up 24 --quiet
903
904 we are missing the branch with rename when following children
905 $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 5:7, startrev=26, descend=True)'
906 27: baz:3+->3-
907
908 we follow all branches in descending direction
909 $ hg up 23 --quiet
910 $ sed 's/3/+3/' baz > baz.new
911 $ mv baz.new baz
912 $ hg ci -m 'baz:3->+3'
913 created new head
914 $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 2:5, startrev=16, descend=True)' --graph
915 @ 30: baz:3->+3
916 :
917 : o 27: baz:3+->3-
918 : :
919 : o 24: baz:3->3+
920 :/
921 o 20: baz:4
922 |\
923 | o 19: baz:3
924 |/
925 o 18: baz:2
926 :
927 o 16: baz:0
928 |
929 ~
930
931 Issue5595: on a merge changeset with different line ranges depending on
932 parent, be conservative and use the surrounding interval to avoid loosing
933 track of possible further descendants in specified range.
934
935 $ hg up 23 --quiet
936 $ hg cat baz -r 24
937 0
938 0
939 1 baz:1
940 2 baz:2
941 3+ baz:3
942 4 baz:4
943 5
944 6
945 $ cat > baz << EOF
946 > 0
947 > 0
948 > a
949 > b
950 > 3+ baz:3
951 > 4 baz:4
952 > y
953 > z
954 > EOF
955 $ hg ci -m 'baz: mostly rewrite with some content from 24'
956 created new head
957 $ hg merge --tool :merge-other 24
958 merging baz
959 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
960 (branch merge, don't forget to commit)
961 $ hg ci -m 'merge forgetting about baz rewrite'
962 $ cat > baz << EOF
963 > 0
964 > 0
965 > 1 baz:1
966 > 2+ baz:2
967 > 3+ baz:3
968 > 4 baz:4
969 > 5
970 > 6
971 > EOF
972 $ hg ci -m 'baz: narrow change (2->2+)'
973 $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 3:4, startrev=20, descend=True)' --graph
974 @ 33: baz: narrow change (2->2+)
975 |
976 o 32: merge forgetting about baz rewrite
977 |\
978 | o 31: baz: mostly rewrite with some content from 24
979 | :
980 | : o 30: baz:3->+3
981 | :/
982 +---o 27: baz:3+->3-
983 | :
984 o : 24: baz:3->3+
985 :/
986 o 20: baz:4
987 |\
988 ~ ~
989
990 An integer as a line range, which is parsed as '1:1'
991
992 $ hg log -r 'followlines(baz, 1)'
993 changeset: 22:2174d0bf352a
994 user: test
995 date: Thu Jan 01 00:00:00 1970 +0000
996 summary: added two lines with 0
997
998
999 check error cases
1000 $ hg up 24 --quiet
1001 $ hg log -r 'followlines()'
1002 hg: parse error: followlines takes at least 1 positional arguments
1003 [10]
1004 $ hg log -r 'followlines(baz)'
1005 hg: parse error: followlines requires a line range
1006 [10]
1007 $ hg log -r 'followlines(baz, x)'
1008 hg: parse error: followlines expects a line number or a range
1009 [10]
1010 $ hg log -r 'followlines(baz, 1:2, startrev=desc("b"))'
1011 hg: parse error: followlines expects exactly one revision
1012 [10]
1013 $ hg log -r 'followlines("glob:*", 1:2)'
1014 hg: parse error: followlines expects exactly one file
1015 [10]
1016 $ hg log -r 'followlines(baz, 1:)'
1017 hg: parse error: line range bounds must be integers
1018 [10]
1019 $ hg log -r 'followlines(baz, :1)'
1020 hg: parse error: line range bounds must be integers
1021 [10]
1022 $ hg log -r 'followlines(baz, x:4)'
1023 hg: parse error: line range bounds must be integers
1024 [10]
1025 $ hg log -r 'followlines(baz, 5:4)'
1026 hg: parse error: line range must be positive
1027 [10]
1028 $ hg log -r 'followlines(baz, 0:4)'
1029 hg: parse error: fromline must be strictly positive
1030 [10]
1031 $ hg log -r 'followlines(baz, 2:40)'
1032 abort: line range exceeds file size
1033 [10]
1034 $ hg log -r 'followlines(baz, 2:4, startrev=20, descend=[1])'
1035 hg: parse error at 43: not a prefix: [
1036 (followlines(baz, 2:4, startrev=20, descend=[1])
1037 ^ here)
1038 [10]
1039 $ hg log -r 'followlines(baz, 2:4, startrev=20, descend=a)'
1040 hg: parse error: descend argument must be a boolean
1041 [10]
1042
1043 Test empty annotate output
1044
1045 $ printf '\0' > binary
1046 $ touch empty
1047 $ hg ci -qAm 'add binary and empty files'
1048
1049 $ hg annotate binary empty
1050 binary: binary file
1051
1052 $ hg annotate -Tjson binary empty
1053 [
1054 {
1055 "path": "binary"
1056 },
1057 {
1058 "lines": [],
1059 "path": "empty"
1060 }
1061 ]
1062
1063 Test non-UTF8 (should use U+FFFD replacement character)
1064 TODO: fix Python which instead emits invalid JSON
1065
1066 $ "$PYTHON" -c 'open("latin1", "wb").write(b"\xc9")'
1067 $ hg ci -qAm 'add latin1 file'
1068 $ hg annotate -Tjson latin1
1069 [
1070 {
1071 "lines": [{"line": "\xed\xb3\x89", "rev": 35}], (esc) (no-rhg known-bad-output !)
1072 "lines": [{"line": "\xef\xbf\xbd", "rev": 35}], (esc) (rhg !)
1073 "path": "latin1"
1074 }
1075 ]
1076
1077 Test annotate with whitespace options
1078
1079 $ cd ..
1080 $ hg init repo-ws
1081 $ cd repo-ws
1082 $ cat > a <<EOF
1083 > aa
1084 >
1085 > b b
1086 > EOF
1087 $ hg ci -Am "adda"
1088 adding a
1089 $ sed 's/EOL$//g' > a <<EOF
1090 > a a
1091 > EOL
1092 > b b
1093 >
1094 > EOF
1095 $ hg ci -m "changea"
1096
1097 Annotate with no option
1098
1099 $ hg annotate a
1100 1: a a
1101 1:
1102 1: b b
1103 0:
1104
1105 Annotate with --ignore-space-change
1106
1107 $ hg annotate --ignore-space-change a
1108 1: a a
1109 0:
1110 0: b b
1111 1:
1112
1113 Annotate with --ignore-all-space
1114
1115 $ hg annotate --ignore-all-space a
1116 0: a a
1117 0:
1118 0: b b
1119 1:
1120
1121 Annotate with --ignore-blank-lines (similar to no options case)
1122
1123 $ hg annotate --ignore-blank-lines a
1124 1: a a
1125 1:
1126 1: b b
1127 0:
1128
1129 Annotate with --ignore-space-at-eol
1130
1131 $ hg annotate --ignore-space-at-eol a
1132 1: a a
1133 0:
1134 1: b b
1135 1:
1136
1137 $ cd ..
1138
1139 Annotate with orphaned CR (issue5798)
1140 -------------------------------------
1141
1142 $ hg init repo-cr
1143 $ cd repo-cr
1144
1145 $ cat <<'EOF' >> "$TESTTMP/substcr.py"
1146 > import sys
1147 > from mercurial.utils import procutil
1148 > procutil.setbinary(sys.stdin)
1149 > procutil.setbinary(sys.stdout)
1150 > stdin = getattr(sys.stdin, 'buffer', sys.stdin)
1151 > stdout = getattr(sys.stdout, 'buffer', sys.stdout)
1152 > stdout.write(stdin.read().replace(b'\r', b'[CR]'))
1153 > EOF
1154
1155 >>> with open('a', 'wb') as f:
1156 ... f.write(b'0a\r0b\r\n0c\r0d\r\n0e\n0f\n0g') and None
1157 $ hg ci -qAm0
1158 >>> with open('a', 'wb') as f:
1159 ... f.write(b'0a\r0b\r\n1c\r1d\r\n0e\n1f\n0g') and None
1160 $ hg ci -m1
1161
1162 $ hg annotate -r0 a | "$PYTHON" "$TESTTMP/substcr.py"
1163 0: 0a[CR]0b[CR]
1164 0: 0c[CR]0d[CR]
1165 0: 0e
1166 0: 0f
1167 0: 0g
1168 $ hg annotate -r1 a | "$PYTHON" "$TESTTMP/substcr.py"
1169 0: 0a[CR]0b[CR]
1170 1: 1c[CR]1d[CR]
1171 0: 0e
1172 1: 1f
1173 0: 0g
1174
1175 $ cd ..
1176
1177 Annotate with linkrev pointing to another branch
1178 ------------------------------------------------
1179
1180 create history with a filerev whose linkrev points to another branch
1181
1182 $ hg init branchedlinkrev
1183 $ cd branchedlinkrev
1184 $ echo A > a
1185 $ hg commit -Am 'contentA'
1186 adding a
1187 $ echo B >> a
1188 $ hg commit -m 'contentB'
1189 $ hg up --rev 'desc(contentA)'
1190 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1191 $ echo unrelated > unrelated
1192 $ hg commit -Am 'unrelated'
1193 adding unrelated
1194 created new head
1195 $ hg graft -r 'desc(contentB)'
1196 grafting 1:fd27c222e3e6 "contentB"
1197 $ echo C >> a
1198 $ hg commit -m 'contentC'
1199 $ echo W >> a
1200 $ hg log -G
1201 @ changeset: 4:072f1e8df249
1202 | tag: tip
1203 | user: test
1204 | date: Thu Jan 01 00:00:00 1970 +0000
1205 | summary: contentC
1206 |
1207 o changeset: 3:ff38df03cc4b
1208 | user: test
1209 | date: Thu Jan 01 00:00:00 1970 +0000
1210 | summary: contentB
1211 |
1212 o changeset: 2:62aaf3f6fc06
1213 | parent: 0:f0932f74827e
1214 | user: test
1215 | date: Thu Jan 01 00:00:00 1970 +0000
1216 | summary: unrelated
1217 |
1218 | o changeset: 1:fd27c222e3e6
1219 |/ user: test
1220 | date: Thu Jan 01 00:00:00 1970 +0000
1221 | summary: contentB
1222 |
1223 o changeset: 0:f0932f74827e
1224 user: test
1225 date: Thu Jan 01 00:00:00 1970 +0000
1226 summary: contentA
1227
1228
1229 Annotate should list ancestor of starting revision only
1230
1231 $ hg annotate a
1232 0: A
1233 3: B
1234 4: C
1235
1236 $ hg annotate a -r 'wdir()'
1237 0 : A
1238 3 : B
1239 4 : C
1240 4+: W
1241
1242 Even when the starting revision is the linkrev-shadowed one:
1243
1244 $ hg annotate a -r 3
1245 0: A
1246 3: B
1247
1248 $ cd ..
1249
1250 Annotate should use the starting revision (-r) as base for ancestor checks.
1251
1252 $ hg init repo-base
1253 $ cd repo-base
1254 $ echo A > file
1255 $ hg commit -Am "initial"
1256 adding file
1257 $ echo B >> file
1258 $ hg commit -m "linkrev"
1259 $ hg up 0
1260 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1261 $ echo B >> file
1262 $ hg ci -m "linkrev alias"
1263 created new head
1264 $ echo C >> file
1265 $ hg commit -m "change"
1266 $ hg merge 1 --tool :local
1267 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1268 (branch merge, don't forget to commit)
1269 $ hg commit -m "merge"
1270 $ hg debugindex file
1271 rev linkrev nodeid p1-nodeid p2-nodeid
1272 0 0 45f17b21388f 000000000000 000000000000
1273 1 1 e338fefefb89 45f17b21388f 000000000000
1274 2 3 b2f3b2eded93 e338fefefb89 000000000000
1275 $ hg log -G --template '{rev}: {desc}'
1276 @ 4: merge
1277 |\
1278 | o 3: change
1279 | |
1280 | o 2: linkrev alias
1281 | |
1282 o | 1: linkrev
1283 |/
1284 o 0: initial
1285
1286 Line B should be attributed to the linkrev 1, because we base ancestor checks
1287 from 4 (starting revision), not from 3 (most recent change to the file).
1288 $ hg annotate file
1289 0: A
1290 1: B
1291 3: C
1292 $ echo D >> file
1293 $ hg commit -m "another change"
1294 $ hg annotate file
1295 0: A
1296 1: B
1297 3: C
1298 5: D
1299
1300 $ cd ..
1301
1302 When scanning the changelog to adjust linkrevs, it should start from a known descendant
1303 rather than from the top. Either result would be correct, but it's better for performance
1304 to start from a descendant, so we should consistently do that.
1305
1306 $ hg init repo-descendant-behavior
1307 $ cd repo-descendant-behavior
1308 $ hg commit --config ui.allowemptycommit=True -m "initial"
1309 $ echo A > file
1310 $ hg commit -qAm "linkrev"
1311 $ hg up 0 -q
1312 $ echo A > file
1313 $ hg commit -qAm "annotation if scanning from descendant"
1314 $ echo B >> file
1315 $ hg commit -m "descendant"
1316 $ hg up 0 -q
1317 $ echo A > file
1318 $ hg commit -qAm "annotation if scanning from merge"
1319 $ hg merge -r 'desc("descendant")' --tool :local
1320 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1321 (branch merge, don't forget to commit)
1322 $ hg commit -m "merge"
1323 $ hg log -G --template '{rev}: {desc}'
1324 @ 5: merge
1325 |\
1326 | o 4: annotation if scanning from merge
1327 | |
1328 o | 3: descendant
1329 | |
1330 o | 2: annotation if scanning from descendant
1331 |/
1332 | o 1: linkrev
1333 |/
1334 o 0: initial
1335
1336 $ hg annotate file
1337 2: A
1338
1339 $ cd ..
1340
1341 Issue5360: Deleted chunk in p1 of a merge changeset
1342
1343 $ hg init repo-5360
1344 $ cd repo-5360
1345 $ echo 1 > a
1346 $ hg commit -A a -m 1
1347 $ echo 2 >> a
1348 $ hg commit -m 2
1349 $ echo a > a
1350 $ hg commit -m a
1351 $ hg update '.^' -q
1352 $ echo 3 >> a
1353 $ hg commit -m 3 -q
1354 $ hg merge 2 -q
1355 warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
1356 [1]
1357 $ cat a
1358 <<<<<<< working copy: 0a068f0261cf - test: 3
1359 1
1360 2
1361 3
1362 ||||||| common ancestor: 1ed24be7e7a0 - test: 2
1363 1
1364 2
1365 =======
1366 a
1367 >>>>>>> merge rev: 9409851bc20a - test: a
1368 $ cat > a << EOF
1369 > b
1370 > 1
1371 > 2
1372 > 3
1373 > a
1374 > EOF
1375 $ hg resolve --mark -q
1376 $ rm a.orig
1377 $ hg commit -m m
1378 $ hg annotate a
1379 4: b
1380 0: 1
1381 1: 2
1382 3: 3
1383 2: a
1384
1385 $ cd ..