Patchwork [2,of,3] import: avoid editor invocation at importing with "--exact" for exact-ness

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Aug. 23, 2014, 2:17 p.m.
Message ID <3aefe8a4d8172c2733dd.1408803452@feefifofum>
Download mbox | patch
Permalink /patch/5560/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - Aug. 23, 2014, 2:17 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1408802630 -32400
#      Sat Aug 23 23:03:50 2014 +0900
# Node ID 3aefe8a4d8172c2733dd0fe3c48d733231aa76fc
# Parent  cbf0173bbdd7e3c22a82ff9531c4b77121c9c78f
import: avoid editor invocation at importing with "--exact" for exact-ness

Before this patch, external editor is invoked when imported patch has
no commit message, even if "--exact" is specified. Then, exact-ness is
broken, because empty commit message causes failure of committing.

This patch avoids editor invocation at importing with "--exact" for
exact-ness, because commit message in the patch should be kept as it
is in such case, even if it is empty.
Augie Fackler - Aug. 23, 2014, 7:22 p.m.
On Sat, Aug 23, 2014 at 11:17:32PM +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1408802630 -32400
> #      Sat Aug 23 23:03:50 2014 +0900
> # Node ID 3aefe8a4d8172c2733dd0fe3c48d733231aa76fc
> # Parent  cbf0173bbdd7e3c22a82ff9531c4b77121c9c78f
> import: avoid editor invocation at importing with "--exact" for exact-ness

Queued these two, thanks. I'll send some other comments on the third one.

>
> Before this patch, external editor is invoked when imported patch has
> no commit message, even if "--exact" is specified. Then, exact-ness is
> broken, because empty commit message causes failure of committing.
>
> This patch avoids editor invocation at importing with "--exact" for
> exact-ness, because commit message in the patch should be kept as it
> is in such case, even if it is empty.
>
> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py
> +++ b/mercurial/cmdutil.py
> @@ -688,7 +688,10 @@
>                  else:
>                      m = scmutil.matchfiles(repo, files or [])
>                  editform = mergeeditform(repo[None], 'import.normal')
> -                editor = getcommiteditor(editform=editform, **opts)
> +                if opts.get('exact'):
> +                    editor = None
> +                else:
> +                    editor = getcommiteditor(editform=editform, **opts)
>                  n = repo.commit(message, opts.get('user') or user,
>                                  opts.get('date') or date, match=m,
>                                  editor=editor, force=partial)
> @@ -705,7 +708,10 @@
>                                      files, eolmode=None)
>                  except patch.PatchError, e:
>                      raise util.Abort(str(e))
> -                editor = getcommiteditor(editform='import.bypass')
> +                if opts.get('exact'):
> +                    editor = None
> +                else:
> +                    editor = getcommiteditor(editform='import.bypass')
>                  memctx = context.makememctx(repo, (p1.node(), p2.node()),
>                                              message,
>                                              opts.get('user') or user,
> diff --git a/tests/test-import-bypass.t b/tests/test-import-bypass.t
> --- a/tests/test-import-bypass.t
> +++ b/tests/test-import-bypass.t
> @@ -226,6 +226,25 @@
>
>    $ cd ..
>
> +Test avoiding editor invocation at applying the patch with --exact
> +even if commit message is empty
> +
> +  $ cd repo-options
> +
> +  $ echo a >> a
> +  $ hg commit -m ' '
> +  $ hg tip -T "{node}\n"
> +  1b77bc7d1db9f0e7f1716d515b630516ab386c89
> +  $ hg export -o ../empty-log.diff .
> +  $ hg update -q -C ".^1"
> +  $ hg --config extensions.strip= strip -q tip
> +  $ HGEDITOR=cat hg import --exact --bypass ../empty-log.diff
> +  applying ../empty-log.diff
> +  $ hg tip -T "{node}\n"
> +  1b77bc7d1db9f0e7f1716d515b630516ab386c89
> +
> +  $ cd ..
> +
>  #if symlink execbit
>
>  Test complicated patch with --exact
> diff --git a/tests/test-import.t b/tests/test-import.t
> --- a/tests/test-import.t
> +++ b/tests/test-import.t
> @@ -107,6 +107,22 @@
>    HG: changed a
>    abort: empty commit message
>    [255]
> +
> +Test avoiding editor invocation at applying the patch with --exact,
> +even if commit message is empty
> +
> +  $ echo a >> b/a
> +  $ hg --cwd b commit -m ' '
> +  $ hg --cwd b tip -T "{node}\n"
> +  d8804f3f5396d800812f579c8452796a5993bdb2
> +  $ hg --cwd b export -o ../empty-log.diff .
> +  $ hg --cwd b update -q -C ".^1"
> +  $ hg --cwd b --config extensions.strip= strip -q tip
> +  $ HGEDITOR=cat hg --cwd b import --exact ../empty-log.diff
> +  applying ../empty-log.diff
> +  $ hg --cwd b tip -T "{node}\n"
> +  d8804f3f5396d800812f579c8452796a5993bdb2
> +
>    $ rm -r b
>
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -688,7 +688,10 @@ 
                 else:
                     m = scmutil.matchfiles(repo, files or [])
                 editform = mergeeditform(repo[None], 'import.normal')
-                editor = getcommiteditor(editform=editform, **opts)
+                if opts.get('exact'):
+                    editor = None
+                else:
+                    editor = getcommiteditor(editform=editform, **opts)
                 n = repo.commit(message, opts.get('user') or user,
                                 opts.get('date') or date, match=m,
                                 editor=editor, force=partial)
@@ -705,7 +708,10 @@ 
                                     files, eolmode=None)
                 except patch.PatchError, e:
                     raise util.Abort(str(e))
-                editor = getcommiteditor(editform='import.bypass')
+                if opts.get('exact'):
+                    editor = None
+                else:
+                    editor = getcommiteditor(editform='import.bypass')
                 memctx = context.makememctx(repo, (p1.node(), p2.node()),
                                             message,
                                             opts.get('user') or user,
diff --git a/tests/test-import-bypass.t b/tests/test-import-bypass.t
--- a/tests/test-import-bypass.t
+++ b/tests/test-import-bypass.t
@@ -226,6 +226,25 @@ 
 
   $ cd ..
 
+Test avoiding editor invocation at applying the patch with --exact
+even if commit message is empty
+
+  $ cd repo-options
+
+  $ echo a >> a
+  $ hg commit -m ' '
+  $ hg tip -T "{node}\n"
+  1b77bc7d1db9f0e7f1716d515b630516ab386c89
+  $ hg export -o ../empty-log.diff .
+  $ hg update -q -C ".^1"
+  $ hg --config extensions.strip= strip -q tip
+  $ HGEDITOR=cat hg import --exact --bypass ../empty-log.diff
+  applying ../empty-log.diff
+  $ hg tip -T "{node}\n"
+  1b77bc7d1db9f0e7f1716d515b630516ab386c89
+
+  $ cd ..
+
 #if symlink execbit
 
 Test complicated patch with --exact
diff --git a/tests/test-import.t b/tests/test-import.t
--- a/tests/test-import.t
+++ b/tests/test-import.t
@@ -107,6 +107,22 @@ 
   HG: changed a
   abort: empty commit message
   [255]
+
+Test avoiding editor invocation at applying the patch with --exact,
+even if commit message is empty
+
+  $ echo a >> b/a
+  $ hg --cwd b commit -m ' '
+  $ hg --cwd b tip -T "{node}\n"
+  d8804f3f5396d800812f579c8452796a5993bdb2
+  $ hg --cwd b export -o ../empty-log.diff .
+  $ hg --cwd b update -q -C ".^1"
+  $ hg --cwd b --config extensions.strip= strip -q tip
+  $ HGEDITOR=cat hg --cwd b import --exact ../empty-log.diff
+  applying ../empty-log.diff
+  $ hg --cwd b tip -T "{node}\n"
+  d8804f3f5396d800812f579c8452796a5993bdb2
+
   $ rm -r b