Skip to content

Commit 98be00a

Browse files
committed
Take account of CompareOptions.IndentHeuristic
When this flag is set, enable the GIT_DIFF_INDENT_HEURISTIC option.
1 parent 6a6f134 commit 98be00a

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

LibGit2Sharp/Core/GitDiff.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ internal enum GitDiffOptionFlags
133133
* Options controlling how output will be generated
134134
*/
135135

136+
/// <summary>
137+
/// Use a heuristic that takes indentation and whitespace into account
138+
/// which generally can produce better diffs when dealing with ambiguous
139+
/// diff hunks.
140+
/// </summary>
141+
GIT_DIFF_INDENT_HEURISTIC = (1 << 18),
142+
136143
/// <summary>
137144
/// Treat all files as text, disabling binary attributes and detection
138145
/// </summary>
@@ -304,11 +311,11 @@ enum GitDiffLineOrigin : byte
304311

305312
enum GitDiffFormat
306313
{
307-
GIT_DIFF_FORMAT_PATCH = 1, // < full git diff
314+
GIT_DIFF_FORMAT_PATCH = 1, // < full git diff
308315
GIT_DIFF_FORMAT_PATCH_HEADER = 2, // < just the file headers of patch
309-
GIT_DIFF_FORMAT_RAW = 3, // < like git diff --raw
310-
GIT_DIFF_FORMAT_NAME_ONLY = 4, // < like git diff --name-only
311-
GIT_DIFF_FORMAT_NAME_STATUS = 5, // < like git diff --name-status
316+
GIT_DIFF_FORMAT_RAW = 3, // < like git diff --raw
317+
GIT_DIFF_FORMAT_NAME_ONLY = 4, // < like git diff --name-only
318+
GIT_DIFF_FORMAT_NAME_STATUS = 5, // < like git diff --name-status
312319
}
313320

314321
[Flags]

LibGit2Sharp/Diff.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ private static GitDiffOptions BuildOptions(DiffModifiers diffOptions, FilePath[]
6363
options.Flags |= GitDiffOptionFlags.GIT_DIFF_DISABLE_PATHSPEC_MATCH;
6464
}
6565

66+
if (compareOptions.IndentHeuristic)
67+
{
68+
options.Flags |= GitDiffOptionFlags.GIT_DIFF_INDENT_HEURISTIC;
69+
}
70+
6671
if (matchedPathsAggregator != null)
6772
{
6873
options.NotifyCallback = matchedPathsAggregator.OnGitDiffNotify;
@@ -351,7 +356,7 @@ public virtual T Compare<T>(Tree oldTree, DiffTargets diffTargets, IEnumerable<s
351356
}
352357

353358
DiffHandle diff = BuildDiffList(oldTreeId, null, comparer, diffOptions, paths, explicitPathsOptions, compareOptions);
354-
359+
355360
try
356361
{
357362
return BuildDiffResult<T>(diff);

0 commit comments

Comments
 (0)