From 66c41b3329bf36860c1df9f6318d5cef3b8caf8f Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sat, 23 May 2015 11:38:52 +0200 Subject: [PATCH] Obsolete CompareOptions.UsePatienceAlgorithm in favor of .Algorithm Fix #1043 --- LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs | 2 +- LibGit2Sharp/CompareOptions.cs | 10 ++++++++++ LibGit2Sharp/Diff.cs | 2 +- LibGit2Sharp/DiffAlgorithm.cs | 18 ++++++++++++++++++ LibGit2Sharp/LibGit2Sharp.csproj | 1 + 5 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 LibGit2Sharp/DiffAlgorithm.cs diff --git a/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs b/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs index 479b39d78..0e8ef905e 100644 --- a/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs +++ b/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs @@ -1200,7 +1200,7 @@ public void UsingPatienceAlgorithmCompareOptionProducesPatienceDiff() Assert.Equal(diffDefault, repo.Diff.Compare(treeOld, treeNew)); Assert.Equal(diffPatience, repo.Diff.Compare(treeOld, treeNew, - compareOptions: new CompareOptions { UsePatienceAlgorithm = true })); + compareOptions: new CompareOptions { Algorithm = DiffAlgorithm.Patience })); } } } diff --git a/LibGit2Sharp/CompareOptions.cs b/LibGit2Sharp/CompareOptions.cs index fccd75583..6e9acb434 100644 --- a/LibGit2Sharp/CompareOptions.cs +++ b/LibGit2Sharp/CompareOptions.cs @@ -1,3 +1,5 @@ +using System; + namespace LibGit2Sharp { /// @@ -12,6 +14,7 @@ public CompareOptions() { ContextLines = 3; InterhunkLines = 0; + Algorithm = DiffAlgorithm.Meyers; } /// @@ -39,6 +42,13 @@ public CompareOptions() /// /// Use the "patience diff" algorithm. /// + [Obsolete("This property will be removed in the next release. Please use Algorithm instead.")] public bool UsePatienceAlgorithm { get; set; } + + /// + /// Algorithm to be used when performing a Diff. + /// By default, will be used. + /// + public DiffAlgorithm Algorithm { get; set; } } } diff --git a/LibGit2Sharp/Diff.cs b/LibGit2Sharp/Diff.cs index 54ad11b02..265aa0cd6 100644 --- a/LibGit2Sharp/Diff.cs +++ b/LibGit2Sharp/Diff.cs @@ -49,7 +49,7 @@ private static GitDiffOptions BuildOptions(DiffModifiers diffOptions, FilePath[] options.Flags |= GitDiffOptionFlags.GIT_DIFF_INCLUDE_UNMODIFIED; } - if (compareOptions.UsePatienceAlgorithm) + if (compareOptions.Algorithm == DiffAlgorithm.Patience) { options.Flags |= GitDiffOptionFlags.GIT_DIFF_PATIENCE; } diff --git a/LibGit2Sharp/DiffAlgorithm.cs b/LibGit2Sharp/DiffAlgorithm.cs new file mode 100644 index 000000000..9e89e68e6 --- /dev/null +++ b/LibGit2Sharp/DiffAlgorithm.cs @@ -0,0 +1,18 @@ +namespace LibGit2Sharp +{ + /// + /// Algorithm used when performing a Diff. + /// + public enum DiffAlgorithm + { + /// + /// The basic greedy diff algorithm. + /// + Meyers = 0, + + /// + /// Use "patience diff" algorithm when generating patches. + /// + Patience = 2, + } +} diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 856d2433b..1b630e57e 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -79,6 +79,7 @@ +