Patchwork [2,of,8] formatter: open raw template file in binary mode (BC)

login
register
mail settings
Submitter Yuya Nishihara
Date June 14, 2017, 1:40 p.m.
Message ID <4642ef5a653b3daa3db1.1497447633@mimosa>
Download mbox | patch
Permalink /patch/21372/
State Accepted
Headers show

Comments

Yuya Nishihara - June 14, 2017, 1:40 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1494049651 -32400
#      Sat May 06 14:47:31 2017 +0900
# Node ID 4642ef5a653b3daa3db1121e8bdd1351b98b28fc
# Parent  ce83b5ca8a012516342b2228da00da3c70f6218a
formatter: open raw template file in binary mode (BC)

I believe it was a mistake to open file in text mode. Now '\r' is preserved
on Windows, but it should be okay to print '\r\n' as long as users live in
such platform.

Patch

diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -399,7 +399,7 @@  def lookuptemplate(ui, topic, tmpl):
         # is it a mapfile for a style?
         if os.path.basename(tmpl).startswith("map-"):
             return None, os.path.realpath(tmpl)
-        with open(tmpl) as f:
+        with open(tmpl, 'rb') as f:
             tmpl = f.read()
         return tmpl, None