-
Notifications
You must be signed in to change notification settings - Fork 894
/
Copy pathMatchedPathsAggregator.cs
43 lines (37 loc) · 1.42 KB
/
MatchedPathsAggregator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Collections;
using System.Collections.Generic;
using LibGit2Sharp.Core;
namespace LibGit2Sharp
{
internal class MatchedPathsAggregator : IEnumerable<FilePath>
{
private readonly List<FilePath> matchedPaths = new List<FilePath>();
/// <summary>
/// The delegate with a signature that matches the native diff git_diff_notify_cb function's signature.
/// </summary>
/// <param name="diffListSoFar">The diff list so far, before the delta is inserted.</param>
/// <param name="deltaToAdd">The delta that is being diffed</param>
/// <param name="matchedPathspec">The pathsec that matched the path of the diffed files.</param>
/// <param name="payload">Payload object.</param>
internal int OnGitDiffNotify(IntPtr diffListSoFar, IntPtr deltaToAdd, IntPtr matchedPathspec, IntPtr payload)
{
// Convert null strings into empty strings.
var path = LaxFilePathMarshaler.FromNative(matchedPathspec) ?? FilePath.Empty;
if (matchedPaths.Contains(path))
{
return 0;
}
matchedPaths.Add(path);
return 0;
}
public IEnumerator<FilePath> GetEnumerator()
{
return matchedPaths.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}