Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/Commands/Diff.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -144,20 +144,23 @@ private void ParseLine(ArraySegment<byte> lineBytes)
if (line.Length == 0)
return;

// If we are reading a chunkbody, try to read the current line as body first (because
// the number of chunk body is greater than the number of chunkindicator in most time.
// If we are reading a chunk-body, try to read the current line as chunk-body first (because
// there are usually more chunk-body lines than chunk-indicator lines).
if (_isInChunk)
{
if (ParseChunkBodyLine(line, lineBytes[1..]))
if (ParseChunkBodyLine(line, lineBytes))
return;

ProcessInlineHighlights();
_isInChunk = false;
}

// If the current line is not a chunkbody, try to parse it as chunkindicator
// If the current line is not a chunk-body, try to parse it as chunk-indicator
if (ParseChunkStartLine(line))
{
_isInChunk = true;
return;
}

// Fallback to diff headers to support type-changed diff (multiple headers).
ParseDiffHeaderLine(line);
Expand DownExpand Up@@ -193,7 +196,6 @@ private bool ParseChunkStartLine(string line)
_newLine = int.Parse(match.Groups[2].Value);
_last = new Models.TextDiffLine(Models.TextDiffLineType.Indicator, line, null, 0, 0);
_result.TextDiff.Lines.Add(_last);
_isInChunk = true;
return true;
}

Expand All@@ -204,13 +206,14 @@ private bool ParseChunkBodyLine(string line, ArraySegment<byte> lineBytes)
{
var prefix = line[0];
var content = line.Substring(1);
var rawContent = lineBytes[1..].ToArray();
if (ParseLFSChange(prefix, content))
return true;

if (prefix == PREFIX_DELETED)
{
_result.TextDiff.DeletedLines++;
_last = new Models.TextDiffLine(Models.TextDiffLineType.Deleted, content, lineBytes.ToArray(), _oldLine, 0);
_last = new Models.TextDiffLine(Models.TextDiffLineType.Deleted, content, rawContent, _oldLine, 0);
_deleted.Add(_last);
_oldLine++;
return true;
Expand All@@ -219,7 +222,7 @@ private bool ParseChunkBodyLine(string line, ArraySegment<byte> lineBytes)
if (prefix == PREFIX_ADDED)
{
_result.TextDiff.AddedLines++;
_last = new Models.TextDiffLine(Models.TextDiffLineType.Added, content, lineBytes.ToArray(), 0, _newLine);
_last = new Models.TextDiffLine(Models.TextDiffLineType.Added, content, rawContent, 0, _newLine);
_added.Add(_last);
_newLine++;
return true;
Expand All@@ -229,7 +232,7 @@ private bool ParseChunkBodyLine(string line, ArraySegment<byte> lineBytes)
{
ProcessInlineHighlights();

_last = new Models.TextDiffLine(Models.TextDiffLineType.Normal, content, lineBytes.ToArray(), _oldLine, _newLine);
_last = new Models.TextDiffLine(Models.TextDiffLineType.Normal, content, rawContent, _oldLine, _newLine);
_result.TextDiff.Lines.Add(_last);
_oldLine++;
_newLine++;
Expand Down