コード例 #1
0
 public static IEnumerable <GitFileInfo> EnumerateFilesRescursively(this GitDirectoryInfo directory)
 {
     foreach (var subDirectory in directory.Directories)
     {
         foreach (var file in subDirectory.EnumerateFilesRescursively())
         {
             yield return(file);
         }
     }
     foreach (var file in directory.Files)
     {
         yield return(file);
     }
 }
コード例 #2
0
        private Dictionary <string, GitDirectoryInfo> LoadDirectories()
        {
            var directories = new Dictionary <string, GitDirectoryInfo>();

            foreach (var item in m_Tree)
            {
                if (item.Target is Tree subTree)
                {
                    var dir = new GitDirectoryInfo(Commit, item.Name, this, subTree);
                    directories.Add(item.Name, dir);
                }
            }

            return(directories);
        }
コード例 #3
0
        public GitFileInfo(string name, GitDirectoryInfo parent, Blob blob)
        {
            if (String.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("Value must not be null or whitespace", nameof(name));
            }

            if (name.Contains("\\") || name.Contains("/"))
            {
                throw new ArgumentException("Name must not contain directory separators", nameof(name));
            }

            Name     = name;
            m_Parent = parent ?? throw new ArgumentNullException(nameof(parent));
            m_Blob   = blob ?? throw new ArgumentNullException(nameof(blob));
        }
コード例 #4
0
        public GitDirectoryInfo(GitId commit, string name, GitDirectoryInfo parent, Tree tree)
        {
            if (String.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("Value must not be null or whitespace", nameof(name));
            }

            if (name.Contains("\\") || name.Contains("/"))
            {
                throw new ArgumentException("Name must not contain directory separators", nameof(name));
            }

            Commit   = commit;
            Name     = name;
            m_Parent = parent ?? throw new ArgumentNullException(nameof(parent));
            m_Tree   = tree ?? throw new ArgumentNullException(nameof(tree));

            m_Directories = new Lazy <Dictionary <string, GitDirectoryInfo> >(LoadDirectories);
            m_Files       = new Lazy <Dictionary <string, GitFileInfo> >(LoadFiles);
        }
コード例 #5
0
        /// <summary>
        /// Gets files from the specified directory using globbing patterns.
        /// </summary>
        /// <param name="directory">The directory to search.</param>
        /// <param name="patterns">The globbing pattern(s) to use.</param>
        /// <returns>Files that match the globbing pattern(s).</returns>
        /// <remarks>Initially based on code from Reliak.FileSystemGlobbingExtensions (https://github.com/reliak/Reliak.FileSystemGlobbingExtensions).</remarks>
        public static IEnumerable <GitFileInfo> GetFiles(GitDirectoryInfo directory, IEnumerable <string> patterns)
        {
            var matcher = new Matcher(NormalizedPath.DefaultComparisonType);

            // Expand braces
            var expandedPatterns = patterns
                                   .SelectMany(ExpandBraces)
                                   .Select(f => f.Replace("\\{", "{").Replace("\\}", "}")); // Unescape braces

            // Add the patterns, any that start with ! are exclusions
            foreach (var expandedPattern in expandedPatterns)
            {
                var isExclude    = expandedPattern[0] == '!';
                var finalPattern = isExclude ? expandedPattern.Substring(1) : expandedPattern;
                finalPattern = finalPattern
                               .Replace("\\!", "!") // Unescape negation
                               .Replace("\\", "/"); // Normalize slashes

                // No support for absolute paths
                if (Path.IsPathRooted(finalPattern))
                {
                    throw new ArgumentException($"Rooted globbing patterns are not supported ({expandedPattern})", nameof(patterns));
                }

                // Add exclude or include pattern to matcher
                if (isExclude)
                {
                    matcher.AddExclude(finalPattern);
                }
                else
                {
                    matcher.AddInclude(finalPattern);
                }
            }

            var result = matcher.Execute(directory);

            return(result.Files.Select(match => directory.GetFile(match.Path)).Cast <GitFileInfo>());
        }