-
Notifications
You must be signed in to change notification settings - Fork 899
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
Changes from 5 commits
79e11b9
92b9e20
445bbbe
70b6bd7
3c777dc
9733e74
37fa585
8196539
a9d5c36
c5bd90a
34a65c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Globalization; | ||
using System.Text; | ||
|
@@ -22,6 +23,9 @@ 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, | ||
|
@@ -51,6 +55,17 @@ internal void AppendToPatch(string patch) | |
/// </summary> | ||
public virtual int LinesDeleted { get; internal set; } | ||
|
||
/// <summary> | ||
/// Lis of all lines added. | ||
Stijn-Rutten marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// </summary> | ||
public virtual List<Line> AddedLines { get; internal set; } | ||
bording marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// <summary> | ||
/// List of all lines deleted. | ||
Stijn-Rutten marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// </summary> | ||
public virtual List<Line> DeletedLines { get; internal set; } | ||
bording marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the extra line There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
/// </summary> | ||
|
@@ -95,11 +110,13 @@ private unsafe int LineCallback(git_diff_delta* delta, GitDiffHunk hunk, GitDiff | |
switch (line.lineOrigin) | ||
{ | ||
case GitDiffLineOrigin.GIT_DIFF_LINE_ADDITION: | ||
AddedLines.Add(new Line(line.NewLineNo, decodedContent)); | ||
LinesAdded++; | ||
prefix = Encoding.ASCII.GetString(new[] { (byte)line.lineOrigin }); | ||
break; | ||
|
||
case GitDiffLineOrigin.GIT_DIFF_LINE_DELETION: | ||
DeletedLines.Add(new Line(line.OldLineNo, decodedContent)); | ||
LinesDeleted++; | ||
prefix = Encoding.ASCII.GetString(new[] { (byte)line.lineOrigin }); | ||
break; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace LibGit2Sharp | ||
{ | ||
/// <summary> | ||
/// Represents a Line with line number and content. | ||
Stijn-Rutten marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// </summary> | ||
public struct Line | ||
{ | ||
/// <summary> | ||
/// Points to the number of the original line in the blob | ||
Stijn-Rutten marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// </summary> | ||
public int LineNumber { get; } | ||
|
||
/// <summary> | ||
/// This content of the line in the original blob | ||
Stijn-Rutten marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// </summary> | ||
public String Content { get; } | ||
Stijn-Rutten marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
internal Line(int lineNumber, string content) | ||
{ | ||
LineNumber = lineNumber; | ||
Content = content; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,11 @@ 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this when this appears to be the same as the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should able to be removed. You can just use the existing |
||
|
||
currentChange.AddedLines = new List<Line>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are these needed? Seems like this should be already handled in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added this in case the contructor that calls |
||
currentChange.DeletedLines = new List<Line>(); | ||
|
||
switch (line.lineOrigin) | ||
{ | ||
case GitDiffLineOrigin.GIT_DIFF_LINE_CONTEXT: | ||
|
@@ -77,12 +82,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)); | ||
prefix = "+"; | ||
break; | ||
|
||
case GitDiffLineOrigin.GIT_DIFF_LINE_DELETION: | ||
linesDeleted++; | ||
currentChange.LinesDeleted++; | ||
currentChange.DeletedLines.Add(new Line(line.OldLineNo, decodedContent)); | ||
prefix = "-"; | ||
break; | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.