[PATCH 19 of 19] mq: use the editor gotten by "getcommiteditor()" instead of "ui.edit()" (qrefresh/qfold)

Siddharth Agarwal sid at less-broken.com
Fri May 16 12:21:05 CDT 2014


On 05/10/2014 09:08 AM, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
> # Date 1399736976 -32400
> #      Sun May 11 00:49:36 2014 +0900
> # Node ID ef339ee3b9713c68705ec530bd83909196e5aa3e
> # Parent  87dc4e9b6d12c91c485c33ce32043ac41dd80fcf
> mq: use the editor gotten by "getcommiteditor()" instead of "ui.edit()" (qrefresh/qfold)

These patches look great and have been queued, thanks.

>
> This patch also replaces "editor = False" by "editor =
> cmdutil.getcommiteditor()", because:
>
>    - it allows to hook commit message determination easily, even in the
>      case without "--edit"
>
>    - it avoids regression (or additional care) around saving
>      "last-message.txt", even if MQ's "newcommit()" changes its
>      implementation logic from "localrepository.commit" to
>      "localrepository.commitctx" with "memctx" in the future
>
>      to save commit message into "last-messge.txt" with "memctx",
>      "editor" should be valid function.
>
> diff --git a/hgext/mq.py b/hgext/mq.py
> --- a/hgext/mq.py
> +++ b/hgext/mq.py
> @@ -1656,17 +1656,18 @@
>                   # might be nice to attempt to roll back strip after this
>   
>                   defaultmsg = "[mq]: %s" % patchfn
> -                editor = False
> +                editor = cmdutil.getcommiteditor()
>                   if edit:
> -                    def desceditor(repo, ctx, subs):
> -                        desc = self.ui.edit(ctx.description() + "\n",
> -                                            ctx.user())
> +                    def finishdesc(desc):
>                           if desc.rstrip():
>                               ph.setmessage(desc)
>                               return desc
>                           return defaultmsg
> +                    # i18n: this message is shown in editor with "HG: " prefix
> +                    extramsg = _('Leave message empty to use default message.')
> +                    editor = cmdutil.getcommiteditor(finishdesc=finishdesc,
> +                                                     extramsg=extramsg)
>                       message = msg or "\n".join(ph.message)
> -                    editor = desceditor
>                   elif not msg:
>                       if not ph.message:
>                           message = defaultmsg
> diff --git a/tests/test-mq-qfold.t b/tests/test-mq-qfold.t
> --- a/tests/test-mq-qfold.t
> +++ b/tests/test-mq-qfold.t
> @@ -20,6 +20,8 @@
>     $ hg qnew -f p3
>   
>   Fold in the middle of the queue:
> +(this tests also that editor is not invoked if '--edit' is not
> +specified)
>   
>     $ hg qpop p1
>     popping p3
> @@ -34,7 +36,7 @@
>      a
>     +a
>   
> -  $ hg qfold p2
> +  $ HGEDITOR=cat hg qfold p2
>     $ grep git .hg/patches/p1 && echo 'git patch found!'
>     [1]
>   
> @@ -215,6 +217,15 @@
>     $ HGEDITOR="sh $TESTTMP/editor.sh" hg qfold -e p3
>     ==== before editing
>     original message
> +
> +
> +  HG: Enter commit message.  Lines beginning with 'HG:' are removed.
> +  HG: Leave message empty to use default message.
> +  HG: --
> +  HG: user: test
> +  HG: branch 'default'
> +  HG: added aa
> +  HG: changed a
>     ====
>     transaction abort!
>     rollback completed
> @@ -225,7 +236,26 @@
>     $ cat .hg/last-message.txt
>     original message
>     
> +
> +
>     test saving last-message.txt
>   
> +(confirm whether files listed up in the commit message editing are correct)
> +
> +  $ cat >> .hg/hgrc <<EOF
> +  > [hooks]
> +  > pretxncommit.unexpectedabort =
> +  > EOF
> +  $ hg status -u | while read f; do rm ${f}; done
> +  $ hg revert --no-backup -q --all
> +  $ hg qpush -q git
> +  now at: git
> +  $ hg qpush -q --move p3
> +  now at: p3
> +
> +  $ hg status --rev "git^1" --rev . -arm
> +  M a
> +  A aa
> +
>     $ cd ..
>   
> diff --git a/tests/test-mq-qrefresh-replace-log-message.t b/tests/test-mq-qrefresh-replace-log-message.t
> --- a/tests/test-mq-qrefresh-replace-log-message.t
> +++ b/tests/test-mq-qrefresh-replace-log-message.t
> @@ -6,6 +6,8 @@
>     $ hg qinit
>   
>   Should fail if no patches applied
> +(this tests also that editor is not invoked if '--edit' is not
> +specified)
>   
>     $ hg qrefresh
>     no patches applied
> @@ -16,7 +18,7 @@
>     $ hg qnew -m "First commit message" first-patch
>     $ echo aaaa > file
>     $ hg add file
> -  $ hg qrefresh
> +  $ HGEDITOR=cat hg qrefresh
>   
>   Should display 'First commit message'
>   
> @@ -126,10 +128,20 @@
>     > EOF
>   
>     $ rm -f .hg/last-message.txt
> +  $ hg status --rev "second-patch^1" -arm
> +  A file2
>     $ HGEDITOR="sh $TESTTMP/editor.sh" hg qrefresh -e
>     ==== before editing
>     Fifth commit message
>      This is the 5th log message
> +
> +
> +  HG: Enter commit message.  Lines beginning with 'HG:' are removed.
> +  HG: Leave message empty to use default message.
> +  HG: --
> +  HG: user: test
> +  HG: branch 'default'
> +  HG: added file2
>     ====
>     transaction abort!
>     rollback completed
> @@ -141,4 +153,6 @@
>     Fifth commit message
>      This is the 5th log message
>     
> +
> +
>     test saving last-message.txt
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel



More information about the Mercurial-devel mailing list