Patchwork [2,of,3,checkunknown] merge: determine what untracked conflicts cause warns and aborts separately

login
register
mail settings
Submitter Siddharth Agarwal
Date Jan. 13, 2016, 2:40 a.m.
Message ID <e66b50d246a8d2c1e864.1452652845@dev666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/12741/
State Accepted
Headers show

Comments

Siddharth Agarwal - Jan. 13, 2016, 2:40 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1452651427 28800
#      Tue Jan 12 18:17:07 2016 -0800
# Node ID e66b50d246a8d2c1e8649b6a4067070e241e0d64
# Parent  e3ac8a047a74694082be679ac80a1b7ed86387fd
# Available At http://42.netv6.net/sid0-wip/hg/
#              hg pull http://42.netv6.net/sid0-wip/hg/ -r e66b50d246a8
merge: determine what untracked conflicts cause warns and aborts separately

This is written in a somewhat weird style, but it's designed for code reuse in
an upcoming patch.

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -583,6 +583,14 @@  def _checkunknownfiles(repo, wctx, mctx,
     """
     conflicts = set()
     if not force:
+        abortconflicts = set()
+        warnconflicts = set()
+        def collectconflicts(conflicts, config):
+            if config == 'abort':
+                abortconflicts.update(conflicts)
+            elif config == 'warn':
+                warnconflicts.update(conflicts)
+
         config = _getcheckunknownconfig(repo, 'merge', 'checkunknown')
         for f, (m, args, msg) in actions.iteritems():
             if m in ('c', 'dc'):
@@ -592,15 +600,15 @@  def _checkunknownfiles(repo, wctx, mctx,
                 if _checkunknownfile(repo, wctx, mctx, f, args[0]):
                     conflicts.add(f)
 
-        if config == 'abort':
-            for f in sorted(conflicts):
-                repo.ui.warn(_("%s: untracked file differs\n") % f)
-            if conflicts:
-                raise error.Abort(_("untracked files in working directory "
-                                    "differ from files in requested revision"))
-        elif config == 'warn':
-            for f in sorted(conflicts):
-                repo.ui.warn(_("%s: replacing untracked file\n") % f)
+        collectconflicts(conflicts, config)
+        for f in sorted(abortconflicts):
+            repo.ui.warn(_("%s: untracked file differs\n") % f)
+        if abortconflicts:
+            raise error.Abort(_("untracked files in working directory "
+                                "differ from files in requested revision"))
+
+        for f in sorted(warnconflicts):
+            repo.ui.warn(_("%s: replacing untracked file\n") % f)
 
     for f, (m, args, msg) in actions.iteritems():
         backup = f in conflicts