@@ -19,12 +19,15 @@ public class Diff
19
19
{
20
20
private readonly Repository repo ;
21
21
22
- private static GitDiffOptions BuildOptions ( DiffOptions diffOptions , FilePath [ ] filePaths = null , MatchedPathsAggregator matchedPathsAggregator = null )
22
+ private static GitDiffOptions BuildOptions ( DiffOptions diffOptions , FilePath [ ] filePaths = null , MatchedPathsAggregator matchedPathsAggregator = null , CompareOptions compareOptions = null )
23
23
{
24
24
var options = new GitDiffOptions ( ) ;
25
25
26
26
options . Flags |= GitDiffOptionFlags . GIT_DIFF_INCLUDE_TYPECHANGE ;
27
- options . ContextLines = 3 ;
27
+
28
+ compareOptions = compareOptions ?? new CompareOptions ( ) ;
29
+ options . ContextLines = ( ushort ) compareOptions . ContextLines ;
30
+ options . InterhunkLines = ( ushort ) compareOptions . InterhunkLines ;
28
31
29
32
if ( diffOptions . HasFlag ( DiffOptions . IncludeUntracked ) )
30
33
{
@@ -110,8 +113,9 @@ internal Diff(Repository repo)
110
113
/// If set, the passed <paramref name="paths"/> will be treated as explicit paths.
111
114
/// Use these options to determine how unmatched explicit paths should be handled.
112
115
/// </param>
116
+ /// <param name = "compareOptions">Additional options to define comparison behavior.</param>
113
117
/// <returns>A <see cref = "TreeChanges"/> containing the changes between the <paramref name = "oldTree"/> and the <paramref name = "newTree"/>.</returns>
114
- public virtual TreeChanges Compare ( Tree oldTree , Tree newTree , IEnumerable < string > paths = null , ExplicitPathsOptions explicitPathsOptions = null )
118
+ public virtual TreeChanges Compare ( Tree oldTree , Tree newTree , IEnumerable < string > paths = null , ExplicitPathsOptions explicitPathsOptions = null , CompareOptions compareOptions = null )
115
119
{
116
120
var comparer = TreeToTree ( repo ) ;
117
121
ObjectId oldTreeId = oldTree != null ? oldTree . Id : null ;
@@ -129,18 +133,19 @@ public virtual TreeChanges Compare(Tree oldTree, Tree newTree, IEnumerable<strin
129
133
}
130
134
}
131
135
132
- return BuildTreeChangesFromComparer ( oldTreeId , newTreeId , comparer , diffOptions , paths , explicitPathsOptions ) ;
136
+ return BuildTreeChangesFromComparer ( oldTreeId , newTreeId , comparer , diffOptions , paths , explicitPathsOptions , compareOptions ) ;
133
137
}
134
138
135
139
/// <summary>
136
140
/// Show changes between two <see cref = "Blob"/>s.
137
141
/// </summary>
138
142
/// <param name = "oldBlob">The <see cref = "Blob"/> you want to compare from.</param>
139
143
/// <param name = "newBlob">The <see cref = "Blob"/> you want to compare to.</param>
144
+ /// <param name = "compareOptions">Additional options to define comparison behavior.</param>
140
145
/// <returns>A <see cref = "ContentChanges"/> containing the changes between the <paramref name = "oldBlob"/> and the <paramref name = "newBlob"/>.</returns>
141
- public virtual ContentChanges Compare ( Blob oldBlob , Blob newBlob )
146
+ public virtual ContentChanges Compare ( Blob oldBlob , Blob newBlob , CompareOptions compareOptions = null )
142
147
{
143
- using ( GitDiffOptions options = BuildOptions ( DiffOptions . None ) )
148
+ using ( GitDiffOptions options = BuildOptions ( DiffOptions . None , compareOptions : compareOptions ) )
144
149
{
145
150
return new ContentChanges ( repo , oldBlob , newBlob , options ) ;
146
151
}
@@ -168,8 +173,9 @@ private static IDictionary<DiffTargets, Func<Repository, TreeComparisonHandleRet
168
173
/// If set, the passed <paramref name="paths"/> will be treated as explicit paths.
169
174
/// Use these options to determine how unmatched explicit paths should be handled.
170
175
/// </param>
176
+ /// <param name = "compareOptions">Additional options to define comparison behavior.</param>
171
177
/// <returns>A <see cref = "TreeChanges"/> containing the changes between the <see cref="Tree"/> and the selected target.</returns>
172
- public virtual TreeChanges Compare ( Tree oldTree , DiffTargets diffTargets , IEnumerable < string > paths = null , ExplicitPathsOptions explicitPathsOptions = null )
178
+ public virtual TreeChanges Compare ( Tree oldTree , DiffTargets diffTargets , IEnumerable < string > paths = null , ExplicitPathsOptions explicitPathsOptions = null , CompareOptions compareOptions = null )
173
179
{
174
180
var comparer = handleRetrieverDispatcher [ diffTargets ] ( repo ) ;
175
181
ObjectId oldTreeId = oldTree != null ? oldTree . Id : null ;
@@ -188,7 +194,7 @@ public virtual TreeChanges Compare(Tree oldTree, DiffTargets diffTargets, IEnume
188
194
}
189
195
}
190
196
191
- return BuildTreeChangesFromComparer ( oldTreeId , null , comparer , diffOptions , paths , explicitPathsOptions ) ;
197
+ return BuildTreeChangesFromComparer ( oldTreeId , null , comparer , diffOptions , paths , explicitPathsOptions , compareOptions ) ;
192
198
}
193
199
194
200
/// <summary>
@@ -200,14 +206,15 @@ public virtual TreeChanges Compare(Tree oldTree, DiffTargets diffTargets, IEnume
200
206
/// If set, the passed <paramref name="paths"/> will be treated as explicit paths.
201
207
/// Use these options to determine how unmatched explicit paths should be handled.
202
208
/// </param>
209
+ /// <param name = "compareOptions">Additional options to define comparison behavior.</param>
203
210
/// <returns>A <see cref = "TreeChanges"/> containing the changes between the working directory and the index.</returns>
204
- public virtual TreeChanges Compare ( IEnumerable < string > paths = null , bool includeUntracked = false , ExplicitPathsOptions explicitPathsOptions = null )
211
+ public virtual TreeChanges Compare ( IEnumerable < string > paths = null , bool includeUntracked = false , ExplicitPathsOptions explicitPathsOptions = null , CompareOptions compareOptions = null )
205
212
{
206
- return Compare ( includeUntracked ? DiffOptions . IncludeUntracked : DiffOptions . None , paths , explicitPathsOptions ) ;
213
+ return Compare ( includeUntracked ? DiffOptions . IncludeUntracked : DiffOptions . None , paths , explicitPathsOptions , compareOptions ) ;
207
214
}
208
215
209
216
internal virtual TreeChanges Compare ( DiffOptions diffOptions , IEnumerable < string > paths = null ,
210
- ExplicitPathsOptions explicitPathsOptions = null )
217
+ ExplicitPathsOptions explicitPathsOptions = null , CompareOptions compareOptions = null )
211
218
{
212
219
var comparer = WorkdirToIndex ( repo ) ;
213
220
@@ -222,7 +229,7 @@ internal virtual TreeChanges Compare(DiffOptions diffOptions, IEnumerable<string
222
229
}
223
230
}
224
231
225
- return BuildTreeChangesFromComparer ( null , null , comparer , diffOptions , paths , explicitPathsOptions ) ;
232
+ return BuildTreeChangesFromComparer ( null , null , comparer , diffOptions , paths , explicitPathsOptions , compareOptions ) ;
226
233
}
227
234
228
235
private delegate DiffListSafeHandle TreeComparisonHandleRetriever ( ObjectId oldTreeId , ObjectId newTreeId , GitDiffOptions options ) ;
@@ -275,14 +282,12 @@ private static TreeComparisonHandleRetriever IndexToTree(Repository repo)
275
282
return ( oh , nh , o ) => Proxy . git_diff_tree_to_index ( repo . Handle , repo . Index . Handle , oh , o ) ;
276
283
}
277
284
278
- private TreeChanges BuildTreeChangesFromComparer (
279
- ObjectId oldTreeId , ObjectId newTreeId , TreeComparisonHandleRetriever comparisonHandleRetriever ,
280
- DiffOptions diffOptions , IEnumerable < string > paths = null , ExplicitPathsOptions explicitPathsOptions = null )
285
+ private TreeChanges BuildTreeChangesFromComparer ( ObjectId oldTreeId , ObjectId newTreeId , TreeComparisonHandleRetriever comparisonHandleRetriever , DiffOptions diffOptions , IEnumerable < string > paths = null , ExplicitPathsOptions explicitPathsOptions = null , CompareOptions compareOptions = null )
281
286
{
282
287
var matchedPaths = new MatchedPathsAggregator ( ) ;
283
288
var filePaths = ToFilePaths ( repo , paths ) ;
284
289
285
- using ( GitDiffOptions options = BuildOptions ( diffOptions , filePaths , matchedPaths ) )
290
+ using ( GitDiffOptions options = BuildOptions ( diffOptions , filePaths , matchedPaths , compareOptions ) )
286
291
using ( DiffListSafeHandle diffList = comparisonHandleRetriever ( oldTreeId , newTreeId , options ) )
287
292
{
288
293
if ( explicitPathsOptions != null )
0 commit comments