# HG changeset patch
# User Simon Farnsworth
# Date 1471006902 25200
# Fri Aug 12 06:01:42 2016 -0700
# Node ID 6d3af00243808b1be9f27a5545be0fce0e43d1f2
# Parent 37b6f0ec6241a62de90737409458cd622e2fac0d
merge: use labels in prompts to the user
Now that we persist the labels, we can consistently use the labels in
prompts for the user without risk of confusion. This changes a huge amount
of command output:
This means that merge prompts like:
no tool found to merge a
keep (l)ocal, take (o)ther, or leave (u)nresolved? u
and
remote changed a which local deleted
use (c)hanged version, leave (d)eleted, or leave (u)nresolved? c
become:
no tool found to merge a
keep (l)ocal [working copy], take (o)ther [destination], or leave
(u)nresolved? u
and
remote [source] changed a which local [dest] deleted
use (c)hanged version, leave (d)eleted, or leave (u)nresolved? c
where "working copy" and "destination" were supplied by the command that
requested the merge as labels for conflict markers, and thus should be
human-friendly.
diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -230,50 +230,56 @@
util.writefile(file, newdata)
@internaltool('prompt', nomerge)
-def _iprompt(repo, mynode, orig, fcd, fco, fca, toolconf):
+def _iprompt(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None):
"""Asks the user which of the local `p1()` or the other `p2()` version to
keep as the merged version."""
ui = repo.ui
fd = fcd.path()
+prompts = partextras(labels)
+prompts['fd'] = fd
try:
if fco.isabsent():
index = ui.promptchoice(
-_("local changed %s which remote deleted\n"
+_("local%(l)s changed %(fd)s which remote%(o)s deleted\n"
"use (c)hanged version, (d)elete, or leave (u)nresolved?"
- "$$ $$ $$ ") % fd, 2)
+ "$$ $$ $$ ") % prompts, 2)
choice = ['local', 'other', 'unresolved'][index]
elif fcd.isabsent():
index = ui.promptchoice(
-_("remote changed %s which local deleted\n"
+_("remote%(o)s changed %(fd)s which local%(l)s deleted\n"
"use (c)hanged version, leave (d)eleted, or "
"leave (u)nresolved?"
- "$$ $$ $$ ") % fd, 2)
+ "$$ $$ $$ ") % prompts, 2)
choice = ['other', 'local', 'unresolved'][index]
else:
index = ui.promptchoice(
-_("no tool found to merge %s\n"
- "keep (l)ocal, take (o)ther, or leave (u)nresolved?"
- "$$ $$ $$ ") % fd, 2)
+_("no tool found to merge %(fd)s\n"
+ "keep (l)ocal%(l)s, take (o)ther%(o)s, or leave
(u)nresolved?"
+ "$$ $$ $$ ") % prompts, 2)
choice = ['local', 'other', 'unresolved'][index]
if choice == 'other':
-return _iother(repo, mynode, orig, fcd, fco, fca, toolconf)
+return _iother(repo, mynode, orig, fcd, fco, fca, toolconf,
+ labels)
elif choice == 'local':
-return _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf)
+return _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf,
+ labels)
elif choice == 'unresolved':
-return _ifail(repo, mynode, orig, fcd, fco, fca, toolconf)
+return _ifail(repo, mynode, orig, fcd, fco, fca, toolconf,
+ labels)
except error.ResponseExpected:
ui.write("\n")
-return _ifail(repo, mynode, orig, fcd, fco, fca, toolconf)
+return _ifail(repo, mynode, orig, fcd, fco, fca, toolconf,
+ labels)
@internaltool('local', nomerge)
-def _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf):
+def _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None):
"""Uses the local `p1()` version of files as the merged version."""
return 0, fcd.isabsent()
@internaltool('other', nomerge)
-def _iother(repo, mynode, orig, fcd, fco, fca, toolconf):
+def _iother(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None):
"""Uses the other `p2()` version of files as the merged version."""
if fco.isabsent():
# local changed, remote deleted -- 'deleted' picked
@@ -285,7 +291,7 @@
return 0, deleted
@internaltool('fail', nomerge)
-def _ifail(repo, mynode, orig, fcd, fco, fca, toolconf):
+def _ifail(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None):
"""
Rather than attempting to merge files that were modified on both
branches, it marks them as unresolved. The resolve command must be
@@ -537,6 +543,22 @@
newlabels.append(_formatconflictmarker(repo, ca, tmpl, labels[2], pad))
return newlabels
+def partextras(labels):
+"""Return