Ejemplo n.º 1
0
        public void Parse(ITextSegment textSegment)
        {
            Verify.Argument.IsNotNull(textSegment, nameof(textSegment));

            while (textSegment.Length > 0)
            {
                if (_line.Parse(textSegment))
                {
                    bool staged             = false;
                    bool unstaged           = false;
                    var  conflictType       = ConflictType.None;
                    var  stagedFileStatus   = FileStatus.Unknown;
                    var  unstagedFileStatus = FileStatus.Unknown;

                    var x  = _line.X;
                    var y  = _line.Y;
                    var to = _line.To;

                    if (x == '?')
                    {
                        staged             = false;
                        unstaged           = true;
                        unstagedFileStatus = FileStatus.Added;
                        ++_unstagedUntrackedCount;
                    }
                    else
                    {
                        if (x == 'C' || x == 'R')
                        {
                            var from = _line.From;
                            if (x == 'C')
                            {
                                x = 'A';
                                stagedFileStatus = FileStatus.Added;
                            }
                            else
                            {
                                if (!_stagedFiles.ContainsKey(from))
                                {
                                    var file = new TreeFileData(from, FileStatus.Removed, ConflictType.None, StagedStatus.Staged);
                                    _stagedFiles.Add(from, file);
                                    ++_stagedRemovedCount;
                                }
                                x = 'A';
                                stagedFileStatus = FileStatus.Added;
                            }
                        }
                        conflictType = GetConflictType(x, y);
                        if (conflictType != ConflictType.None)
                        {
                            staged             = false;
                            unstaged           = true;
                            unstagedFileStatus = FileStatus.Unmerged;
                            ++_unmergedCount;
                        }
                        else
                        {
                            if (x != ' ')
                            {
                                staged           = true;
                                stagedFileStatus = CharToFileStatus(x);
                                AddStagedStats(stagedFileStatus, 1);
                            }
                            if (y != ' ')
                            {
                                unstaged           = true;
                                unstagedFileStatus = CharToFileStatus(y);
                                AddUnstagedStats(unstagedFileStatus, 1);
                            }
                        }
                    }

                    if (staged)
                    {
                        var file = new TreeFileData(to, stagedFileStatus, ConflictType.None, StagedStatus.Staged);
                        if (_stagedFiles.TryGetValue(to, out var existing))
                        {
                            AddStagedStats(existing.FileStatus, -1);
                            _stagedFiles[to] = file;
                        }
                        else
                        {
                            _stagedFiles.Add(to, file);
                        }
                    }
                    if (unstaged)
                    {
                        var file = new TreeFileData(to, unstagedFileStatus, conflictType, StagedStatus.Unstaged);
                        if (_unstagedFiles.TryGetValue(to, out var existing))
                        {
                            if (existing.FileStatus == FileStatus.Removed)
                            {
                                --_unstagedRemovedCount;
                                _unstagedFiles[to] = file;
                            }
                        }
                        else
                        {
                            _unstagedFiles.Add(to, file);
                        }
                    }

                    _line.Reset();
                }
            }
        }