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

login
register
mail settings
Submitter timeless@mozdev.org
Date Dec. 31, 2015, 6:47 a.m.
Message ID <37c3ba3d2f3678daa543.1451544439@waste.org>
Download mbox | patch
Permalink /patch/12444/
State Changes Requested
Delegated to: Yuya Nishihara
Headers show

Comments

timeless@mozdev.org - Dec. 31, 2015, 6:47 a.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1451509773 0
#      Wed Dec 30 21:09:33 2015 +0000
# Node ID 37c3ba3d2f3678daa5439947f20d89496282d8b0
# Parent  f157383b6e9967a6c4a43ee30679f4eba6a1d6c5
import: refactor exact handling and split between exact and usenode

The usenode flag identifies when parentnode is being used.
Distinct from when exact might error if the commit isn't perfect.
Yuya Nishihara - Jan. 3, 2016, 2:47 p.m.
On Thu, 31 Dec 2015 00:47:19 -0600, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1451509773 0
> #      Wed Dec 30 21:09:33 2015 +0000
> # Node ID 37c3ba3d2f3678daa5439947f20d89496282d8b0
> # Parent  f157383b6e9967a6c4a43ee30679f4eba6a1d6c5
> import: refactor exact handling and split between exact and usenode
> 
> The usenode flag identifies when parentnode is being used.
> Distinct from when exact might error if the commit isn't perfect.
> 
> 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

I expected that these flags would have different values, but the next patch
didn't touch them. So I couldn't figure out the purpose of this patch.

  exact = opts.get('exact') and nodeid
  usenode = opts.get('exact')

>                  editform = mergeeditform(repo[None], 'import.normal')
> -                if opts.get('exact'):
> +                if usenode:
>                      editor = None
>                  else:
>                      editor = getcommiteditor(editform=editform, **opts)

I think editor is disabled because it needs an "exact" commit message,
not because of "usenode".

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 exact 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: