[PATCH 2 of 8 RFC] merge: move prompts out of manifestmerge into a separate phase
Laurens Holst
laurens.nospam at grauw.nl
Wed Dec 21 19:45:52 UTC 2011
# HG changeset patch
# User Laurens Holst <laurens.hg at grauw.nl>
# Date 1324436157 -3600
# Node ID 41d3bb4d1ef5bdc3a68214123da13f7c7935898f
# Parent 4cff963c895a6465b04a5c6a9e0a207c966e2dcb
merge: move prompts out of manifestmerge into a separate phase
This is done in preparation for guarding against prompts.
diff -r 4cff963c895a -r 41d3bb4d1ef5 mercurial/merge.py
--- a/mercurial/merge.py Wed Dec 21 00:19:35 2011 +0100
+++ b/mercurial/merge.py Wed Dec 21 03:55:57 2011 +0100
@@ -156,15 +156,7 @@
if m == n: # flags agree
return m # unchanged
if m and n and not a: # flags set, don't agree, differ from parent
- r = repo.ui.promptchoice(
- _(" conflicting flags for %s\n"
- "(n)one, e(x)ec or sym(l)ink?") % f,
- (_("&None"), _("E&xec"), _("Sym&link")), 0)
- if r == 1:
- return "x" # Exec
- if r == 2:
- return "l" # Symlink
- return ""
+ return "pf" # prompt for flags
if m and m != a: # changed from a to m
return m
if n and n != a: # changed from a to n
@@ -230,13 +222,7 @@
f, f2, f, fmerge(f, f2, f2), False)
elif f in ma: # clean, a different, no remote
if n != ma[f]:
- if repo.ui.promptchoice(
- _(" local changed %s which remote deleted\n"
- "use (c)hanged version or (d)elete?") % f,
- (_("&Changed"), _("&Delete")), 0):
- act("prompt delete", "r", f)
- else:
- act("prompt keep", "a", f)
+ act("prompt delete", "pr", f)
elif n[20:] == "a": # added, no remote
act("remote deleted", "f", f)
elif n[20:] != "u":
@@ -261,17 +247,63 @@
elif f not in ma:
act("remote created", "g", f, m2.flags(f))
elif n != ma[f]:
- if repo.ui.promptchoice(
- _("remote changed %s which local deleted\n"
- "use (c)hanged version or leave (d)eleted?") % f,
- (_("&Changed"), _("&Deleted")), 0) == 0:
- act("prompt recreating", "g", f, m2.flags(f))
+ act("prompt recreating", "pg", f, m2.flags(f))
return action
def actionkey(a):
return a[1] == 'r' and -1 or 0, a
+def promptquestions(repo, action):
+ "prompt for actions that need user input, and update the actions"
+
+ newaction = []
+
+ def promptflags(f):
+ r = repo.ui.promptchoice(
+ _(" conflicting flags for %s\n"
+ "(n)one, e(x)ec or sym(l)ink?") % f,
+ (_("&None"), _("E&xec"), _("Sym&link")), 0)
+ if r == 1:
+ return "x" # Exec
+ if r == 2:
+ return "l" # Symlink
+ return ""
+
+ def act(msg, m, f, *args):
+ repo.ui.debug(" %s: %s -> %s\n" % (f, msg, m))
+ newaction.append((f, m) + args)
+
+ for a in action:
+ f, m = a[:2]
+ if m == "pr":
+ if repo.ui.promptchoice(
+ _(" local changed %s which remote deleted\n"
+ "use (c)hanged version or (d)elete?") % f,
+ (_("&Changed"), _("&Delete")), 0):
+ act("prompted delete", "r", f)
+ else:
+ act("prompted keep", "a", f)
+
+ elif m == "pg":
+ if repo.ui.promptchoice(
+ _("remote changed %s which local deleted\n"
+ "use (c)hanged version or leave (d)eleted?") % f,
+ (_("&Changed"), _("&Deleted")), 0) == 0:
+ act("prompted recreating", "g", f, a[2])
+ # else swallow
+
+ elif (m == "e" or m == "g") and a[2] == "pf":
+ act("prompted flags", m, f, promptflags(f))
+
+ elif m == "m" and a[4] == "pf":
+ act("prompted flags", m, f, a[2], a[3], promptflags(f), a[5])
+
+ else:
+ newaction.append(a)
+
+ return newaction
+
def applyupdates(repo, action, wctx, mctx, actx, overwrite):
"""apply the merge action list to the working directory
@@ -568,6 +600,9 @@
if guard and not isguardsafe(repo, action, wc, p2, pa):
raise util.Abort(_("update touches modified files"))
+ ### user prompt phase
+ action = promptquestions(repo, action)
+
### apply phase
if not branchmerge: # just jump to the new rev
fp1, fp2, xp1, xp2 = fp2, nullid, xp2, ''
More information about the Mercurial-devel
mailing list