public IList<TreeFileData> ParseFilesToAdd(GitOutput output) { Assert.IsNotNull(output); if(output.ExitCode != 0 && output.ExitCode != 128) { return new List<TreeFileData>(0); } var files = output.Output; var l = files.Length; var pos = 0; var res = new List<TreeFileData>(); while(pos < l) { int eol = files.IndexOf('\n', pos); if(eol == -1) eol = l; var status = FileStatus.Cached; string filePath = null; switch(files[pos]) { case 'a': status = FileStatus.Added; filePath = files.Substring(pos + 5, eol - pos - 6); break; case 'r': status = FileStatus.Removed; filePath = files.Substring(pos + 8, eol - pos - 9); break; case 'T': eol = l; break; } if(filePath != null) { var slashPos = filePath.LastIndexOf('/'); var fileName = slashPos != -1 ? filePath.Substring(slashPos + 1) : filePath; var file = new TreeFileData( filePath, status, ConflictType.None, StagedStatus.Unstaged); res.Add(file); pos = eol + 1; } else { pos = eol + 1; } } return res; }
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(); } } }