Skip to content

Commit 824a1c1

Browse files
committed
Make TreeChanges and TreeEntryChanges expose native paths
Fix #171
1 parent e075315 commit 824a1c1

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Linq;
1+
using System.IO;
2+
using System.Linq;
23
using System.Text;
34
using LibGit2Sharp.Tests.TestHelpers;
45
using Xunit;
@@ -7,6 +8,8 @@ namespace LibGit2Sharp.Tests
78
{
89
public class DiffTreeToTreeFixture : BaseFixture
910
{
11+
private static readonly string subBranchFilePath = Path.Combine("1", "branch_file.txt");
12+
1013
[Fact]
1114
public void ComparingATreeAgainstItselfReturnsNoDifference()
1215
{
@@ -87,7 +90,7 @@ public void CanCompareASubsetofTheTreeAgainstOneOfItsAncestor()
8790
Assert.NotNull(changes);
8891

8992
Assert.Equal(1, changes.Count());
90-
Assert.Equal("1/branch_file.txt", changes.Added.Single().Path);
93+
Assert.Equal(subBranchFilePath, changes.Added.Single().Path);
9194
}
9295
}
9396

@@ -120,7 +123,7 @@ public void CanCompareACommitTreeAgainstATreeWithNoCommonAncestor()
120123
Assert.Equal(1, changes.Deleted.Count());
121124

122125
Assert.Equal("readme.txt", changes.Deleted.Single().Path);
123-
Assert.Equal(new[] { "1.txt", "1/branch_file.txt", "README", "branch_file.txt", "deleted_staged_file.txt", "deleted_unstaged_file.txt", "modified_staged_file.txt", "modified_unstaged_file.txt", "new.txt" },
126+
Assert.Equal(new[] { "1.txt", subBranchFilePath, "README", "branch_file.txt", "deleted_staged_file.txt", "deleted_unstaged_file.txt", "modified_staged_file.txt", "modified_unstaged_file.txt", "new.txt" },
124127
changes.Added.Select(x => x.Path));
125128

126129
Assert.Equal(9, changes.LinesAdded);

LibGit2Sharp/TreeChanges.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace LibGit2Sharp
1313
/// </summary>
1414
public class TreeChanges : IEnumerable<TreeEntryChanges>
1515
{
16-
private readonly IDictionary<string, TreeEntryChanges> changes = new Dictionary<string, TreeEntryChanges>();
16+
private readonly IDictionary<FilePath, TreeEntryChanges> changes = new Dictionary<FilePath, TreeEntryChanges>();
1717
private readonly List<TreeEntryChanges> added = new List<TreeEntryChanges>();
1818
private readonly List<TreeEntryChanges> deleted = new List<TreeEntryChanges>();
1919
private readonly List<TreeEntryChanges> modified = new List<TreeEntryChanges>();
@@ -41,8 +41,8 @@ internal TreeChanges(DiffListSafeHandle diff)
4141

4242
private int PrintCallBack(IntPtr data, GitDiffDelta delta, GitDiffRange range, GitDiffLineOrigin lineorigin, IntPtr content, uint contentlen)
4343
{
44-
var formattedoutput = Utf8Marshaler.FromNative(content, contentlen);
45-
var currentFilePath = Utf8Marshaler.FromNative(delta.NewFile.Path);
44+
string formattedoutput = Utf8Marshaler.FromNative(content, contentlen);
45+
FilePath currentFilePath = FilePathMarshaler.FromNative(delta.NewFile.Path);
4646

4747
AddLineChange(currentFilePath, lineorigin);
4848

@@ -57,7 +57,7 @@ private int PrintCallBack(IntPtr data, GitDiffDelta delta, GitDiffRange range, G
5757
return 0;
5858
}
5959

60-
private void AddLineChange(string currentFilePath, GitDiffLineOrigin lineOrigin)
60+
private void AddLineChange(FilePath currentFilePath, GitDiffLineOrigin lineOrigin)
6161
{
6262
switch (lineOrigin)
6363
{
@@ -71,22 +71,22 @@ private void AddLineChange(string currentFilePath, GitDiffLineOrigin lineOrigin)
7171
}
7272
}
7373

74-
private void IncrementLinesDeleted(string filePath)
74+
private void IncrementLinesDeleted(FilePath filePath)
7575
{
7676
linesDeleted++;
7777
this[filePath].LinesDeleted++;
7878
}
7979

80-
private void IncrementLinesAdded(string filePath)
80+
private void IncrementLinesAdded(FilePath filePath)
8181
{
8282
linesAdded++;
8383
this[filePath].LinesAdded++;
8484
}
8585

8686
private void AddFileChange(GitDiffDelta delta)
8787
{
88-
var newFilePath = Utf8Marshaler.FromNative(delta.NewFile.Path);
89-
var oldFilePath = Utf8Marshaler.FromNative(delta.OldFile.Path);
88+
var newFilePath = FilePathMarshaler.FromNative(delta.NewFile.Path);
89+
var oldFilePath = FilePathMarshaler.FromNative(delta.OldFile.Path);
9090
var newMode = (Mode)delta.NewFile.Mode;
9191
var oldMode = (Mode)delta.OldFile.Mode;
9292
var newOid = new ObjectId(delta.NewFile.Oid);
@@ -95,7 +95,7 @@ private void AddFileChange(GitDiffDelta delta)
9595
var diffFile = new TreeEntryChanges(newFilePath, newMode, newOid, delta.Status, oldFilePath, oldMode, oldOid, delta.IsBinary());
9696

9797
fileDispatcher[delta.Status](this, diffFile);
98-
changes.Add(diffFile.Path, diffFile);
98+
changes.Add(newFilePath, diffFile);
9999
}
100100

101101
/// <summary>
@@ -120,6 +120,11 @@ IEnumerator IEnumerable.GetEnumerator()
120120
/// Gets the <see cref = "TreeEntryChanges"/> corresponding to the specified <paramref name = "path"/>.
121121
/// </summary>
122122
public TreeEntryChanges this[string path]
123+
{
124+
get { return this[(FilePath)path]; }
125+
}
126+
127+
private TreeEntryChanges this[FilePath path]
123128
{
124129
get
125130
{

LibGit2Sharp/TreeEntryChanges.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
using LibGit2Sharp.Core;
2+
13
namespace LibGit2Sharp
24
{
35
/// <summary>
46
/// Holds the changes between two versions of a tree entry.
57
/// </summary>
68
public class TreeEntryChanges : Changes
79
{
8-
internal TreeEntryChanges(string path, Mode mode, ObjectId oid, ChangeKind status, string oldPath, Mode oldMode, ObjectId oldOid, bool isBinaryComparison)
10+
internal TreeEntryChanges(FilePath path, Mode mode, ObjectId oid, ChangeKind status, FilePath oldPath, Mode oldMode, ObjectId oldOid, bool isBinaryComparison)
911
{
10-
Path = path;
12+
Path = path.Native;
1113
Mode = mode;
1214
Oid = oid;
1315
Status = status;
14-
OldPath = oldPath;
16+
OldPath = oldPath.Native;
1517
OldMode = oldMode;
1618
OldOid = oldOid;
1719
IsBinaryComparison = isBinaryComparison;

0 commit comments

Comments
 (0)