[PATCH 7 of 8] merge: extract method for checking for conflicting untracked file

Martin von Zweigbergk martinvonz at google.com
Mon Dec 22 18:33:41 CST 2014


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1418543542 28800
#      Sat Dec 13 23:52:22 2014 -0800
# Node ID 5fd29e7725ee24e77194b781b701dfc4d1810e9d
# Parent  a194174c25fd329be8a74f5b10586187c414f85d
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.

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -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
 


More information about the Mercurial-devel mailing list