Skip to content

Commit e0c3f31

Browse files
author
Jakub Dropia
committed
Expose diff whitespace settings
1 parent 1af4954 commit e0c3f31

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

LibGit2Sharp/CompareOptions.cs

+25
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
namespace LibGit2Sharp
44
{
5+
/// <summary>
6+
/// Represents a mode for handling whitespace while making diff.
7+
/// </summary>
8+
public enum DiffWhitespaceMode
9+
{
10+
/// <summary>
11+
/// Ignore all whitespace
12+
/// </summary>
13+
IgnoreAllWhitespaces,
14+
/// <summary>
15+
/// Ignore changes in amount of whitespace
16+
/// </summary>
17+
IgnoreWhitespaceChange,
18+
/// <summary>
19+
/// Ignore whitespace at end of line
20+
/// </summary>
21+
IgnoreWhitespaceEol
22+
}
23+
524
/// <summary>
625
/// Options to define file comparison behavior.
726
/// </summary>
@@ -34,6 +53,12 @@ public CompareOptions()
3453
/// </summary>
3554
public SimilarityOptions Similarity { get; set; }
3655

56+
/// <summary>
57+
/// Represents a mode for handling whitespace while making diff.
58+
/// By default is null - it means no extra flag is passed
59+
/// </summary>
60+
public DiffWhitespaceMode? WhitespaceMode { get; set; }
61+
3762
/// <summary>
3863
/// Include "unmodified" entries in the results.
3964
/// </summary>

LibGit2Sharp/Diff.cs

+17-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ private static GitDiffOptions BuildOptions(DiffModifiers diffOptions, FilePath[]
5858
options.Flags |= GitDiffOptionFlags.GIT_DIFF_MINIMAL;
5959
}
6060

61+
if (compareOptions.WhitespaceMode != null)
62+
{
63+
if (compareOptions.WhitespaceMode == DiffWhitespaceMode.IgnoreAllWhitespaces)
64+
{
65+
options.Flags |= GitDiffOptionFlags.GIT_DIFF_IGNORE_WHITESPACE;
66+
}
67+
else if (compareOptions.WhitespaceMode == DiffWhitespaceMode.IgnoreWhitespaceChange)
68+
{
69+
options.Flags |= GitDiffOptionFlags.GIT_DIFF_IGNORE_WHITESPACE_CHANGE;
70+
}
71+
else
72+
{
73+
options.Flags |= GitDiffOptionFlags.GIT_DIFF_IGNORE_WHITESPACE_EOL;
74+
}
75+
}
76+
6177
if (diffOptions.HasFlag(DiffModifiers.DisablePathspecMatch))
6278
{
6379
options.Flags |= GitDiffOptionFlags.GIT_DIFF_DISABLE_PATHSPEC_MATCH;
@@ -546,7 +562,7 @@ private DiffHandle BuildDiffList(
546562

547563
MatchedPathsAggregator matchedPaths = null;
548564

549-
// We can't match paths unless we've got something to match
565+
// We can't match paths unless we've got something to match
550566
// against and we're told to do so.
551567
if (filePaths != null && explicitPathsOptions != null)
552568
{

0 commit comments

Comments
 (0)