# HG changeset patch # User FUJIWARA Katsunori # Date 1404583001 -32400 # Node ID 78e56e70c70a870f996c835e4b195b1263e3237e # Parent 755bf1bbe0a90b6357b121139bb480ed695b12d2 filemerge: use 'util.ellipsis' to trim custom conflict markers correctly Before this patch, filemerge slices byte sequence directly to trim conflict markers, but this may cause: - splitting at intermediate multi-byte sequence - incorrect calculation of column width (length of byte sequence is different from columns in display in many cases) This patch uses 'util.ellipsis' to trim custom conflict markers correctly, even if multi-byte characters are used in them. diff -r 755bf1bbe0a9 -r 78e56e70c70a mercurial/filemerge.py --- a/mercurial/filemerge.py Sun Jul 06 02:56:41 2014 +0900 +++ b/mercurial/filemerge.py Sun Jul 06 02:56:41 2014 +0900 @@ -290,12 +290,8 @@ if mark: mark = mark.splitlines()[0] # split for safety - # The <<< marks add 8 to the length, and '...' adds three, so max - # length of the actual marker is 69. - maxlength = 80 - 8 - 3 - if len(mark) > maxlength: - mark = mark[:maxlength] + '...' - return mark + # 8 for the prefix of conflict marker lines (e.g. '<<<<<<< ') + return util.ellipsis(mark, 80 - 8) _defaultconflictmarker = ('{node|short} ' + '{ifeq(tags, "tip", "", "{tags} ")}' + diff -r 755bf1bbe0a9 -r 78e56e70c70a tests/test-conflict.t --- a/tests/test-conflict.t Sun Jul 06 02:56:41 2014 +0900 +++ b/tests/test-conflict.t Sun Jul 06 02:56:41 2014 +0900 @@ -72,9 +72,42 @@ something >>>>>>> other: test 1 +Verify line trimming of custom conflict marker using multi-byte characters + + $ hg up -q --clean . + $ python < fp = open('logfile', 'w') + > fp.write('12345678901234567890123456789012345678901234567890' + + > '1234567890') # there are 5 more columns for 80 columns + > + > # 2 x 4 = 8 columns, but 3 x 4 = 12 bytes + > fp.write(u'\u3042\u3044\u3046\u3048'.encode('utf-8')) + > + > fp.close() + > EOF + $ hg add logfile + $ hg --encoding utf-8 commit --logfile logfile + + $ cat >> .hg/hgrc < [ui] + > mergemarkertemplate={desc|firstline} + > EOF + + $ hg -q --encoding utf-8 merge 1 + warning: conflicts during merge. + merging a incomplete! (edit conflicts, then use 'hg resolve --mark') + [1] + + $ cat a + <<<<<<< local: 123456789012345678901234567890123456789012345678901234567890\xe3\x81\x82... (esc) + something else + ======= + something + >>>>>>> other: branch1 + Verify basic conflict markers - $ hg up -q --clean . + $ hg up -q --clean 2 $ printf "\n[ui]\nmergemarkers=basic\n" >> .hg/hgrc $ hg merge 1