Skip to content

Commit ef63b09

Browse files
committed
Merge pull request #1043 from libgit2/ntk/diff
Expose a more generic DiffAlgorithm property in CompareOptions
2 parents 659be88 + 66c41b3 commit ef63b09

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ public void UsingPatienceAlgorithmCompareOptionProducesPatienceDiff()
12001200

12011201
Assert.Equal(diffDefault, repo.Diff.Compare<Patch>(treeOld, treeNew));
12021202
Assert.Equal(diffPatience, repo.Diff.Compare<Patch>(treeOld, treeNew,
1203-
compareOptions: new CompareOptions { UsePatienceAlgorithm = true }));
1203+
compareOptions: new CompareOptions { Algorithm = DiffAlgorithm.Patience }));
12041204
}
12051205
}
12061206
}

LibGit2Sharp/CompareOptions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
13
namespace LibGit2Sharp
24
{
35
/// <summary>
@@ -12,6 +14,7 @@ public CompareOptions()
1214
{
1315
ContextLines = 3;
1416
InterhunkLines = 0;
17+
Algorithm = DiffAlgorithm.Meyers;
1518
}
1619

1720
/// <summary>
@@ -39,6 +42,13 @@ public CompareOptions()
3942
/// <summary>
4043
/// Use the "patience diff" algorithm.
4144
/// </summary>
45+
[Obsolete("This property will be removed in the next release. Please use Algorithm instead.")]
4246
public bool UsePatienceAlgorithm { get; set; }
47+
48+
/// <summary>
49+
/// Algorithm to be used when performing a Diff.
50+
/// By default, <see cref="DiffAlgorithm.Meyers"/> will be used.
51+
/// </summary>
52+
public DiffAlgorithm Algorithm { get; set; }
4353
}
4454
}

LibGit2Sharp/Diff.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private static GitDiffOptions BuildOptions(DiffModifiers diffOptions, FilePath[]
4949
options.Flags |= GitDiffOptionFlags.GIT_DIFF_INCLUDE_UNMODIFIED;
5050
}
5151

52-
if (compareOptions.UsePatienceAlgorithm)
52+
if (compareOptions.Algorithm == DiffAlgorithm.Patience)
5353
{
5454
options.Flags |= GitDiffOptionFlags.GIT_DIFF_PATIENCE;
5555
}

LibGit2Sharp/DiffAlgorithm.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace LibGit2Sharp
2+
{
3+
/// <summary>
4+
/// Algorithm used when performing a Diff.
5+
/// </summary>
6+
public enum DiffAlgorithm
7+
{
8+
/// <summary>
9+
/// The basic greedy diff algorithm.
10+
/// </summary>
11+
Meyers = 0,
12+
13+
/// <summary>
14+
/// Use "patience diff" algorithm when generating patches.
15+
/// </summary>
16+
Patience = 2,
17+
}
18+
}

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<Compile Include="Core\Handles\DescribeResultSafeHandle.cs" />
8080
<Compile Include="Core\Handles\IndexNameEntrySafeHandle.cs" />
8181
<Compile Include="Core\Handles\IndexReucEntrySafeHandle.cs" />
82+
<Compile Include="DiffAlgorithm.cs" />
8283
<Compile Include="EntryExistsException.cs" />
8384
<Compile Include="FetchOptionsBase.cs" />
8485
<Compile Include="LogEntry.cs" />

0 commit comments

Comments
 (0)