Commit 00790d31 authored by Bruce Dawson's avatar Bruce Dawson Committed by LUCI CQ

Fix \r\r\n line endings in presubmit output

When running "git cl presubmit --all" some of the presubmit messages
were ending up double-spaced if the output is sent to a file and then
loaded into notepad or Visual Studio. Visual Studio would complain
about inconsistent line endings, and it turns out that this was all
caused by some lines having \r\r\n line endings - notepad and Visual
Studio interpret that as two line endings.

The problem is that the stream that WinUnicodeOutput writes to does \n
to \r\n translation. If the text being printed already has \r\n line
endings then we get doubled-up \r characters. The fix is to replace all
\r\n sequences with \n before calling write.

This reduces the line count of the output by almost 2300 lines (more
than 25% of the total) and makes it much more readable.

Bug: 1309977
Change-Id: Ie5475087badc3d3146e4f2ba41d30c9817dd375a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3589498Reviewed-by: 's avatarAravind Vasudevan <aravindvasudev@google.com>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
parent 2c7ed7f5
......@@ -276,6 +276,11 @@ class WinUnicodeOutput(WinUnicodeOutputBase):
if sys.version_info.major == 3 and isinstance(text, bytes):
# Replace characters that cannot be printed instead of failing.
text = text.decode(self.encoding, 'replace')
# When redirecting to a file or process any \n characters will be replaced
# with \r\n. If the text to be printed already has \r\n line endings then
# \r\r\n line endings will be generated, leading to double-spacing of some
# output. Normalizing line endings to \n avoids this problem.
text = text.replace('\r\n', '\n')
self._stream.write(text)
except Exception as e:
complain('%s.write: %r' % (self.name, e))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment