Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MatchedPathsAggregator.cs « LibGit2Sharp - github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ecae6f2c79dd46d74456265f9fdbca0ea0e15c2f (plain)
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();
        }
    }
}