コード例 #1
0
        public static IEnumerable <GitFile> Load(
            string filter      = null,
            string dir         = null,
            LfxFileFlags flags = LfxFileFlags.Default)
        {
            GitFileFlags gitFlags = default(GitFileFlags);

            if ((flags & LfxFileFlags.Tracked) != 0)
            {
                gitFlags |= GitFileFlags.Tracked;
            }

            if ((flags & LfxFileFlags.Untracked) != 0)
            {
                gitFlags |= GitFileFlags.Untracked;
            }

            var lfxFiles = GitFile.Load(filter, dir, gitFlags)
                           .Where(o => o.IsDefined("filter", "lfx"));

            if ((flags & LfxFileFlags.Content) != 0)
            {
                lfxFiles = lfxFiles.Where(o => !LfxPointer.CanLoad(o.Path));
            }

            if ((flags & LfxFileFlags.Pointer) != 0)
            {
                lfxFiles = lfxFiles.Where(o => LfxPointer.CanLoad(o.Path));
            }

            return(lfxFiles);
        }
コード例 #2
0
ファイル: GitFile.cs プロジェクト: kingces95/lfx
 public GitFile(
     string path,
     GitFileFlags flags,
     Dictionary <string, string> attributes)
 {
     m_path       = path;
     m_flags      = flags;
     m_pathLower  = m_path.ToLower();
     m_attributes = attributes;
 }
コード例 #3
0
ファイル: GitFile.cs プロジェクト: kingces95/lfx
        public static IEnumerable <GitFile> Load(
            string filter      = null,
            string dir         = null,
            GitFileFlags flags = GitFileFlags.All)
        {
            if (dir == null)
            {
                dir = Environment.CurrentDirectory;
            }
            dir = IOPath.GetFullPath(dir.ToDir());

            // tracked, untracked files
            var lsFilesCommand = $"ls-files {filter}";

            if ((flags & GitFileFlags.Tracked) != 0)
            {
                lsFilesCommand += " -c";
            }
            if ((flags & GitFileFlags.Untracked) != 0)
            {
                lsFilesCommand += " -o";
            }

            // ls-files | check-attr
            var stream = GitCmd.Stream(lsFilesCommand, dir)
                         .PipeTo(GitCmd.Exe, "check-attr -a --stdin", dir);

            // parse output
            Uri currentPath = null;
            Dictionary <string, string> attributes = null;

            var dirUrl = dir.ToUrl();

            foreach (var line in new StreamReader(stream).Lines())
            {
                var match = Regex.Match(line, AttributeRegex, RegexOptions.IgnoreCase);
                var path  = match.Get(PatternPath);
                var key   = match.Get(PatternName);
                var value = match.Get(PatternValue);

                var thisPath = new Uri(dirUrl, path);

                if (string.IsNullOrEmpty(value))
                {
                    value = null;
                }

                if (currentPath != thisPath)
                {
                    if (currentPath != null)
                    {
                        yield return(new GitFile(
                                         currentPath.LocalPath, flags, attributes));
                    }

                    currentPath = thisPath;
                    attributes  = new Dictionary <string, string>(
                        StringComparer.InvariantCultureIgnoreCase);
                }

                attributes[key] = value;
            }

            if (currentPath != null)
            {
                yield return(new GitFile(
                                 currentPath.LocalPath, flags, attributes));
            }
        }