Skip to content

Commit 2e5e50a

Browse files
committed
revert: revert changes to read diff lines
`StringReader.ReadLine()` will trim the ending `\r` if the line-ending of this file is `\r\n`. We need to restore the line-endings in `TextDiffView` by append a single '\n' Signed-off-by: leo <[email protected]>
1 parent 666305e commit 2e5e50a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/Commands/Diff.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.IO;
43
using System.Text.RegularExpressions;
54
using System.Threading.Tasks;
65

@@ -40,10 +39,20 @@ public Diff(string repo, Models.DiffOption opt, int unified, bool ignoreWhitespa
4039
public async Task<Models.DiffResult> ReadAsync()
4140
{
4241
var rs = await ReadToEndAsync().ConfigureAwait(false);
43-
var sr = new StringReader(rs.StdOut);
44-
while (sr.ReadLine() is { } line)
42+
var start = 0;
43+
var end = rs.StdOut.IndexOf('\n', start);
44+
while (end > 0)
45+
{
46+
var line = rs.StdOut.Substring(start, end - start);
4547
ParseLine(line);
4648

49+
start = end + 1;
50+
end = rs.StdOut.IndexOf('\n', start);
51+
}
52+
53+
if (start < rs.StdOut.Length)
54+
ParseLine(rs.StdOut.Substring(start));
55+
4756
if (_result.IsBinary || _result.IsLFS || _result.TextDiff.Lines.Count == 0)
4857
{
4958
_result.TextDiff = null;

0 commit comments

Comments
 (0)