Patchwork [4,of,5,V3] transplant: use "ui.promptchoice()" for interactive transplant

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Dec. 1, 2013, 4:01 p.m.
Message ID <e7c0437539f56541c441.1385913716@juju>
Download mbox | patch
Permalink /patch/3196/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - Dec. 1, 2013, 4:01 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1385913030 -32400
#      Mon Dec 02 00:50:30 2013 +0900
# Node ID e7c0437539f56541c44150896bfb182da532fa7b
# Parent  d3a08ba9a1e7a3e344435faa23f1d44a02c4dbd4
transplant: use "ui.promptchoice()" for interactive transplant

Before this patch, transplant extension uses "ui.prompt()" for
interactive transplant, and has to check whether user response
returned by "ui.prompt()" is valid or not in own code.

In addition to it, transplant extension uses response characters
(e.g. "y", "n", and so on) directly in own code, and this disallows to
use another response characters by translation, even though the help
shown by '?'  typing is translatable.

This patch uses "ui.promptchoice()" instead of "ui.prompt()" to
resolve problems above.

Patch

diff --git a/hgext/transplant.py b/hgext/transplant.py
--- a/hgext/transplant.py
+++ b/hgext/transplant.py
@@ -463,11 +463,19 @@ 
     displayer = cmdutil.show_changeset(ui, repo, opts)
     transplants = []
     merges = []
+    prompt = _('apply changeset? [ynmpcq?]:'
+               '$$ &yes, transplant this changeset'
+               '$$ &no, skip this changeset'
+               '$$ &merge at this changeset'
+               '$$ show &patch'
+               '$$ &commit selected changesets'
+               '$$ &quit and cancel transplant'
+               '$$ &? (show this help)')
     for node in nodes:
         displayer.show(repo[node])
         action = None
         while not action:
-            action = ui.prompt(_('apply changeset? [ynmpcq?]:'))
+            action = 'ynmpcq?'[ui.promptchoice(prompt)]
             if action == '?':
                 browsehelp(ui)
                 action = None
@@ -476,9 +484,6 @@ 
                 for chunk in patch.diff(repo, parent, node):
                     ui.write(chunk)
                 action = None
-            elif action not in ('y', 'n', 'm', 'c', 'q'):
-                ui.write(_('no such option\n'))
-                action = None
         if action == 'y':
             transplants.append(node)
         elif action == 'm':
diff --git a/tests/test-transplant.t b/tests/test-transplant.t
--- a/tests/test-transplant.t
+++ b/tests/test-transplant.t
@@ -492,7 +492,7 @@ 
   > q
   > EOF
   1:d11e3596cc1a
-  apply changeset? [ynmpcq?]: no such option
+  apply changeset? [ynmpcq?]: unrecognized response
   apply changeset? [ynmpcq?]: y: transplant this changeset
   n: skip this changeset
   m: merge at this changeset