mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-20 19:55:00 +00:00
code_review: PR #1177
- use `Command.ReadToEnd` instead of `Command.Exec` to avoid git trims line endings. - use `StringBuilder.Append('\n')` instead of `StringBuilder.AppendLine()` to restore original line endings (we split the original diff output by `\n` not `\r') - there's no need to show file content (the `StreamReader.ReadLine()` will trim line endings) Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
81820e7034
commit
e89dbd8f43
3 changed files with 31 additions and 53 deletions
|
@ -35,7 +35,26 @@ namespace SourceGit.Commands
|
|||
|
||||
public Models.DiffResult Result()
|
||||
{
|
||||
Exec();
|
||||
var rs = ReadToEnd();
|
||||
if (!rs.IsSuccess)
|
||||
{
|
||||
_result.TextDiff = null;
|
||||
return _result;
|
||||
}
|
||||
|
||||
var start = 0;
|
||||
var end = rs.StdOut.IndexOf('\n', start);
|
||||
while (end > 0)
|
||||
{
|
||||
var line = rs.StdOut.Substring(start, end - start);
|
||||
ParseLine(line);
|
||||
|
||||
start = end + 1;
|
||||
end = rs.StdOut.IndexOf('\n', start);
|
||||
}
|
||||
|
||||
if (start < rs.StdOut.Length)
|
||||
ParseLine(rs.StdOut.Substring(start));
|
||||
|
||||
if (_result.IsBinary || _result.IsLFS)
|
||||
{
|
||||
|
@ -54,8 +73,11 @@ namespace SourceGit.Commands
|
|||
return _result;
|
||||
}
|
||||
|
||||
protected override void OnReadline(string line)
|
||||
private void ParseLine(string line)
|
||||
{
|
||||
if (_result.IsBinary)
|
||||
return;
|
||||
|
||||
if (line.StartsWith("old mode ", StringComparison.Ordinal))
|
||||
{
|
||||
_result.OldMode = line.Substring(9);
|
||||
|
@ -80,9 +102,6 @@ namespace SourceGit.Commands
|
|||
return;
|
||||
}
|
||||
|
||||
if (_result.IsBinary)
|
||||
return;
|
||||
|
||||
if (_result.IsLFS)
|
||||
{
|
||||
var ch = line[0];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue