Skip to content

Commit cffdf24

Browse files
committed
Make ContentChanges.IsBinaryDelta() an extension method
1 parent 841a987 commit cffdf24

4 files changed

Lines changed: 14 additions & 8 deletions

File tree

LibGit2Sharp/ContentChanges.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ internal ContentChanges(Repository repo, Blob oldBlob, Blob newBlob, GitDiffOpti
2626

2727
private int FileCallback(IntPtr data, GitDiffDelta delta, float progress)
2828
{
29-
IsBinaryComparison = IsBinaryDelta(delta);
29+
IsBinaryComparison = delta.IsBinary();
3030

3131
if (!IsBinaryComparison)
3232
{
@@ -38,12 +38,6 @@ private int FileCallback(IntPtr data, GitDiffDelta delta, float progress)
3838
return 0;
3939
}
4040

41-
internal static bool IsBinaryDelta(GitDiffDelta delta)
42-
{
43-
//TODO Fix the interop issue on amd64 and use GitDiffDelta.Binary
44-
return delta.OldFile.Flags.Has(GitDiffFileFlags.GIT_DIFF_FILE_BINARY) || delta.NewFile.Flags.Has(GitDiffFileFlags.GIT_DIFF_FILE_BINARY);
45-
}
46-
4741
private int HunkCallback(IntPtr data, GitDiffDelta delta, GitDiffRange range, IntPtr header, uint headerlen)
4842
{
4943
string decodedContent = Utf8Marshaler.FromNative(header, headerlen);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace LibGit2Sharp.Core
2+
{
3+
internal static class GitDiffExtensions
4+
{
5+
public static bool IsBinary(this GitDiffDelta delta)
6+
{
7+
//TODO Fix the interop issue on amd64 and use GitDiffDelta.Binary
8+
return delta.OldFile.Flags.Has(GitDiffFileFlags.GIT_DIFF_FILE_BINARY) || delta.NewFile.Flags.Has(GitDiffFileFlags.GIT_DIFF_FILE_BINARY);
9+
}
10+
}
11+
}

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<Compile Include="ChangeKind.cs" />
7575
<Compile Include="Core\GitBranchType.cs" />
7676
<Compile Include="Core\GitDiff.cs" />
77+
<Compile Include="Core\GitDiffExtensions.cs" />
7778
<Compile Include="Core\GitError.cs" />
7879
<Compile Include="Core\GitErrorType.cs" />
7980
<Compile Include="Core\GitNoteData.cs" />

LibGit2Sharp/TreeChanges.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private void AddFileChange(GitDiffDelta delta)
9292
var newOid = new ObjectId(delta.NewFile.Oid);
9393
var oldOid = new ObjectId(delta.OldFile.Oid);
9494

95-
var diffFile = new TreeEntryChanges(newFilePath, newMode, newOid, delta.Status, oldFilePath, oldMode, oldOid, ContentChanges.IsBinaryDelta(delta));
95+
var diffFile = new TreeEntryChanges(newFilePath, newMode, newOid, delta.Status, oldFilePath, oldMode, oldOid, delta.IsBinary());
9696

9797
fileDispatcher[delta.Status](this, diffFile);
9898
changes.Add(diffFile.Path, diffFile);

0 commit comments

Comments
 (0)