Submitter | Durham Goode |
---|---|
Date | May 9, 2014, 12:33 a.m. |
Message ID | <69cf8247537f72bf864d.1399595608@dev2000.prn2.facebook.com> |
Download | mbox | patch |
Permalink | /patch/4689/ |
State | Changes Requested |
Headers | show |
Comments
On 05/08/2014 05:33 PM, Durham Goode wrote: > # HG changeset patch > # User Durham Goode <durham@fb.com> > # Date 1399593022 25200 > # Thu May 08 16:50:22 2014 -0700 > # Node ID 69cf8247537f72bf864d4799270329a7ef00b04f > # Parent 7ff0390bd790e788b91b85dee7fecd00d588ba4f > merge: add conflict marker formatter > > Adds a conflict marker formatter that can produce custom conflict marker > descriptions. It can be set via ui.conflictmarkertemplate. > > The default format is similar to: > > {shortest(node)} {tag} {branch} {bookmarks} - "{desc|firstline}" > > And renders as: > > contextblahblah > <<<<<<< local: 50c3 - "Merge 1" > line from my changes > ======= > line from the other changes > >>>>>>> other: 40d1 - "two -> two-point-one" > morecontextblahblah > diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py > --- a/mercurial/filemerge.py > +++ b/mercurial/filemerge.py > @@ -7,7 +7,7 @@ > > from node import short > from i18n import _ > -import util, simplemerge, match, error > +import util, simplemerge, match, error, templater, templatekw > import os, tempfile, re, filecmp > > def _toolstr(ui, tool, part, default=""): > @@ -269,6 +269,46 @@ > return True, r > return False, 0 > > +_defaultmarkertemplate = ('{shortest(node)}' + > + '{ifeq(tags, "tip", " ", " {tags}")}' + > + '{if(bookmarks, " {bookmarks}")}' + > + '{ifeq(branch, "default", "", " {branch}")}' + > + ' - "{desc|firstline}"') > + > +def _formatlabels(repo, fcd, fco, labels): > + """Formats the given labels using the conflict marker template. > + > + Returns a list of formatted labels. > + """ > + cd = fcd.changectx() > + co = fco.changectx() > + if cd.node() is None: > + cd = cd.p1() Meh, we cannot juste take the parent here. it's not going to provide and helpful message. (For other people: this applies when updating with uncommited changes). I really love the feature. but we needs that properly handled before accepting this patch.
On 05/09/2014 02:33 AM, Durham Goode wrote: > # HG changeset patch > # User Durham Goode <durham@fb.com> > # Date 1399593022 25200 > # Thu May 08 16:50:22 2014 -0700 > # Node ID 69cf8247537f72bf864d4799270329a7ef00b04f > # Parent 7ff0390bd790e788b91b85dee7fecd00d588ba4f > merge: add conflict marker formatter > > Adds a conflict marker formatter that can produce custom conflict marker > descriptions. It can be set via ui.conflictmarkertemplate. Shouldn't that be merge.conflictmarkertemplate ? Most other templates are real templates in mercurial/templates/map* . Is this template so special that it deserves special treatment? It might be more convenient to customize in the configuration than to customize templates ... but that could perhaps be addressed by fully merging the config and template name spaces or making it possible to overrule templates in configuration. > The default format is similar to: > > {shortest(node)} {tag} {branch} {bookmarks} - "{desc|firstline}" Perhaps out of scope, but I would like to have a generic one-liner style that could be used everywhere - also here. For instance, most tests define their own one-liner style for log ... and tests which don't probably should. > And renders as: > > contextblahblah > <<<<<<< local: 50c3 - "Merge 1" > line from my changes > ======= > line from the other changes > >>>>>>> other: 40d1 - "two -> two-point-one" > morecontextblahblah > > diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py > --- a/mercurial/filemerge.py > +++ b/mercurial/filemerge.py > @@ -7,7 +7,7 @@ > > from node import short > from i18n import _ > -import util, simplemerge, match, error > +import util, simplemerge, match, error, templater, templatekw > import os, tempfile, re, filecmp > > def _toolstr(ui, tool, part, default=""): > @@ -269,6 +269,46 @@ > return True, r > return False, 0 > > +_defaultmarkertemplate = ('{shortest(node)}' + > + '{ifeq(tags, "tip", " ", " {tags}")}' + > + '{if(bookmarks, " {bookmarks}")}' + > + '{ifeq(branch, "default", "", " {branch}")}' + > + ' - "{desc|firstline}"') > + > +def _formatlabels(repo, fcd, fco, labels): > + """Formats the given labels using the conflict marker template. > + > + Returns a list of formatted labels. > + """ > + cd = fcd.changectx() > + co = fco.changectx() > + if cd.node() is None: > + cd = cd.p1() > + > + ui = repo.ui > + tmpl = ui.config('ui', 'conflictmarkertemplate', _defaultmarkertemplate) > + tmpl = templater.parsestring(tmpl, quoted=False) > + t = templater.templater(None, cache={ 'marker': tmpl }) > + > + def getmarker(label, ctx): > + props = templatekw.keywords.copy() > + props['templ'] = t > + props['ctx'] = ctx > + props['repo'] = repo > + mark = '%s: %s' % (label, templater.stringify(t('marker', **props))) > + > + # 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] + '...' That looks like a missing ellipsis feature in the template language ;-) > + return mark > + > + return [ > + getmarker(labels[0], cd), > + getmarker(labels[1], co), > + ] > + > def filemerge(repo, mynode, orig, fcd, fco, fca): > """perform a 3-way merge in the working directory > > @@ -327,8 +367,9 @@ > ui.debug("my %s other %s ancestor %s\n" % (fcd, fco, fca)) > > labels = ['local', 'other'] > + formattedlabels = _formatlabels(repo, fcd, fco, labels) > needcheck, r = func(repo, mynode, orig, fcd, fco, fca, toolconf, > - (a, b, c, back), labels=labels) > + (a, b, c, back), labels=formattedlabels) > if not needcheck: > if r: > if onfailure: > diff --git a/tests/test-commit-amend.t b/tests/test-commit-amend.t > --- a/tests/test-commit-amend.t > +++ b/tests/test-commit-amend.t > @@ -588,7 +588,7 @@ > $ hg resolve -m cc > $ hg ci -m 'merge bar' > $ hg log --config diff.git=1 -pr . > - changeset: 23:d51446492733 > + changeset: 23:7982f58410ed Do you know why the hashes change? Do the test do weird stuff like committing the conflict markers? /Mads
On 5/9/14, 3:37 AM, "Mads Kiilerich" <mads@kiilerich.com> wrote: >On 05/09/2014 02:33 AM, Durham Goode wrote: >> # HG changeset patch >> # User Durham Goode <durham@fb.com> >> # Date 1399593022 25200 >> # Thu May 08 16:50:22 2014 -0700 >> # Node ID 69cf8247537f72bf864d4799270329a7ef00b04f >> # Parent 7ff0390bd790e788b91b85dee7fecd00d588ba4f >> merge: add conflict marker formatter >> >> Adds a conflict marker formatter that can produce custom conflict marker >> descriptions. It can be set via ui.conflictmarkertemplate. > >Shouldn't that be merge.conflictmarkertemplate ? > >Most other templates are real templates in mercurial/templates/map* . Is >this template so special that it deserves special treatment? > >It might be more convenient to customize in the configuration than to >customize templates ... but that could perhaps be addressed by fully >merging the config and template name spaces or making it possible to >overrule templates in configuration. I¹ll make it read from a template file and overridable from the config. I think template files as a means of customization is a pretty poor experience, so I¹d prefer to keep the config override at least. > >> diff --git a/tests/test-commit-amend.t b/tests/test-commit-amend.t >> --- a/tests/test-commit-amend.t >> +++ b/tests/test-commit-amend.t >> @@ -588,7 +588,7 @@ >> $ hg resolve -m cc >> $ hg ci -m 'merge bar' >> $ hg log --config diff.git=1 -pr . >> - changeset: 23:d51446492733 >> + changeset: 23:7982f58410ed > >Do you know why the hashes change? Do the test do weird stuff like >committing the conflict markers? Yea, the test hits a conflict, marks it resolved, then commits the result.
On 5/8/14, 9:13 PM, "Pierre-Yves David" <pierre-yves.david@ens-lyon.org> wrote: > > >On 05/08/2014 05:33 PM, Durham Goode wrote: >> # HG changeset patch >> # User Durham Goode <durham@fb.com> >> # Date 1399593022 25200 >> # Thu May 08 16:50:22 2014 -0700 >> # Node ID 69cf8247537f72bf864d4799270329a7ef00b04f >> # Parent 7ff0390bd790e788b91b85dee7fecd00d588ba4f >> merge: add conflict marker formatter >> >> Adds a conflict marker formatter that can produce custom conflict marker >> descriptions. It can be set via ui.conflictmarkertemplate. >> >> The default format is similar to: >> >> {shortest(node)} {tag} {branch} {bookmarks} - "{desc|firstline}" >> >> And renders as: >> >> contextblahblah >> <<<<<<< local: 50c3 - "Merge 1" >> line from my changes >> ======= >> line from the other changes >> >>>>>>> other: 40d1 - "two -> two-point-one" >> morecontextblahblah > > > >> diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py >> --- a/mercurial/filemerge.py >> +++ b/mercurial/filemerge.py >> @@ -7,7 +7,7 @@ >> >> from node import short >> from i18n import _ >> -import util, simplemerge, match, error >> +import util, simplemerge, match, error, templater, templatekw >> import os, tempfile, re, filecmp >> >> def _toolstr(ui, tool, part, default=""): >> @@ -269,6 +269,46 @@ >> return True, r >> return False, 0 >> >> +_defaultmarkertemplate = ('{shortest(node)}' + >> + '{ifeq(tags, "tip", " ", " {tags}")}' + >> + '{if(bookmarks, " {bookmarks}")}' + >> + '{ifeq(branch, "default", "", " {branch}")}' + >> + ' - "{desc|firstline}"') >> + >> +def _formatlabels(repo, fcd, fco, labels): >> + """Formats the given labels using the conflict marker template. >> + >> + Returns a list of formatted labels. >> + """ >> + cd = fcd.changectx() >> + co = fco.changectx() >> + if cd.node() is None: >> + cd = cd.p1() > >Meh, we cannot juste take the parent here. it's not going to provide and >helpful message. > >(For other people: this applies when updating with uncommited changes). > >I really love the feature. but we needs that properly handled before >accepting this patch. > >-- >Pierre-Yves David In the V2 of the series I left cd = cd .p1() so we¹ll always have some commit output as part of the marker, but I¹ve changed 'hg update¹ to have special conflict labels so it¹ll say Œworking copy: ...¹ and Œdestination: ...'
Patch
diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py --- a/mercurial/filemerge.py +++ b/mercurial/filemerge.py @@ -7,7 +7,7 @@ from node import short from i18n import _ -import util, simplemerge, match, error +import util, simplemerge, match, error, templater, templatekw import os, tempfile, re, filecmp def _toolstr(ui, tool, part, default=""): @@ -269,6 +269,46 @@ return True, r return False, 0 +_defaultmarkertemplate = ('{shortest(node)}' + + '{ifeq(tags, "tip", " ", " {tags}")}' + + '{if(bookmarks, " {bookmarks}")}' + + '{ifeq(branch, "default", "", " {branch}")}' + + ' - "{desc|firstline}"') + +def _formatlabels(repo, fcd, fco, labels): + """Formats the given labels using the conflict marker template. + + Returns a list of formatted labels. + """ + cd = fcd.changectx() + co = fco.changectx() + if cd.node() is None: + cd = cd.p1() + + ui = repo.ui + tmpl = ui.config('ui', 'conflictmarkertemplate', _defaultmarkertemplate) + tmpl = templater.parsestring(tmpl, quoted=False) + t = templater.templater(None, cache={ 'marker': tmpl }) + + def getmarker(label, ctx): + props = templatekw.keywords.copy() + props['templ'] = t + props['ctx'] = ctx + props['repo'] = repo + mark = '%s: %s' % (label, templater.stringify(t('marker', **props))) + + # 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 + + return [ + getmarker(labels[0], cd), + getmarker(labels[1], co), + ] + def filemerge(repo, mynode, orig, fcd, fco, fca): """perform a 3-way merge in the working directory @@ -327,8 +367,9 @@ ui.debug("my %s other %s ancestor %s\n" % (fcd, fco, fca)) labels = ['local', 'other'] + formattedlabels = _formatlabels(repo, fcd, fco, labels) needcheck, r = func(repo, mynode, orig, fcd, fco, fca, toolconf, - (a, b, c, back), labels=labels) + (a, b, c, back), labels=formattedlabels) if not needcheck: if r: if onfailure: diff --git a/tests/test-commit-amend.t b/tests/test-commit-amend.t --- a/tests/test-commit-amend.t +++ b/tests/test-commit-amend.t @@ -588,7 +588,7 @@ $ hg resolve -m cc $ hg ci -m 'merge bar' $ hg log --config diff.git=1 -pr . - changeset: 23:d51446492733 + changeset: 23:7982f58410ed tag: tip parent: 22:30d96aeaf27b parent: 21:1aa437659d19 @@ -603,11 +603,11 @@ --- a/cc +++ b/cc @@ -1,1 +1,5 @@ - +<<<<<<< local + +<<<<<<< local: 30d9 - "aa" dd +======= +cc - +>>>>>>> other + +>>>>>>> other: 1aa4 bar - "aazzcc" diff --git a/z b/zz rename from z rename to zz @@ -620,7 +620,7 @@ cc not renamed $ hg ci --amend -m 'merge bar (amend message)' $ hg log --config diff.git=1 -pr . - changeset: 24:59de3dce7a79 + changeset: 24:2ac15bdf3ca6 tag: tip parent: 22:30d96aeaf27b parent: 21:1aa437659d19 @@ -635,11 +635,11 @@ --- a/cc +++ b/cc @@ -1,1 +1,5 @@ - +<<<<<<< local + +<<<<<<< local: 30d9 - "aa" dd +======= +cc - +>>>>>>> other + +>>>>>>> other: 1aa4 bar - "aazzcc" diff --git a/z b/zz rename from z rename to zz @@ -653,7 +653,7 @@ $ hg mv zz z $ hg ci --amend -m 'merge bar (undo rename)' $ hg log --config diff.git=1 -pr . - changeset: 26:7fb89c461f81 + changeset: 26:16df3eb8b415 tag: tip parent: 22:30d96aeaf27b parent: 21:1aa437659d19 @@ -668,11 +668,11 @@ --- a/cc +++ b/cc @@ -1,1 +1,5 @@ - +<<<<<<< local + +<<<<<<< local: 30d9 - "aa" dd +======= +cc - +>>>>>>> other + +>>>>>>> other: 1aa4 bar - "aazzcc" $ hg debugrename z z not renamed @@ -689,9 +689,9 @@ $ echo aa >> aaa $ hg ci -m 'merge bar again' $ hg log --config diff.git=1 -pr . - changeset: 28:982d7a34ffee + changeset: 28:1c1f11b6e28a tag: tip - parent: 26:7fb89c461f81 + parent: 26:16df3eb8b415 parent: 27:4c94d5bc65f5 user: test date: Thu Jan 01 00:00:00 1970 +0000 @@ -724,9 +724,9 @@ $ hg mv aaa aa $ hg ci --amend -m 'merge bar again (undo rename)' $ hg log --config diff.git=1 -pr . - changeset: 30:522688c0e71b + changeset: 30:02f0bc7df731 tag: tip - parent: 26:7fb89c461f81 + parent: 26:16df3eb8b415 parent: 27:4c94d5bc65f5 user: test date: Thu Jan 01 00:00:00 1970 +0000 @@ -764,9 +764,9 @@ use (c)hanged version or (d)elete? c $ hg ci -m 'merge bar (with conflicts)' $ hg log --config diff.git=1 -pr . - changeset: 33:5f9904c491b8 + changeset: 33:961b6a107905 tag: tip - parent: 32:01780b896f58 + parent: 32:a392542cd00f parent: 31:67db8847a540 user: test date: Thu Jan 01 00:00:00 1970 +0000 @@ -776,9 +776,9 @@ $ hg rm aa $ hg ci --amend -m 'merge bar (with conflicts, amended)' $ hg log --config diff.git=1 -pr . - changeset: 35:6ce0c89781a3 + changeset: 35:996b67573eeb tag: tip - parent: 32:01780b896f58 + parent: 32:a392542cd00f parent: 31:67db8847a540 user: test date: Thu Jan 01 00:00:00 1970 +0000 diff --git a/tests/test-conflict.t b/tests/test-conflict.t --- a/tests/test-conflict.t +++ b/tests/test-conflict.t @@ -10,7 +10,7 @@ $ hg commit -m branch2 created new head - $ hg merge 1 + $ hg merge 1 --traceback merging a warning: conflicts during merge. merging a incomplete! (edit conflicts, then use 'hg resolve --mark') @@ -22,11 +22,11 @@ 32e80765d7fe+75234512624c+ tip $ cat a - <<<<<<< local + <<<<<<< local: 32e8 - "branch2" something else ======= something - >>>>>>> other + >>>>>>> other: 7523 - "branch1" $ hg status M a diff --git a/tests/test-keyword.t b/tests/test-keyword.t --- a/tests/test-keyword.t +++ b/tests/test-keyword.t @@ -1049,11 +1049,11 @@ [1] $ cat m $Id$ - <<<<<<< local + <<<<<<< local: 88a8 - "8bar" bar ======= foo - >>>>>>> other + >>>>>>> other: 85d2 - "simplemerge" resolve to local diff --git a/tests/test-merge-revert2.t b/tests/test-merge-revert2.t --- a/tests/test-merge-revert2.t +++ b/tests/test-merge-revert2.t @@ -57,11 +57,11 @@ @@ -1,3 +1,7 @@ added file1 another line of text - +<<<<<<< local + +<<<<<<< local: c3fa - "added file1 and file2" +changed file1 different +======= changed file1 - +>>>>>>> other + +>>>>>>> other: dfab - "changed file1" $ hg status M file1 diff --git a/tests/test-merge-tools.t b/tests/test-merge-tools.t --- a/tests/test-merge-tools.t +++ b/tests/test-merge-tools.t @@ -66,11 +66,11 @@ [1] $ aftermerge # cat f - <<<<<<< local + <<<<<<< local: ef83 - "revision 1" revision 1 ======= revision 2 - >>>>>>> other + >>>>>>> other: 0185 - "revision 2" space # hg stat M f diff --git a/tests/test-merge-types.t b/tests/test-merge-types.t --- a/tests/test-merge-types.t +++ b/tests/test-merge-types.t @@ -289,18 +289,18 @@ U h $ tellmeabout a a is a plain file with content: - <<<<<<< local + <<<<<<< local: 0139 - "2" 2 ======= 1 - >>>>>>> other + >>>>>>> other: 97e2 - "1" $ tellmeabout b b is a plain file with content: - <<<<<<< local + <<<<<<< local: 0139 - "2" 2 ======= 1 - >>>>>>> other + >>>>>>> other: 97e2 - "1" $ tellmeabout c c is a plain file with content: x @@ -344,18 +344,18 @@ [1] $ tellmeabout a a is a plain file with content: - <<<<<<< local + <<<<<<< local: 97e2 - "1" 1 ======= 2 - >>>>>>> other + >>>>>>> other: 0139 - "2" $ tellmeabout b b is an executable file with content: - <<<<<<< local + <<<<<<< local: 97e2 - "1" 1 ======= 2 - >>>>>>> other + >>>>>>> other: 0139 - "2" $ tellmeabout c c is an executable file with content: x diff --git a/tests/test-merge7.t b/tests/test-merge7.t --- a/tests/test-merge7.t +++ b/tests/test-merge7.t @@ -97,11 +97,11 @@ $ cat test.txt one - <<<<<<< local + <<<<<<< local: 50c3 - "Merge 1" two-point-five ======= two-point-one - >>>>>>> other + >>>>>>> other: 40d1 - "two -> two-point-one" three $ hg debugindex test.txt diff --git a/tests/test-shelve.t b/tests/test-shelve.t --- a/tests/test-shelve.t +++ b/tests/test-shelve.t @@ -210,11 +210,11 @@ +++ b/a/a @@ -1,2 +1,6 @@ a - +<<<<<<< local + +<<<<<<< local: * - "pending changes temporary commit" (glob) c +======= +a - +>>>>>>> other + +>>>>>>> other: * - "changes to '[mq]: second.patch'" (glob) diff --git a/b.rename/b b/b.rename/b new file mode 100644 --- /dev/null @@ -601,11 +601,11 @@ M f ? f.orig $ cat f - <<<<<<< local + <<<<<<< local: 5f6b - "pending changes temporary commit" g ======= f - >>>>>>> other + >>>>>>> other: 23b2 - "changes to 'commit stuff'" $ cat f.orig g $ hg unshelve --abort @@ -644,11 +644,11 @@ M f ? f.orig $ cat f - <<<<<<< local + <<<<<<< local: 6b56 - "intermediate other change" g ======= f - >>>>>>> other + >>>>>>> other: 23b2 - "changes to 'commit stuff'" $ cat f.orig g $ hg unshelve --abort diff --git a/tests/test-subrepo.t b/tests/test-subrepo.t --- a/tests/test-subrepo.t +++ b/tests/test-subrepo.t @@ -298,11 +298,11 @@ should conflict $ cat t/t - <<<<<<< local + <<<<<<< local: 20a0 - "10" conflict ======= t3 - >>>>>>> other + >>>>>>> other: 7af3 - "7" clone
# HG changeset patch # User Durham Goode <durham@fb.com> # Date 1399593022 25200 # Thu May 08 16:50:22 2014 -0700 # Node ID 69cf8247537f72bf864d4799270329a7ef00b04f # Parent 7ff0390bd790e788b91b85dee7fecd00d588ba4f merge: add conflict marker formatter Adds a conflict marker formatter that can produce custom conflict marker descriptions. It can be set via ui.conflictmarkertemplate. The default format is similar to: {shortest(node)} {tag} {branch} {bookmarks} - "{desc|firstline}" And renders as: contextblahblah <<<<<<< local: 50c3 - "Merge 1" line from my changes ======= line from the other changes >>>>>>> other: 40d1 - "two -> two-point-one" morecontextblahblah