changeset 23655:79235b46062c

merge: extract method for checking for conflicting untracked file Now that the functionality is collected in one place, let's extract it to a method.
author Martin von Zweigbergk <martinvonz@google.com>
date Sat, 13 Dec 2014 23:52:22 -0800
parents 9d56be47b5d6
children d3e137c91f94
files mercurial/merge.py
diffstat 1 files changed, 35 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/merge.py	Mon Dec 15 16:45:19 2014 -0800
+++ b/mercurial/merge.py	Sat Dec 13 23:52:22 2014 -0800
@@ -305,6 +305,40 @@
         and repo.dirstate.normalize(f) not in repo.dirstate
         and mctx[f2].cmp(wctx[f]))
 
+def _checkunknownfiles(repo, wctx, mctx, force, actions):
+    """
+    Considers any actions that care about the presence of conflicting unknown
+    files. For some actions, the result is to abort; for others, it is to
+    choose a different action.
+    """
+    aborts = []
+    if not force:
+        for f, (m, args, msg) in actions.iteritems():
+            if m in ('c', 'dc'):
+                if _checkunknownfile(repo, wctx, mctx, f):
+                    aborts.append(f)
+            elif m == 'dg':
+                if _checkunknownfile(repo, wctx, mctx, f, args[0]):
+                    aborts.append(f)
+
+    for f in sorted(aborts):
+        repo.ui.warn(_("%s: untracked file differs\n") % f)
+    if aborts:
+        raise util.Abort(_("untracked files in working directory differ "
+                           "from files in requested revision"))
+
+    for f, (m, args, msg) in actions.iteritems():
+        if m == 'c':
+            actions[f] = ('g', args, msg)
+        elif m == 'cm':
+            fl2, anc = args
+            different = _checkunknownfile(repo, wctx, mctx, f)
+            if different:
+                actions[f] = ('m', (f, f, None, False, anc),
+                              "remote differs from untracked local")
+            else:
+                actions[f] = ('g', (fl2,), "remote created")
+
 def _forgetremoved(wctx, mctx, branchmerge):
     """
     Forget removed files
@@ -509,33 +543,7 @@
                 else:
                     actions[f] = ('dc', (fl2,), "prompt deleted/changed")
 
-    aborts = []
-    if not force:
-        for f, (m, args, msg) in actions.iteritems():
-            if m in ('c', 'dc'):
-                if _checkunknownfile(repo, wctx, p2, f):
-                    aborts.append(f)
-            elif m == 'dg':
-                if _checkunknownfile(repo, wctx, p2, f, args[0]):
-                    aborts.append(f)
-
-    for f in sorted(aborts):
-        repo.ui.warn(_("%s: untracked file differs\n") % f)
-    if aborts:
-        raise util.Abort(_("untracked files in working directory differ "
-                           "from files in requested revision"))
-
-    for f, (m, args, msg) in actions.iteritems():
-        if m == 'c':
-            actions[f] = ('g', args, msg)
-        elif m == 'cm':
-            fl2, anc = args
-            different = _checkunknownfile(repo, wctx, p2, f)
-            if different:
-                actions[f] = ('m', (f, f, None, False, anc),
-                              "remote differs from untracked local")
-            else:
-                actions[f] = ('g', (fl2,), "remote created")
+    _checkunknownfiles(repo, wctx, p2, force, actions)
 
     return actions, diverge, renamedelete