Patchwork [6,of,7] py3: call strftime() with native str type

login
register
mail settings
Submitter Yuya Nishihara
Date March 13, 2017, 6:59 p.m.
Message ID <2657aad32bdde8ab6225.1489431547@mimosa>
Download mbox | patch
Permalink /patch/19295/
State Accepted
Headers show

Comments

Yuya Nishihara - March 13, 2017, 6:59 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1489421947 25200
#      Mon Mar 13 09:19:07 2017 -0700
# Node ID 2657aad32bdde8ab6225d988a0a5cd979f6834d1
# Parent  5a7ae0b9a19659dec4c951a86349728867265cab
py3: call strftime() with native str type

Since strftime() may contain non-ascii character if locale set, we use
strfrom/tolocal().

Now "hg tip" works.

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1792,7 +1792,7 @@  def datestr(date=None, format='%a %b %d 
     # because they use the gmtime() system call which is buggy on Windows
     # for negative values.
     t = datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=d)
-    s = t.strftime(format)
+    s = encoding.strtolocal(t.strftime(encoding.strfromlocal(format)))
     return s
 
 def shortdate(date=None):