Patchwork [4,of,5] import: refactor exact handling and split between exact and usenode

login
register
mail settings
Submitter timeless@mozdev.org
Date Dec. 30, 2015, 10:47 p.m.
Message ID <a2350aab89ddc6ddffc5.1451515670@waste.org>
Download mbox | patch
Permalink /patch/12430/
State Superseded
Headers show

Comments

timeless@mozdev.org - Dec. 30, 2015, 10:47 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1451509773 0
#      Wed Dec 30 21:09:33 2015 +0000
# Node ID a2350aab89ddc6ddffc556f8ecb0c2398ad348d8
# Parent  0179b3fbf17aa787dce200d03d2deb924246fda5
import: refactor exact handling and split between exact and usenode

The usenode flag prepares for introducing an inexact,
whereas exact promises to error if the commit isn't perfect.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -887,6 +887,8 @@ 
         return (None, None, False)
 
     rejects = False
+    exact = opts.get('exact')
+    usenode = exact
 
     try:
         cmdline_message = logmessage(ui, opts)
@@ -903,7 +905,7 @@ 
 
         if len(parents) == 1:
             parents.append(repo[nullid])
-        if opts.get('exact'):
+        if usenode:
             if not nodeid or not p1:
                 raise error.Abort(_('not a Mercurial patch'))
             p1 = repo[p1]
@@ -933,7 +935,7 @@ 
             if p2 != parents[1]:
                 repo.setparents(p1.node(), p2.node())
 
-            if opts.get('exact') or importbranch:
+            if usenode or importbranch:
                 repo.dirstate.setbranch(branch or 'default')
 
             partial = opts.get('partial', False)
@@ -952,7 +954,7 @@ 
                 if message:
                     msgs.append(message)
             else:
-                if opts.get('exact') or p2:
+                if usenode or p2:
                     # If you got here, you either use --force and know what
                     # you are doing or used --exact or a merge patch while
                     # being updated to its first parent.
@@ -960,7 +962,7 @@ 
                 else:
                     m = scmutil.matchfiles(repo, files or [])
                 editform = mergeeditform(repo[None], 'import.normal')
-                if opts.get('exact'):
+                if usenode:
                     editor = None
                 else:
                     editor = getcommiteditor(editform=editform, **opts)
@@ -979,7 +981,7 @@ 
                 finally:
                     repo.ui.restoreconfig(allowemptyback)
         else:
-            if opts.get('exact') or importbranch:
+            if usenode or importbranch:
                 branch = branch or 'default'
             else:
                 branch = p1.branch()
@@ -991,7 +993,7 @@ 
                                     files, eolmode=None)
                 except patch.PatchError as e:
                     raise error.Abort(str(e))
-                if opts.get('exact'):
+                if usenode:
                     editor = None
                 else:
                     editor = getcommiteditor(editform='import.bypass')
@@ -1004,11 +1006,11 @@ 
                 n = memctx.commit()
             finally:
                 store.close()
-        if opts.get('exact') and nocommit:
+        if usenode and nocommit:
             # --exact with --no-commit is still useful in that it does merge
             # and branch bits
             ui.warn(_("warning: can't check exact import with --no-commit\n"))
-        elif opts.get('exact') and hex(n) != nodeid:
+        elif exact and hex(n) != nodeid:
             raise error.Abort(_('patch is damaged or loses information'))
         msg = _('applied to working directory')
         if n: