patch: define full messages for interactive record/revert
authorDenis Laxalde <denis.laxalde@logilab.fr>
Tue, 07 Jun 2016 10:37:19 +0200
changeset 29326 d48fc6f318a3
parent 29325 4f2f8baba2ff
child 29327 baab9ea4426c
patch: define full messages for interactive record/revert Followup 14eee72c8d52 to provide complete context for proper localization. Also update cmdutil.recordfilter docstring to remove recommendation that "operation" argument should be translated. Indeed, for record/revert, we either go to patch.filterpatch or crecord.filterpatch (in curses mode) ; the former now build the full ui message from the operation parameter and the latter does not use this parameter (removing in a followup patch). For shelve, operation is not specified and this thus falls back to "record".
mercurial/cmdutil.py
mercurial/patch.py
--- a/mercurial/cmdutil.py	Wed Jun 01 15:16:38 2016 +0200
+++ b/mercurial/cmdutil.py	Tue Jun 07 10:37:19 2016 +0200
@@ -91,9 +91,9 @@
 def recordfilter(ui, originalhunks, operation=None):
     """ Prompts the user to filter the originalhunks and return a list of
     selected hunks.
-    *operation* is used for ui purposes to indicate the user
-    what kind of filtering they are doing: reverting, committing, shelving, etc.
-    *operation* has to be a translated string.
+    *operation* is used for to build ui messages to indicate the user what
+    kind of filtering they are doing: reverting, committing, shelving, etc.
+    (see patch.filterpatch).
     """
     usecurses = crecordmod.checkcurses(ui)
     testfile = ui.config('experimental', 'crecordtest', None)
@@ -3301,7 +3301,7 @@
         else:
             diff = patch.diff(repo, None, ctx.node(), m, opts=diffopts)
         originalchunks = patch.parsepatch(diff)
-        operation = _('discard') if node == parent else _('revert')
+        operation = 'discard' if node == parent else 'revert'
 
         try:
 
--- a/mercurial/patch.py	Wed Jun 01 15:16:38 2016 +0200
+++ b/mercurial/patch.py	Tue Jun 07 10:37:19 2016 +0200
@@ -978,7 +978,19 @@
 def filterpatch(ui, headers, operation=None):
     """Interactively filter patch chunks into applied-only chunks"""
     if operation is None:
-        operation = _('record')
+        operation = 'record'
+    messages = {
+        'multiple': {
+            'discard': _("discard change %d/%d to '%s'?"),
+            'record': _("record change %d/%d to '%s'?"),
+            'revert': _("revert change %d/%d to '%s'?"),
+        }[operation],
+        'single': {
+            'discard': _("discard this change to '%s'?"),
+            'record': _("record this change to '%s'?"),
+            'revert': _("revert this change to '%s'?"),
+        }[operation],
+    }
 
     def prompt(skipfile, skipall, query, chunk):
         """prompt query, and process base inputs
@@ -1109,12 +1121,10 @@
             if skipfile is None and skipall is None:
                 chunk.pretty(ui)
             if total == 1:
-                msg = _("%s this change to '%s'?") % (operation,
-                                                      chunk.filename())
+                msg = messages['single'] % chunk.filename()
             else:
                 idx = pos - len(h.hunks) + i
-                msg = _("%s change %d/%d to '%s'?") % (operation, idx, total,
-                                                       chunk.filename())
+                msg = messages['multiple'] % (idx, total, chunk.filename())
             r, skipfile, skipall, newpatches = prompt(skipfile,
                     skipall, msg, chunk)
             if r: