[PATCH 2 of 3 STABLE] i18n: fix "% inside _()" problems

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Mon Mar 31 13:17:33 CDT 2014


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1396287963 -32400
#      Tue Apr 01 02:46:03 2014 +0900
# Branch stable
# Node ID 1a28c327d40f2793356f04c0c54ef34fbcfa4b03
# Parent  44df0fef692bcf343d9e748ddb8d7bceb0b657aa
i18n: fix "% inside _()" problems

Before this patch, "contrib/check-code.py" can't detect these
problems, because the regexp pattern to detect "% inside _()" doesn't
suppose the case that the format string and "%" aren't placed in the
same line.

This patch replaces "\s" in that regexp pattern with "[ \t\n]" to
detect "% inside _()" problems in such case.

"[\s\n]" can't be used in this purpose, because "\s" is automatically
replaced with "[ \t]" by "_preparepats()" and "\s" in "[]" causes
nested "[]" unexpectedly.

diff --git a/contrib/check-code.py b/contrib/check-code.py
--- a/contrib/check-code.py
+++ b/contrib/check-code.py
@@ -198,8 +198,8 @@
     (r'\s<>\s', '<> operator is not available in Python 3+, use !='),
     (r'^\s*\t', "don't use tabs"),
     (r'\S;\s*\n', "semicolon"),
-    (r'[^_]_\("[^"]+"\s*%', "don't use % inside _()"),
-    (r"[^_]_\('[^']+'\s*%", "don't use % inside _()"),
+    (r'[^_]_\("[^"]+"[ \t\n]*%', "don't use % inside _()"),
+    (r"[^_]_\('[^']+'[ \t\n]*%", "don't use % inside _()"),
     (r'(\w|\)),\w', "missing whitespace after ,"),
     (r'(\w|\))[+/*\-<>]\w', "missing whitespace in expression"),
     (r'^\s+(\w|\.)+=\w[^,()\n]*$', "missing whitespace in assignment"),
diff --git a/hgext/largefiles/lfcommands.py b/hgext/largefiles/lfcommands.py
--- a/hgext/largefiles/lfcommands.py
+++ b/hgext/largefiles/lfcommands.py
@@ -303,14 +303,14 @@
         try:
             id, name = line.split(' ', 1)
         except ValueError:
-            ui.warn(_('skipping incorrectly formatted tag %s\n'
-                % line))
+            ui.warn(_('skipping incorrectly formatted tag %s\n')
+                % line)
             continue
         try:
             newid = node.bin(id)
         except TypeError:
-            ui.warn(_('skipping incorrectly formatted id %s\n'
-                % id))
+            ui.warn(_('skipping incorrectly formatted id %s\n')
+                % id)
             continue
         try:
             newdata.append('%s %s\n' % (node.hex(revmap[newid]),
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -752,8 +752,8 @@
         if not changesets:
             extendnode = extendbisectrange(nodes, good)
             if extendnode is not None:
-                ui.write(_("Extending search to changeset %d:%s\n"
-                         % (extendnode.rev(), extendnode)))
+                ui.write(_("Extending search to changeset %d:%s\n")
+                         % (extendnode.rev(), extendnode))
                 state['current'] = [extendnode.node()]
                 hbisect.save_state(repo, state)
                 if noupdate:
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -433,7 +433,7 @@
                         if bn == 'default':
                             status = _("updating to bookmark @\n")
                         else:
-                            status = _("updating to bookmark @ on branch %s\n"
+                            status = (_("updating to bookmark @ on branch %s\n")
                                        % bn)
                     except KeyError:
                         try:
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -70,8 +70,8 @@
                 bits = record.split("\0")
                 self._state[bits[0]] = bits[1:]
             elif not rtype.islower():
-                raise util.Abort(_('unsupported merge state record: %s'
-                                   % rtype))
+                raise util.Abort(_('unsupported merge state record: %s')
+                                   % rtype)
         self._dirty = False
     def _readrecords(self):
         v1records = self._readrecordsv1()
diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -321,8 +321,8 @@
         for f in names:
             if f.lower() == 'hgrc':
                 ui.warn(
-                    _("warning: removing potentially hostile .hg/hgrc in '%s'"
-                      % path))
+                    _("warning: removing potentially hostile .hg/hgrc in '%s'")
+                      % path)
                 os.unlink(os.path.join(dirname, f))
     os.walk(path, v, None)
 


More information about the Mercurial-devel mailing list