Decode datetime string when it's not utf-8
If the encoding is not utf-8, datatime_now() will yield
> 'now': '2019-05-17 \xbf\xc0\xc0\xfc 11:28:31'(with CP949),
and it fails to decode it with utf-8 afterward.
> traces_readme, TRACES_README_FORMAT % git_push_metadata)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xbf in position 17: invalid start byte
For further information, please check out
https://bugs.chromium.org/p/chromium/issues/detail?id=955206#c16
Bug: 955206
Change-Id: I2733849735adc0361140b042ce617522c58fcc78
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1621576
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Sang Woo Ko <sangwoo108@chromium.org>
diff --git a/git_cl.py b/git_cl.py
index f7f84d8..5c858ce 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -2552,6 +2552,10 @@
git_info_zip = trace_name + '-git-info'
git_push_metadata['now'] = datetime_now().strftime('%c')
+ if sys.stdin.encoding != 'utf-8':
+ git_push_metadata['now'] = git_push_metadata['now'].decode(
+ sys.stdin.encoding)
+
git_push_metadata['trace_name'] = trace_name
gclient_utils.FileWrite(
traces_readme, TRACES_README_FORMAT % git_push_metadata)