diff mercurial/patch.py @ 11611:4f5a6df2af92 stable

i18n: use encoding.colwidth() for correct column width Some encoding and language combinations (e.g.: UTF-8 and Japanese) cause encoding characters into sequence of bytes more than column width of them. So, encoding.colwidth() should be applied instread of len() on i18n strings. In addition to it, formatting by '%*s'/'%-*s' also uses "number of bytes" to calculate space padding size, and should be fixed, too.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Sun, 18 Jul 2010 01:06:50 +0900
parents 9916263d9a60
children 88b89ace643b
line wrap: on
line diff
--- a/mercurial/patch.py	Fri Jul 16 16:33:55 2010 +0900
+++ b/mercurial/patch.py	Sun Jul 18 01:06:50 2010 +0900
@@ -11,7 +11,7 @@
 
 from i18n import _
 from node import hex, nullid, short
-import base85, cmdutil, mdiff, util, diffhelpers, copies
+import base85, cmdutil, mdiff, util, diffhelpers, copies, encoding
 
 gitre = re.compile('diff --git a/(.*) b/(.*)')
 
@@ -1644,10 +1644,14 @@
     maxtotal, maxname = 0, 0
     totaladds, totalremoves = 0, 0
     hasbinary = False
-    for filename, adds, removes, isbinary in stats:
+
+    sized = [(filename, adds, removes, isbinary, encoding.colwidth(filename))
+             for filename, adds, removes, isbinary in stats]
+
+    for filename, adds, removes, isbinary, namewidth in sized:
         totaladds += adds
         totalremoves += removes
-        maxname = max(maxname, len(filename))
+        maxname = max(maxname, namewidth)
         maxtotal = max(maxtotal, adds + removes)
         if isbinary:
             hasbinary = True
@@ -1667,15 +1671,17 @@
         # if there were at least some changes.
         return max(i * graphwidth // maxtotal, int(bool(i)))
 
-    for filename, adds, removes, isbinary in stats:
+    for filename, adds, removes, isbinary, namewidth in sized:
         if git and isbinary:
             count = 'Bin'
         else:
             count = adds + removes
         pluses = '+' * scale(adds)
         minuses = '-' * scale(removes)
-        output.append(' %-*s |  %*s %s%s\n' % (maxname, filename, countwidth,
-                                               count, pluses, minuses))
+        output.append(' %s%s |  %*s %s%s\n' %
+                      (filename, ' ' * (maxname - namewidth),
+                       countwidth, count,
+                       pluses, minuses))
 
     if stats:
         output.append(_(' %d files changed, %d insertions(+), %d deletions(-)\n')