[PATCH 1 of 1 STABLE] i18n: use locale insensitive format for datetimes as intermediate representation (issue3398)

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Wed Apr 25 12:48:55 CDT 2012


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1335375680 -32400
# Branch stable
# Node ID 964728f7292e6274da4ae682f4734ac0827e666f
# Parent  e3c7ca15cde24f7e1ef5018fcfd902f4d6c95adc
i18n: use locale insensitive format for datetimes as intermediate representation (issue3398)

on some non "en" locale environments, "hg convert" is aborted, because
"util.parsedate()" fails.

it fails in "memctx.__init__()" called by "putcommit()" of "convert".

in "hg convert", datetimes gotten from source repository
are usually formatted by "util.datestr()" with default format "%a %b
%d %H:%M:%S %Y %1%2".

but on some environments, "%a" and "%b" may cause locale sensitive
string, and such string may cause parse error in "util.parsedate()".

this path uses "%Y-%m-%d %H:%M:%S %1%2" as intermediate representation
format for datetimes, because it consists only of locale insensitive
elements.

datetimes in above format are only used for passing them from
conversion logic to memctx object, so it doesn't have to be formatted
by locale sensitive one.

this patch just avoids locale sensitivity problem of "datestr()" and
"parsedate()" combintion.

diff -r e3c7ca15cde2 -r 964728f7292e hgext/convert/cvs.py
--- a/hgext/convert/cvs.py	Mon Apr 23 00:38:22 2012 +0900
+++ b/hgext/convert/cvs.py	Thu Apr 26 02:41:20 2012 +0900
@@ -70,7 +70,7 @@
                 cs.author = self.recode(cs.author)
                 self.lastbranch[cs.branch] = id
                 cs.comment = self.recode(cs.comment)
-                date = util.datestr(cs.date)
+                date = util.datestr(cs.date, '%Y-%m-%d %H:%M:%S %1%2')
                 self.tags.update(dict.fromkeys(cs.tags, id))
 
                 files = {}
diff -r e3c7ca15cde2 -r 964728f7292e hgext/convert/darcs.py
--- a/hgext/convert/darcs.py	Mon Apr 23 00:38:22 2012 +0900
+++ b/hgext/convert/darcs.py	Thu Apr 26 02:41:20 2012 +0900
@@ -139,7 +139,7 @@
         # etree can return unicode objects for name, comment, and author,
         # so recode() is used to ensure str objects are emitted.
         return commit(author=self.recode(elt.get('author')),
-                      date=util.datestr(date),
+                      date=util.datestr(date, '%Y-%m-%d %H:%M:%S %1%2'),
                       desc=self.recode(desc).strip(),
                       parents=self.parents[rev])
 
diff -r e3c7ca15cde2 -r 964728f7292e hgext/convert/hg.py
--- a/hgext/convert/hg.py	Mon Apr 23 00:38:22 2012 +0900
+++ b/hgext/convert/hg.py	Thu Apr 26 02:41:20 2012 +0900
@@ -342,7 +342,8 @@
             crev = rev
         else:
             crev = None
-        return commit(author=ctx.user(), date=util.datestr(ctx.date()),
+        return commit(author=ctx.user(),
+                      date=util.datestr(ctx.date(), '%Y-%m-%d %H:%M:%S %1%2'),
                       desc=ctx.description(), rev=crev, parents=parents,
                       branch=ctx.branch(), extra=ctx.extra(),
                       sortkey=ctx.rev())
diff -r e3c7ca15cde2 -r 964728f7292e hgext/convert/p4.py
--- a/hgext/convert/p4.py	Mon Apr 23 00:38:22 2012 +0900
+++ b/hgext/convert/p4.py	Thu Apr 26 02:41:20 2012 +0900
@@ -119,7 +119,8 @@
                 parents = []
 
             date = (int(d["time"]), 0)     # timezone not set
-            c = commit(author=self.recode(d["user"]), date=util.datestr(date),
+            c = commit(author=self.recode(d["user"]),
+                       date=util.datestr(date, '%Y-%m-%d %H:%M:%S %1%2'),
                        parents=parents, desc=desc, branch='',
                        extra={"p4": change})
 
diff -r e3c7ca15cde2 -r 964728f7292e hgext/convert/subversion.py
--- a/hgext/convert/subversion.py	Mon Apr 23 00:38:22 2012 +0900
+++ b/hgext/convert/subversion.py	Thu Apr 26 02:41:20 2012 +0900
@@ -808,7 +808,7 @@
                 branch = None
 
             cset = commit(author=author,
-                          date=util.datestr(date),
+                          date=util.datestr(date, '%Y-%m-%d %H:%M:%S %1%2'),
                           desc=log,
                           parents=parents,
                           branch=branch,


More information about the Mercurial-devel mailing list