Patchwork [V3] record: display the running operation for recording commands

login
register
mail settings
Submitter Laurent Charignon
Date June 1, 2015, 5:38 p.m.
Message ID <1e379d0f63b47fba8887.1433180301@lcharignon-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/9428/
State Accepted
Headers show

Comments

Laurent Charignon - June 1, 2015, 5:38 p.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@fb.com>
# Date 1432767495 25200
#      Wed May 27 15:58:15 2015 -0700
# Node ID 1e379d0f63b47fba888724c5a90717c67c874552
# Parent  6084926366b979e81e5dcc84fa595965d4c07883
record: display the running operation for recording commands

This patch is part of a series of patches to change the recording ui to reflect
the operation currently running (commit, shelve, revert ...).
This patch makes the UI change to display the running operation on the UI.
It does not change any tests since we are not using the feature in any command
yet.
Yuya Nishihara - June 2, 2015, 12:54 p.m.
On Mon, 1 Jun 2015 10:38:21 -0700, Laurent Charignon wrote:
> # HG changeset patch
> # User Laurent Charignon <lcharignon@fb.com>
> # Date 1432767495 25200
> #      Wed May 27 15:58:15 2015 -0700
> # Node ID 1e379d0f63b47fba888724c5a90717c67c874552
> # Parent  6084926366b979e81e5dcc84fa595965d4c07883
> record: display the running operation for recording commands
> 
> This patch is part of a series of patches to change the recording ui to reflect
> the operation currently running (commit, shelve, revert ...).
> This patch makes the UI change to display the running operation on the UI.
> It does not change any tests since we are not using the feature in any command
> yet.

> --- a/mercurial/patch.py
> +++ b/mercurial/patch.py
> @@ -970,7 +970,7 @@
>              return skipfile, skipfile, skipall, newpatches
>          while True:
>              resps = _('[Ynesfdaq?]'
> -                      '$$ &Yes, record this change'
> +                      '$$ &Yes, ') + operation + _(' this change'

Maybe it was pointed out already, but there are two i18n issues:

 a. it assumes that all languages have subject-verb-object structure, which is
    untrue.
 b. choices and their descriptions should be put into a single message
    because &-char may be different by translation (see c58b6ab4c26f)

So, I think it should be

  yesop = {'record': _('record this change'),
           'confirm': ...}[operation]
  _('[Ynesfdaq?]'
    '$$ &Yes, %s'
    '$$ &No, ...') % yesop

Regards,
Katsunori FUJIWARA - June 2, 2015, 4:31 p.m.
At Mon, 1 Jun 2015 10:38:21 -0700,
Laurent Charignon wrote:
> 
> # HG changeset patch
> # User Laurent Charignon <lcharignon@fb.com>
> # Date 1432767495 25200
> #      Wed May 27 15:58:15 2015 -0700
> # Node ID 1e379d0f63b47fba888724c5a90717c67c874552
> # Parent  6084926366b979e81e5dcc84fa595965d4c07883
> record: display the running operation for recording commands
> 
> This patch is part of a series of patches to change the recording ui to reflect
> the operation currently running (commit, shelve, revert ...).
> This patch makes the UI change to display the running operation on the UI.
> It does not change any tests since we are not using the feature in any command
> yet.
> 
> diff --git a/mercurial/crecord.py b/mercurial/crecord.py
> --- a/mercurial/crecord.py
> +++ b/mercurial/crecord.py
> @@ -441,7 +441,7 @@
>      uiheaders = [uiheader(h) for h in headers]
>      # let user choose headers/hunks/lines, and mark their applied flags
>      # accordingly
> -    chunkselector(ui, uiheaders)
> +    chunkselector(ui, uiheaders, operation)
>      appliedhunklist = []
>      for hdr in uiheaders:
>          if (hdr.applied and
> @@ -474,14 +474,14 @@
>          "hhhh", fcntl.ioctl(_origstdout, termios.TIOCGWINSZ, "\000"*8))[0:2]
>      return h, w
>  
> -def chunkselector(ui, headerlist):
> +def chunkselector(ui, headerlist, operation):
>      """
>      curses interface to get selection of chunks, and mark the applied flags
>      of the chosen chunks.
>  
>      """
>      ui.write(_('starting interactive selection\n'))
> -    chunkselector = curseschunkselector(headerlist, ui)
> +    chunkselector = curseschunkselector(headerlist, ui, operation)
>      curses.wrapper(chunkselector.main)
>  
>  def testdecorator(testfn, f):
> @@ -489,7 +489,7 @@
>          return f(testfn, *args, **kwargs)
>      return u
>  
> -def testchunkselector(testfn, ui, headerlist):
> +def testchunkselector(testfn, ui, headerlist, operation):
>      """
>      test interface to get selection of chunks, and mark the applied flags
>      of the chosen chunks.
> @@ -505,10 +505,11 @@
>                  break
>  
>  class curseschunkselector(object):
> -    def __init__(self, headerlist, ui):
> +    def __init__(self, headerlist, ui, operation=_('confirm')):
>          # put the headers into a patch object
>          self.headerlist = patch(headerlist)
>  
> +        self.operation = operation
>          self.ui = ui
>  
>          # list of all chunks
> @@ -1322,10 +1323,7 @@
>          helptext = """            [press any key to return to the patch-display]
>  
>  crecord allows you to interactively choose among the changes you have made,
> -and confirm only those changes you select for further processing by the command
> -you are running (commit/shelve/revert), after confirming the selected
> -changes, the unselected changes are still present in your working copy, so you
> -can use crecord multiple times to split large changes into smaller changesets.
> +and %s only those changes you select.
>  the following are valid keystrokes:
>  
>                  [space] : (un-)select item ([~]/[x] = partly/fully applied)
> @@ -1339,10 +1337,11 @@
>                        m : edit / resume editing the commit message
>                        e : edit the currently selected hunk
>                        a : toggle amend mode (hg rev >= 2.2)
> -                      c : confirm selected changes
> +                      c : %s selected changes
>                        r : review/edit and confirm selected changes
>                        q : quit without confirming (no changes will be made)
> -                      ? : help (what you're currently reading)"""
> +                      ? : help (what you're currently reading)"""\
> +                      % (self.operation, self.operation)
>  
>          helpwin = curses.newwin(self.yscreensize, 0, 0, 0)
>          helplines = helptext.split("\n")
> @@ -1391,11 +1390,12 @@
>  note: don't add/remove lines unless you also modify the range information.
>        failing to follow this rule will result in the commit aborting.
>  
> -are you sure you want to review/edit and confirm the selected changes [yn]?
> -""")
> +are you sure you want to review/edit and %s the selected changes [yn]?
> +""" %(self.operation))
>          else:
>              confirmtext = (
> -                "are you sure you want to confirm the selected changes [yn]? ")
> +                "are you sure you want to %s the selected changes [yn]? "
> +                %(self.operation))
>  
>          response = self.confirmationwindow(confirmtext)
>          if response is None:
> diff --git a/mercurial/patch.py b/mercurial/patch.py
> --- a/mercurial/patch.py
> +++ b/mercurial/patch.py
> @@ -970,7 +970,7 @@
>              return skipfile, skipfile, skipall, newpatches
>          while True:
>              resps = _('[Ynesfdaq?]'
> -                      '$$ &Yes, record this change'
> +                      '$$ &Yes, ') + operation + _(' this change'
>                        '$$ &No, skip this change'
>                        '$$ &Edit this change manually'
>                        '$$ &Skip remaining changes to this file'
> @@ -1080,10 +1080,10 @@
>              if skipfile is None and skipall is None:
>                  chunk.pretty(ui)
>              if total == 1:
> -                msg = _("record this change to '%s'?") % chunk.filename()
> +                msg = operation + _(" this change to '%s'?") % chunk.filename()
>              else:
>                  idx = pos - len(h.hunks) + i
> -                msg = _("record change %d/%d to '%s'?") % (idx, total,
> +                msg = operation + _(" change %d/%d to '%s'?") % (idx, total,
>                                                             chunk.filename())
>              r, skipfile, skipall, newpatches = prompt(skipfile,
>                      skipall, msg, chunk)

What would native speakers feel about messages built up by code paths
below ? ("action" instead of "operation" ? simpler 'apply "%s" on
....' ? OK, you have control :-))

Messages in this style seems easier for message translation and
extensible for adding/revising messages (operations, too ?) in the
future.

====================
        helptext = """            ....
                      ....
and apply "%s" operation on only those changes you select.
                      ....

                      c : apply "%s" operation on selected changes

                      ....""" % (self.operation, self.operation)
====================

====================
    confirmtext = (
        'are you sure you want to apply "%s" operation '
        'on the selected changes [yn]? ' % (self.operation))
====================

====================
    _('....'
      '$$ &Yes, apply "%s" operation on this change'
      '.......') % operation
====================

====================
    msg = (_("apply '%s' operation on this change in '%s'?")
           % (operation, chunk.filename())
====================

BTW, if messages are built in this style, 'i18n:' comments like below
helps translators to know how these generic words are used.

    # i18n: "confirm" is an operation name of interactive selection
    def __init__(self, headerlist, ui, operation=_('confirm')):

    if operation is None:
        # i18n: "record" is an operation name of interactive selection
        operation = _('record')


> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel

----------------------------------------------------------------------
[FUJIWARA Katsunori]                             foozy@lares.dti.ne.jp

Patch

diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -441,7 +441,7 @@ 
     uiheaders = [uiheader(h) for h in headers]
     # let user choose headers/hunks/lines, and mark their applied flags
     # accordingly
-    chunkselector(ui, uiheaders)
+    chunkselector(ui, uiheaders, operation)
     appliedhunklist = []
     for hdr in uiheaders:
         if (hdr.applied and
@@ -474,14 +474,14 @@ 
         "hhhh", fcntl.ioctl(_origstdout, termios.TIOCGWINSZ, "\000"*8))[0:2]
     return h, w
 
-def chunkselector(ui, headerlist):
+def chunkselector(ui, headerlist, operation):
     """
     curses interface to get selection of chunks, and mark the applied flags
     of the chosen chunks.
 
     """
     ui.write(_('starting interactive selection\n'))
-    chunkselector = curseschunkselector(headerlist, ui)
+    chunkselector = curseschunkselector(headerlist, ui, operation)
     curses.wrapper(chunkselector.main)
 
 def testdecorator(testfn, f):
@@ -489,7 +489,7 @@ 
         return f(testfn, *args, **kwargs)
     return u
 
-def testchunkselector(testfn, ui, headerlist):
+def testchunkselector(testfn, ui, headerlist, operation):
     """
     test interface to get selection of chunks, and mark the applied flags
     of the chosen chunks.
@@ -505,10 +505,11 @@ 
                 break
 
 class curseschunkselector(object):
-    def __init__(self, headerlist, ui):
+    def __init__(self, headerlist, ui, operation=_('confirm')):
         # put the headers into a patch object
         self.headerlist = patch(headerlist)
 
+        self.operation = operation
         self.ui = ui
 
         # list of all chunks
@@ -1322,10 +1323,7 @@ 
         helptext = """            [press any key to return to the patch-display]
 
 crecord allows you to interactively choose among the changes you have made,
-and confirm only those changes you select for further processing by the command
-you are running (commit/shelve/revert), after confirming the selected
-changes, the unselected changes are still present in your working copy, so you
-can use crecord multiple times to split large changes into smaller changesets.
+and %s only those changes you select.
 the following are valid keystrokes:
 
                 [space] : (un-)select item ([~]/[x] = partly/fully applied)
@@ -1339,10 +1337,11 @@ 
                       m : edit / resume editing the commit message
                       e : edit the currently selected hunk
                       a : toggle amend mode (hg rev >= 2.2)
-                      c : confirm selected changes
+                      c : %s selected changes
                       r : review/edit and confirm selected changes
                       q : quit without confirming (no changes will be made)
-                      ? : help (what you're currently reading)"""
+                      ? : help (what you're currently reading)"""\
+                      % (self.operation, self.operation)
 
         helpwin = curses.newwin(self.yscreensize, 0, 0, 0)
         helplines = helptext.split("\n")
@@ -1391,11 +1390,12 @@ 
 note: don't add/remove lines unless you also modify the range information.
       failing to follow this rule will result in the commit aborting.
 
-are you sure you want to review/edit and confirm the selected changes [yn]?
-""")
+are you sure you want to review/edit and %s the selected changes [yn]?
+""" %(self.operation))
         else:
             confirmtext = (
-                "are you sure you want to confirm the selected changes [yn]? ")
+                "are you sure you want to %s the selected changes [yn]? "
+                %(self.operation))
 
         response = self.confirmationwindow(confirmtext)
         if response is None:
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -970,7 +970,7 @@ 
             return skipfile, skipfile, skipall, newpatches
         while True:
             resps = _('[Ynesfdaq?]'
-                      '$$ &Yes, record this change'
+                      '$$ &Yes, ') + operation + _(' this change'
                       '$$ &No, skip this change'
                       '$$ &Edit this change manually'
                       '$$ &Skip remaining changes to this file'
@@ -1080,10 +1080,10 @@ 
             if skipfile is None and skipall is None:
                 chunk.pretty(ui)
             if total == 1:
-                msg = _("record this change to '%s'?") % chunk.filename()
+                msg = operation + _(" this change to '%s'?") % chunk.filename()
             else:
                 idx = pos - len(h.hunks) + i
-                msg = _("record change %d/%d to '%s'?") % (idx, total,
+                msg = operation + _(" change %d/%d to '%s'?") % (idx, total,
                                                            chunk.filename())
             r, skipfile, skipall, newpatches = prompt(skipfile,
                     skipall, msg, chunk)