##// END OF EJS Templates
merge: add conflict marker formatter (BC)...
Durham Goode -
r21519:25d5a9ec default
parent child Browse files
Show More
@@ -7,7 +7,7 b''
7
7
8 from node import short
8 from node import short
9 from i18n import _
9 from i18n import _
10 import util, simplemerge, match, error
10 import util, simplemerge, match, error, templater, templatekw
11 import os, tempfile, re, filecmp
11 import os, tempfile, re, filecmp
12
12
13 def _toolstr(ui, tool, part, default=""):
13 def _toolstr(ui, tool, part, default=""):
@@ -269,6 +269,55 b' def _xmerge(repo, mynode, orig, fcd, fco'
269 return True, r
269 return True, r
270 return False, 0
270 return False, 0
271
271
272 def _formatconflictmarker(repo, ctx, template, label, pad):
273 """Applies the given template to the ctx, prefixed by the label.
274
275 Pad is the minimum width of the label prefix, so that multiple markers
276 can have aligned templated parts.
277 """
278 if ctx.node() is None:
279 ctx = ctx.p1()
280
281 props = templatekw.keywords.copy()
282 props['templ'] = template
283 props['ctx'] = ctx
284 props['repo'] = repo
285 templateresult = template('conflictmarker', **props)
286
287 label = ('%s:' % label).ljust(pad + 1)
288 mark = '%s %s' % (label, templater.stringify(templateresult))
289
290 # The <<< marks add 8 to the length, and '...' adds three, so max
291 # length of the actual marker is 69.
292 maxlength = 80 - 8 - 3
293 if len(mark) > maxlength:
294 mark = mark[:maxlength] + '...'
295 return mark
296
297 _defaultconflictmarker = ('{node|short} ' +
298 '{ifeq(tags, "tip", "", "{tags} ")}' +
299 '{if(bookmarks, "{bookmarks} ")}' +
300 '{ifeq(branch, "default", "", "{branch} ")}' +
301 '- {author|user}: "{desc|firstline}"')
302
303 def _formatlabels(repo, fcd, fco, labels):
304 """Formats the given labels using the conflict marker template.
305
306 Returns a list of formatted labels.
307 """
308 cd = fcd.changectx()
309 co = fco.changectx()
310
311 ui = repo.ui
312 template = ui.config('ui', 'mergemarkertemplate', _defaultconflictmarker)
313 template = templater.parsestring(template, quoted=False)
314 tmpl = templater.templater(None, cache={ 'conflictmarker' : template })
315
316 pad = max(len(labels[0]), len(labels[1]))
317
318 return [_formatconflictmarker(repo, cd, tmpl, labels[0], pad),
319 _formatconflictmarker(repo, co, tmpl, labels[1], pad)]
320
272 def filemerge(repo, mynode, orig, fcd, fco, fca):
321 def filemerge(repo, mynode, orig, fcd, fco, fca):
273 """perform a 3-way merge in the working directory
322 """perform a 3-way merge in the working directory
274
323
@@ -326,9 +375,15 b' def filemerge(repo, mynode, orig, fcd, f'
326
375
327 ui.debug("my %s other %s ancestor %s\n" % (fcd, fco, fca))
376 ui.debug("my %s other %s ancestor %s\n" % (fcd, fco, fca))
328
377
378 markerstyle = ui.config('ui', 'mergemarkers', 'detailed')
329 labels = ['local', 'other']
379 labels = ['local', 'other']
380 if markerstyle == 'basic':
381 formattedlabels = labels
382 else:
383 formattedlabels = _formatlabels(repo, fcd, fco, labels)
384
330 needcheck, r = func(repo, mynode, orig, fcd, fco, fca, toolconf,
385 needcheck, r = func(repo, mynode, orig, fcd, fco, fca, toolconf,
331 (a, b, c, back), labels=labels)
386 (a, b, c, back), labels=formattedlabels)
332 if not needcheck:
387 if not needcheck:
333 if r:
388 if r:
334 if onfailure:
389 if onfailure:
@@ -1208,6 +1208,20 b' User interface controls.'
1208 For more information on merge tools see :hg:`help merge-tools`.
1208 For more information on merge tools see :hg:`help merge-tools`.
1209 For configuring merge tools see the ``[merge-tools]`` section.
1209 For configuring merge tools see the ``[merge-tools]`` section.
1210
1210
1211 ``mergemarkers``
1212 Sets the merge conflict marker label styling. The default ``detailed``
1213 style uses the ``mergemarkertemplate`` setting to style the labels.
1214 The ``basic`` style just uses 'local' and 'other' as the marker label.
1215 One of ``basic`` or ``detailed``.
1216 Default is ``detailed``.
1217
1218 ``mergemarkertemplate``
1219 The template used to print the commit description next to each conflict
1220 marker during merge conflicts. See :hg:`help templates` for the template
1221 format.
1222 Defaults to showing the hash, tags, branches, bookmarks, author, and
1223 the first line of the commit description.
1224
1211 ``portablefilenames``
1225 ``portablefilenames``
1212 Check for portable filenames. Can be ``warn``, ``ignore`` or ``abort``.
1226 Check for portable filenames. Can be ``warn``, ``ignore`` or ``abort``.
1213 Default is ``warn``.
1227 Default is ``warn``.
@@ -589,7 +589,7 b' Amend a merge changeset (with renames an'
589 no more unresolved files
589 no more unresolved files
590 $ hg ci -m 'merge bar'
590 $ hg ci -m 'merge bar'
591 $ hg log --config diff.git=1 -pr .
591 $ hg log --config diff.git=1 -pr .
592 changeset: 23:d51446492733
592 changeset: 23:29ee7aa200c8
593 tag: tip
593 tag: tip
594 parent: 22:30d96aeaf27b
594 parent: 22:30d96aeaf27b
595 parent: 21:1aa437659d19
595 parent: 21:1aa437659d19
@@ -604,11 +604,11 b' Amend a merge changeset (with renames an'
604 --- a/cc
604 --- a/cc
605 +++ b/cc
605 +++ b/cc
606 @@ -1,1 +1,5 @@
606 @@ -1,1 +1,5 @@
607 +<<<<<<< local
607 +<<<<<<< local: 30d96aeaf27b - test: "aa"
608 dd
608 dd
609 +=======
609 +=======
610 +cc
610 +cc
611 +>>>>>>> other
611 +>>>>>>> other: 1aa437659d19 bar - test: "aazzcc"
612 diff --git a/z b/zz
612 diff --git a/z b/zz
613 rename from z
613 rename from z
614 rename to zz
614 rename to zz
@@ -621,7 +621,7 b' Amend a merge changeset (with renames an'
621 cc not renamed
621 cc not renamed
622 $ hg ci --amend -m 'merge bar (amend message)'
622 $ hg ci --amend -m 'merge bar (amend message)'
623 $ hg log --config diff.git=1 -pr .
623 $ hg log --config diff.git=1 -pr .
624 changeset: 24:59de3dce7a79
624 changeset: 24:ba3eb3e8e8c2
625 tag: tip
625 tag: tip
626 parent: 22:30d96aeaf27b
626 parent: 22:30d96aeaf27b
627 parent: 21:1aa437659d19
627 parent: 21:1aa437659d19
@@ -636,11 +636,11 b' Amend a merge changeset (with renames an'
636 --- a/cc
636 --- a/cc
637 +++ b/cc
637 +++ b/cc
638 @@ -1,1 +1,5 @@
638 @@ -1,1 +1,5 @@
639 +<<<<<<< local
639 +<<<<<<< local: 30d96aeaf27b - test: "aa"
640 dd
640 dd
641 +=======
641 +=======
642 +cc
642 +cc
643 +>>>>>>> other
643 +>>>>>>> other: 1aa437659d19 bar - test: "aazzcc"
644 diff --git a/z b/zz
644 diff --git a/z b/zz
645 rename from z
645 rename from z
646 rename to zz
646 rename to zz
@@ -654,7 +654,7 b' Amend a merge changeset (with renames an'
654 $ hg mv zz z
654 $ hg mv zz z
655 $ hg ci --amend -m 'merge bar (undo rename)'
655 $ hg ci --amend -m 'merge bar (undo rename)'
656 $ hg log --config diff.git=1 -pr .
656 $ hg log --config diff.git=1 -pr .
657 changeset: 26:7fb89c461f81
657 changeset: 26:0ce8747233f6
658 tag: tip
658 tag: tip
659 parent: 22:30d96aeaf27b
659 parent: 22:30d96aeaf27b
660 parent: 21:1aa437659d19
660 parent: 21:1aa437659d19
@@ -669,11 +669,11 b' Amend a merge changeset (with renames an'
669 --- a/cc
669 --- a/cc
670 +++ b/cc
670 +++ b/cc
671 @@ -1,1 +1,5 @@
671 @@ -1,1 +1,5 @@
672 +<<<<<<< local
672 +<<<<<<< local: 30d96aeaf27b - test: "aa"
673 dd
673 dd
674 +=======
674 +=======
675 +cc
675 +cc
676 +>>>>>>> other
676 +>>>>>>> other: 1aa437659d19 bar - test: "aazzcc"
677
677
678 $ hg debugrename z
678 $ hg debugrename z
679 z not renamed
679 z not renamed
@@ -690,9 +690,9 b' Amend a merge changeset (with renames du'
690 $ echo aa >> aaa
690 $ echo aa >> aaa
691 $ hg ci -m 'merge bar again'
691 $ hg ci -m 'merge bar again'
692 $ hg log --config diff.git=1 -pr .
692 $ hg log --config diff.git=1 -pr .
693 changeset: 28:982d7a34ffee
693 changeset: 28:b8235574e741
694 tag: tip
694 tag: tip
695 parent: 26:7fb89c461f81
695 parent: 26:0ce8747233f6
696 parent: 27:4c94d5bc65f5
696 parent: 27:4c94d5bc65f5
697 user: test
697 user: test
698 date: Thu Jan 01 00:00:00 1970 +0000
698 date: Thu Jan 01 00:00:00 1970 +0000
@@ -725,9 +725,9 b' Amend a merge changeset (with renames du'
725 $ hg mv aaa aa
725 $ hg mv aaa aa
726 $ hg ci --amend -m 'merge bar again (undo rename)'
726 $ hg ci --amend -m 'merge bar again (undo rename)'
727 $ hg log --config diff.git=1 -pr .
727 $ hg log --config diff.git=1 -pr .
728 changeset: 30:522688c0e71b
728 changeset: 30:dbafc132c18a
729 tag: tip
729 tag: tip
730 parent: 26:7fb89c461f81
730 parent: 26:0ce8747233f6
731 parent: 27:4c94d5bc65f5
731 parent: 27:4c94d5bc65f5
732 user: test
732 user: test
733 date: Thu Jan 01 00:00:00 1970 +0000
733 date: Thu Jan 01 00:00:00 1970 +0000
@@ -765,9 +765,9 b' Amend a merge changeset (with manifest-l'
765 use (c)hanged version or (d)elete? c
765 use (c)hanged version or (d)elete? c
766 $ hg ci -m 'merge bar (with conflicts)'
766 $ hg ci -m 'merge bar (with conflicts)'
767 $ hg log --config diff.git=1 -pr .
767 $ hg log --config diff.git=1 -pr .
768 changeset: 33:5f9904c491b8
768 changeset: 33:8b0c83445ff5
769 tag: tip
769 tag: tip
770 parent: 32:01780b896f58
770 parent: 32:f60ace0fe178
771 parent: 31:67db8847a540
771 parent: 31:67db8847a540
772 user: test
772 user: test
773 date: Thu Jan 01 00:00:00 1970 +0000
773 date: Thu Jan 01 00:00:00 1970 +0000
@@ -777,9 +777,9 b' Amend a merge changeset (with manifest-l'
777 $ hg rm aa
777 $ hg rm aa
778 $ hg ci --amend -m 'merge bar (with conflicts, amended)'
778 $ hg ci --amend -m 'merge bar (with conflicts, amended)'
779 $ hg log --config diff.git=1 -pr .
779 $ hg log --config diff.git=1 -pr .
780 changeset: 35:6ce0c89781a3
780 changeset: 35:f9b6726d8bd2
781 tag: tip
781 tag: tip
782 parent: 32:01780b896f58
782 parent: 32:f60ace0fe178
783 parent: 31:67db8847a540
783 parent: 31:67db8847a540
784 user: test
784 user: test
785 date: Thu Jan 01 00:00:00 1970 +0000
785 date: Thu Jan 01 00:00:00 1970 +0000
@@ -22,12 +22,52 b''
22 32e80765d7fe+75234512624c+ tip
22 32e80765d7fe+75234512624c+ tip
23
23
24 $ cat a
24 $ cat a
25 <<<<<<< local: 32e80765d7fe - test: "branch2"
26 something else
27 =======
28 something
29 >>>>>>> other: 75234512624c - test: "branch1"
30
31 $ hg status
32 M a
33 ? a.orig
34
35 Verify custom conflict markers
36
37 $ hg up -q --clean .
38 $ printf "\n[ui]\nmergemarkertemplate={author} {rev}\n" >> .hg/hgrc
39
40 $ hg merge 1
41 merging a
42 warning: conflicts during merge.
43 merging a incomplete! (edit conflicts, then use 'hg resolve --mark')
44 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
45 use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
46 [1]
47
48 $ cat a
49 <<<<<<< local: test 2
50 something else
51 =======
52 something
53 >>>>>>> other: test 1
54
55 Verify basic conflict markers
56
57 $ hg up -q --clean .
58 $ printf "\n[ui]\nmergemarkers=basic\n" >> .hg/hgrc
59
60 $ hg merge 1
61 merging a
62 warning: conflicts during merge.
63 merging a incomplete! (edit conflicts, then use 'hg resolve --mark')
64 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
65 use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
66 [1]
67
68 $ cat a
25 <<<<<<< local
69 <<<<<<< local
26 something else
70 something else
27 =======
71 =======
28 something
72 something
29 >>>>>>> other
73 >>>>>>> other
30
31 $ hg status
32 M a
33 ? a.orig
@@ -1049,11 +1049,11 b' conflict: keyword should stay outside co'
1049 [1]
1049 [1]
1050 $ cat m
1050 $ cat m
1051 $Id$
1051 $Id$
1052 <<<<<<< local
1052 <<<<<<< local: 88a80c8d172e - test: "8bar"
1053 bar
1053 bar
1054 =======
1054 =======
1055 foo
1055 foo
1056 >>>>>>> other
1056 >>>>>>> other: 85d2d2d732a5 - test: "simplemerge"
1057
1057
1058 resolve to local
1058 resolve to local
1059
1059
@@ -57,11 +57,11 b''
57 @@ -1,3 +1,7 @@
57 @@ -1,3 +1,7 @@
58 added file1
58 added file1
59 another line of text
59 another line of text
60 +<<<<<<< local
60 +<<<<<<< local: c3fa057dd86f - test: "added file1 and file2"
61 +changed file1 different
61 +changed file1 different
62 +=======
62 +=======
63 changed file1
63 changed file1
64 +>>>>>>> other
64 +>>>>>>> other: dfab7f3c2efb - test: "changed file1"
65
65
66 $ hg status
66 $ hg status
67 M file1
67 M file1
@@ -66,11 +66,11 b' running from a devel copy, not a temp in'
66 [1]
66 [1]
67 $ aftermerge
67 $ aftermerge
68 # cat f
68 # cat f
69 <<<<<<< local
69 <<<<<<< local: ef83787e2614 - test: "revision 1"
70 revision 1
70 revision 1
71 =======
71 =======
72 revision 2
72 revision 2
73 >>>>>>> other
73 >>>>>>> other: 0185f4e0cf02 - test: "revision 2"
74 space
74 space
75 # hg stat
75 # hg stat
76 M f
76 M f
@@ -290,18 +290,18 b' h: l vs l, different'
290 U h
290 U h
291 $ tellmeabout a
291 $ tellmeabout a
292 a is a plain file with content:
292 a is a plain file with content:
293 <<<<<<< local
293 <<<<<<< local: 0139c5610547 - test: "2"
294 2
294 2
295 =======
295 =======
296 1
296 1
297 >>>>>>> other
297 >>>>>>> other: 97e29675e796 - test: "1"
298 $ tellmeabout b
298 $ tellmeabout b
299 b is a plain file with content:
299 b is a plain file with content:
300 <<<<<<< local
300 <<<<<<< local: 0139c5610547 - test: "2"
301 2
301 2
302 =======
302 =======
303 1
303 1
304 >>>>>>> other
304 >>>>>>> other: 97e29675e796 - test: "1"
305 $ tellmeabout c
305 $ tellmeabout c
306 c is a plain file with content:
306 c is a plain file with content:
307 x
307 x
@@ -345,18 +345,18 b' h: l vs l, different'
345 [1]
345 [1]
346 $ tellmeabout a
346 $ tellmeabout a
347 a is a plain file with content:
347 a is a plain file with content:
348 <<<<<<< local
348 <<<<<<< local: 97e29675e796 - test: "1"
349 1
349 1
350 =======
350 =======
351 2
351 2
352 >>>>>>> other
352 >>>>>>> other: 0139c5610547 - test: "2"
353 $ tellmeabout b
353 $ tellmeabout b
354 b is an executable file with content:
354 b is an executable file with content:
355 <<<<<<< local
355 <<<<<<< local: 97e29675e796 - test: "1"
356 1
356 1
357 =======
357 =======
358 2
358 2
359 >>>>>>> other
359 >>>>>>> other: 0139c5610547 - test: "2"
360 $ tellmeabout c
360 $ tellmeabout c
361 c is an executable file with content:
361 c is an executable file with content:
362 x
362 x
@@ -98,11 +98,11 b' pull and merge from test-a again'
98
98
99 $ cat test.txt
99 $ cat test.txt
100 one
100 one
101 <<<<<<< local
101 <<<<<<< local: 50c3a7e29886 - test: "Merge 1"
102 two-point-five
102 two-point-five
103 =======
103 =======
104 two-point-one
104 two-point-one
105 >>>>>>> other
105 >>>>>>> other: 40d11a4173a8 - test: "two -> two-point-one"
106 three
106 three
107
107
108 $ hg debugindex test.txt
108 $ hg debugindex test.txt
@@ -210,11 +210,11 b' ensure that we have a merge with unresol'
210 +++ b/a/a
210 +++ b/a/a
211 @@ -1,2 +1,6 @@
211 @@ -1,2 +1,6 @@
212 a
212 a
213 +<<<<<<< local
213 +<<<<<<< local: * - shelve: "pending changes temporary commit" (glob)
214 c
214 c
215 +=======
215 +=======
216 +a
216 +a
217 +>>>>>>> other
217 +>>>>>>> other: * - shelve: "changes to '[mq]: second.patch'" (glob)
218 diff --git a/b.rename/b b/b.rename/b
218 diff --git a/b.rename/b b/b.rename/b
219 new file mode 100644
219 new file mode 100644
220 --- /dev/null
220 --- /dev/null
@@ -604,11 +604,11 b' unshelve and conflicts with tracked and '
604 M f
604 M f
605 ? f.orig
605 ? f.orig
606 $ cat f
606 $ cat f
607 <<<<<<< local
607 <<<<<<< local: 5f6b880e719b - shelve: "pending changes temporary commit"
608 g
608 g
609 =======
609 =======
610 f
610 f
611 >>>>>>> other
611 >>>>>>> other: 23b29cada8ba - shelve: "changes to 'commit stuff'"
612 $ cat f.orig
612 $ cat f.orig
613 g
613 g
614 $ hg unshelve --abort
614 $ hg unshelve --abort
@@ -647,11 +647,11 b' unshelve and conflicts with tracked and '
647 M f
647 M f
648 ? f.orig
648 ? f.orig
649 $ cat f
649 $ cat f
650 <<<<<<< local
650 <<<<<<< local: 6b563750f973 - test: "intermediate other change"
651 g
651 g
652 =======
652 =======
653 f
653 f
654 >>>>>>> other
654 >>>>>>> other: 23b29cada8ba - shelve: "changes to 'commit stuff'"
655 $ cat f.orig
655 $ cat f.orig
656 g
656 g
657 $ hg unshelve --abort
657 $ hg unshelve --abort
@@ -298,11 +298,11 b' merge tests'
298 should conflict
298 should conflict
299
299
300 $ cat t/t
300 $ cat t/t
301 <<<<<<< local
301 <<<<<<< local: 20a0db6fbf6c - test: "10"
302 conflict
302 conflict
303 =======
303 =======
304 t3
304 t3
305 >>>>>>> other
305 >>>>>>> other: 7af322bc1198 - test: "7"
306
306
307 clone
307 clone
308
308
General Comments 0
You need to be logged in to leave comments. Login now