8000 added lines and deleted lines in content changes by Stijn-Rutten · Pull Request #1790 · libgit2/libgit2sharp · GitHub
[go: up one dir, main page]

Skip to content

added lines and deleted lines in content changes #1790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Apply suggestions from code review
  • Loading branch information
Stijn-Rutten committed Jun 11, 2020
commit c5bd90a3ec68a8fda7ee6e533feb4da0afa2f624
10 changes: 8 additions & 2 deletions LibGit2Sharp.Tests/DiffBlobToBlobFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using LibGit2Sharp.Tests.TestHelpers;
using System.IO;
using System.IO;
using System.Linq;
using System.Text;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;

namespace LibGit2Sharp.Tests
Expand Down Expand Up @@ -227,6 +227,12 @@ public void DiffSetsTheAddedAndDeletedLinesCorrectly()

Assert.Single(changes.AddedLines);
Assert.Single(changes.DeletedLines);

Assert.Equal("4", changes.DeletedLines.First().Content);
Assert.Equal("5", changes.AddedLines.First().Content);

Assert.Equal(4, changes.DeletedLines.First().LineNumber);
Assert.Equal(4, changes.AddedLines.First().LineNumber);
}
}

Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/DiffTreeToTargetFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using LibGit2Sharp.Tests.TestHelpers;
using System.IO;
using System.Linq;
using System.Text;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;

namespace LibGit2Sharp.Tests
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using LibGit2Sharp.Tests.TestHelpers;
using System;
using System;
using System.IO;
using System.Linq;
using System.Text;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;

namespace LibGit2Sharp.Tests
Expand Down
8 changes: 2 additions & 6 deletions LibGit2Sharp/ContentChanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ protected ContentChanges()

internal unsafe ContentChanges(Repository repo, Blob oldBlob, Blob newBlob, GitDiffOptions options)
{
AddedLines = new List<Line>();
DeletedLines = new List<Line>();

Proxy.git_diff_blobs(repo.Handle,
oldBlob != null ? oldBlob.Id : null,
newBlob != null ? newBlob.Id : null,
Expand Down Expand Up @@ -58,13 +55,12 @@ internal void AppendToPatch(string patch)
/// <summary>
/// Lis of all lines added.
/// </summary>
public virtual List<Line> AddedLines { get; internal set; }
public virtual List<Line> AddedLines { get; } = new List<Line>();

/// <summary>
/// List of all lines deleted.
/// </summary>
public virtual List<Line> DeletedLines { get; internal set; }

public virtual List<Line> DeletedLines { get; } = new List<Line>();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the extra line

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need to clean up this extra line break.

/// <summary>
/// The patch corresponding to these changes.
Expand Down
13 changes: 4 additions & 9 deletions LibGit2Sharp/Patch.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using LibGit2Sharp.Core;
using LibGit2Sharp.Core.Handles;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Text;
using LibGit2Sharp.Core;
using LibGit2Sharp.Core.Handles;

namespace LibGit2Sharp
{
Expand Down Expand Up @@ -68,11 +68,6 @@ private unsafe int PrintCallBack(git_diff_delta* delta, GitDiffHunk hunk, GitDif
PatchEntryChanges currentChange = this[filePath];
string prefix = string.Empty;

string decodedContent = LaxUtf8Marshaler.FromNative(line.content, (int)line.contentLen);

currentChange.AddedLines = currentChange.AddedLines ?? new List<Line>();
currentChange.DeletedLines = currentChange.DeletedLines ?? new List<Line>();

switch (line.lineOrigin)
{
case GitDiffLineOrigin.GIT_DIFF_LINE_CONTEXT:
Expand All @@ -82,14 +77,14 @@ private unsafe int PrintCallBack(git_diff_delta* delta, GitDiffHunk hunk, GitDif
case GitDiffLineOrigin.GIT_DIFF_LINE_ADDITION:
linesAdded++;
currentChange.LinesAdded++;
currentChange.AddedLines.Add(new Line(line.NewLineNo, decodedContent));
currentChange.AddedLines.Add(new Line(line.NewLineNo, patchPart));
prefix = "+";
break;

case GitDiffLineOrigin.GIT_DIFF_LINE_DELETION:
linesDeleted++;
currentChange.LinesDeleted++;
currentChange.DeletedLines.Add(new Line(line.OldLineNo, decodedContent));
currentChange.DeletedLines.Add(new Line(line.OldLineNo, patchPart));
prefix = "-";
break;
}
Expand Down
0