Skip to content

Expose a more generic DiffAlgorithm property in CompareOptions #1043

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

Merged
merged 1 commit into from
May 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ public void UsingPatienceAlgorithmCompareOptionProducesPatienceDiff()

Assert.Equal(diffDefault, repo.Diff.Compare<Patch>(treeOld, treeNew));
Assert.Equal(diffPatience, repo.Diff.Compare<Patch>(treeOld, treeNew,
compareOptions: new CompareOptions { UsePatienceAlgorithm = true }));
compareOptions: new CompareOptions { Algorithm = DiffAlgorithm.Patience }));
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions LibGit2Sharp/CompareOptions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

namespace LibGit2Sharp
{
/// <summary>
Expand All @@ -12,6 +14,7 @@ public CompareOptions()
{
ContextLines = 3;
InterhunkLines = 0;
Algorithm = DiffAlgorithm.Meyers;
}

/// <summary>
Expand Down Expand Up @@ -39,6 +42,13 @@ public CompareOptions()
/// <summary>
/// Use the "patience diff" algorithm.
/// </summary>
[Obsolete("This property will be removed in the next release. Please use Algorithm instead.")]
public bool UsePatienceAlgorithm { get; set; }

/// <summary>
/// Algorithm to be used when performing a Diff.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Default = Algorithm.Meyers)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

/// By default, <see cref="DiffAlgorithm.Meyers"/> will be used.
/// </summary>
public DiffAlgorithm Algorithm { get; set; }
}
}
2 changes: 1 addition & 1 deletion LibGit2Sharp/Diff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing check for DiffAlgorithm.Minimal

{
options.Flags |= GitDiffOptionFlags.GIT_DIFF_PATIENCE;
}
Expand Down
18 changes: 18 additions & 0 deletions LibGit2Sharp/DiffAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace LibGit2Sharp
{
/// <summary>
/// Algorithm used when performing a Diff.
/// </summary>
public enum DiffAlgorithm
{
/// <summary>
/// The basic greedy diff algorithm.
/// </summary>
Meyers = 0,

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing DIffAlgorithm.Minimal.

/// <summary>
/// Use "patience diff" algorithm when generating patches.
/// </summary>
Patience = 2,
}
}
1 change: 1 addition & 0 deletions LibGit2Sharp/LibGit2Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<Compile Include="Core\Handles\DescribeResultSafeHandle.cs" />
<Compile Include="Core\Handles\IndexNameEntrySafeHandle.cs" />
<Compile Include="Core\Handles\IndexReucEntrySafeHandle.cs" />
<Compile Include="DiffAlgorithm.cs" />
<Compile Include="EntryExistsException.cs" />
<Compile Include="FetchOptionsBase.cs" />
<Compile Include="LogEntry.cs" />
Expand Down