Commits

Yuya Nishihara  committed 04d7338

wconfig: serialize config data prior to opening file for writing

It should do little thing after open because we'll disable atomic rename
on Windows.

  • Participants
  • Parent commits 9763406
  • Branches stable

Comments (0)

Files changed (1)

File tortoisehg/util/wconfig.py

 
 def writefile(config, path):
     """Write the given config obj to the specified file"""
+    # normalize line endings
+    buf = cStringIO.StringIO()
+    config.write(buf)
+    data = '\n'.join(buf.getvalue().splitlines()) + '\n'
+
     f = util.atomictempfile(os.path.realpath(path), 'w')
     try:
-        buf = cStringIO.StringIO()
-        config.write(buf)
-        # normalize line endings
-        for line in buf.getvalue().splitlines():
-            f.write(line + '\n')
+        f.write(data)
         f.close()
     finally:
         del f  # unlink temp file