public override void LineReceived(string line) { if (line == null) { ReturnGitLogEntry(); return; } sb.AppendLine(line); if (phase == ProcessingPhase.Files && seenBodyEnd) { seenBodyEnd = false; var proc = new LineParser(line); if (proc.Matches(hashRegex)) { // there's no files on this commit, it's a new one! ReturnGitLogEntry(); } } switch (phase) { case ProcessingPhase.CommitHash: commitId = line; phase++; break; case ProcessingPhase.ParentHash: var parentHashes = line.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); if (parentHashes.Length > 1) { mergeA = parentHashes[0]; mergeB = parentHashes[1]; } phase++; break; case ProcessingPhase.AuthorName: authorName = line; phase++; break; case ProcessingPhase.AuthorEmail: authorEmail = line; phase++; break; case ProcessingPhase.AuthorDate: DateTimeOffset t; if (DateTimeOffset.TryParse(line, out t)) { time = t; } else { Logger.Error("ERROR {0}", sb.ToString()); throw new FormatException("Invalid line"); } phase++; break; case ProcessingPhase.CommitterName: committerName = line; phase++; break; case ProcessingPhase.CommitterEmail: committerEmail = line; phase++; break; case ProcessingPhase.CommitterDate: committerTime = DateTimeOffset.Parse(line); phase++; break; case ProcessingPhase.Summary: { var idx = line.IndexOf("---GHUBODYEND---", StringComparison.InvariantCulture); var oneliner = idx >= 0; if (oneliner) { line = line.Substring(0, idx); } summary = line; descriptionLines.Add(line); phase++; // there's no description so skip it if (oneliner) { phase++; seenBodyEnd = true; } } break; case ProcessingPhase.Description: var indexOf = line.IndexOf("---GHUBODYEND---", StringComparison.InvariantCulture); if (indexOf == -1) { descriptionLines.Add(line); } else if (indexOf == 0) { phase++; seenBodyEnd = true; } else { var substring = line.Substring(0, indexOf); descriptionLines.Add(substring); phase++; seenBodyEnd = true; } break; case ProcessingPhase.Files: if (line == string.Empty) { ReturnGitLogEntry(); return; } if (line.IndexOf("---GHUBODYEND---", StringComparison.InvariantCulture) >= 0) { seenBodyEnd = true; return; } var proc = new LineParser(line); string file = null; GitFileStatus status; string originalPath = null; if (proc.Matches('M')) { status = GitFileStatus.Modified; } else if (proc.Matches('A')) { status = GitFileStatus.Added; } else if (proc.Matches('D')) { status = GitFileStatus.Deleted; } else if (proc.Matches('R')) { status = GitFileStatus.Renamed; } else if (proc.Matches('C')) { status = GitFileStatus.Copied; } else if (proc.Matches('T')) { status = GitFileStatus.TypeChange; } else if (proc.Matches('U')) { status = GitFileStatus.Unmerged; } else if (proc.Matches('X')) { status = GitFileStatus.Unknown; } else if (proc.Matches('B')) { status = GitFileStatus.Broken; } else if (String.IsNullOrEmpty(line)) { // there's no files on this commit, it's a new one! ReturnGitLogEntry(); return; } else { HandleUnexpected(line); return; } switch (status) { case GitFileStatus.Modified: case GitFileStatus.Added: case GitFileStatus.Deleted: proc.SkipWhitespace(); file = proc.Matches('"') ? proc.ReadUntil('"') : proc.ReadToEnd(); break; case GitFileStatus.Renamed: proc.SkipWhitespace(); originalPath = proc.Matches('"') ? proc.ReadUntil('"') : proc.ReadUntilWhitespace(); proc.SkipWhitespace(); file = proc.Matches('"') ? proc.ReadUntil('"') : proc.ReadToEnd(); break; default: proc.SkipWhitespace(); file = proc.Matches('"') ? proc.ReadUntil('"') : proc.ReadUntilWhitespace(); if (file == null) { file = proc.ReadToEnd(); } break; } changes.Add(gitObjectFactory.CreateGitStatusEntry(file, status, originalPath)); break; default: HandleUnexpected(line); break; } }
public override void LineReceived(string line) { if (line == null) { ReturnStatus(); } else { Prepare(); var proc = new LineParser(line); if (gitStatus.LocalBranch == null) { if (proc.Matches("##")) { proc.MoveToAfter('#'); proc.SkipWhitespace(); string branchesString; if (proc.Matches(branchTrackedAndDelta)) { //master...origin/master [ahead 1] //master...origin/master [behind 1] //master...origin/master [ahead 1, behind 1] branchesString = proc.ReadUntilWhitespace(); proc.MoveToAfter('['); var deltaString = proc.ReadUntil(']'); var deltas = deltaString.Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries); foreach (var delta in deltas) { var deltaComponents = delta.Split(' '); if (deltaComponents[0] == "ahead") { gitStatus.Ahead = Int32.Parse(deltaComponents[1]); } else if (deltaComponents[0] == "behind") { gitStatus.Behind = Int32.Parse(deltaComponents[1]); } else if (deltaComponents[0] == "gone") { } else { throw new InvalidOperationException("Unexpected deltaComponent in o"); } } } else { branchesString = proc.ReadToEnd(); } var branches = branchesString.Split(new[] { "..." }, StringSplitOptions.RemoveEmptyEntries); gitStatus.LocalBranch = branches[0]; if (branches.Length == 2) { gitStatus.RemoteBranch = branches[1]; } } else { HandleUnexpected(line); } } else { // M GitHubVS.sln //R README.md -> README2.md // D deploy.cmd //A something added.txt //?? something.txt string originalPath = null; string path = null; var status = GitFileStatus.Added; var staged = false; if (proc.Matches('?')) { //?? something.txt proc.MoveToAfter('?'); proc.SkipWhitespace(); path = proc.ReadToEnd().Trim('"'); status = GitFileStatus.Untracked; } else if (proc.Matches('!')) { //?? something.txt proc.MoveToAfter('!'); proc.SkipWhitespace(); path = proc.ReadToEnd().Trim('"'); status = GitFileStatus.Ignored; } else { if (proc.IsAtWhitespace) { proc.SkipWhitespace(); } else { staged = true; } if (proc.Matches('M')) { //M GitHubVS.sln proc.MoveNext(); proc.SkipWhitespace(); path = proc.ReadToEnd().Trim('"'); status = GitFileStatus.Modified; } else if (proc.Matches('D')) { //D deploy.cmd proc.MoveNext(); proc.SkipWhitespace(); path = proc.ReadToEnd().Trim('"'); status = GitFileStatus.Deleted; } else if (proc.Matches('R')) { //R README.md -> README2.md proc.MoveNext(); proc.SkipWhitespace(); var files = proc.ReadToEnd() .Split(new[] { "->" }, StringSplitOptions.RemoveEmptyEntries) .Select(s => s.Trim()) .Select(s => s.Trim('"')) .ToArray(); originalPath = files[0]; path = files[1]; status = GitFileStatus.Renamed; } else if (proc.Matches('A')) { //A something added.txt proc.MoveNext(); proc.SkipWhitespace(); path = proc.ReadToEnd().Trim('"'); status = GitFileStatus.Added; } else { HandleUnexpected(line); } } var gitStatusEntry = gitObjectFactory.CreateGitStatusEntry(path, status, originalPath, staged); gitStatus.Entries.Add(gitStatusEntry); } } }
protected override bool ProcessLine(string line, out GitLogEntry result) { base.ProcessLine(line, out result); if (line == null) { ReturnGitLogEntry(); return(false); } sb.AppendLine(line); if (phase == ProcessingPhase.Files && seenBodyEnd) { seenBodyEnd = false; var proc = new LineParser(line); if (proc.Matches(hashRegex)) { // there's no files on this commit, it's a new one! ReturnGitLogEntry(); } } switch (phase) { case ProcessingPhase.CommitHash: commitId = line; phase++; break; case ProcessingPhase.ParentHash: var parentHashes = line.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); if (parentHashes.Length > 1) { mergeA = parentHashes[0]; mergeB = parentHashes[1]; } phase++; break; case ProcessingPhase.AuthorName: authorName = line; phase++; break; case ProcessingPhase.AuthorEmail: authorEmail = line; phase++; break; case ProcessingPhase.AuthorDate: DateTimeOffset t; if (DateTimeOffset.TryParse(line, out t)) { time = t; } else { Logger.Error("ERROR {0}", sb.ToString()); throw new FormatException("Invalid line"); } phase++; break; case ProcessingPhase.CommitterName: committerName = line; phase++; break; case ProcessingPhase.CommitterEmail: committerEmail = line; phase++; break; case ProcessingPhase.CommitterDate: committerTime = DateTimeOffset.Parse(line); phase++; break; case ProcessingPhase.Summary: { var idx = line.IndexOf("---GHUBODYEND---", StringComparison.Ordinal); var oneliner = idx >= 0; if (oneliner) { line = line.Substring(0, idx); } summary = line; phase++; // there's no description so skip it if (oneliner) { phase++; seenBodyEnd = true; } } break; case ProcessingPhase.Description: var indexOf = line.IndexOf("---GHUBODYEND---", StringComparison.InvariantCulture); if (indexOf == -1) { descriptionLines.Add(line); } else if (indexOf == 0) { phase++; seenBodyEnd = true; } else { var substring = line.Substring(0, indexOf); descriptionLines.Add(substring); phase++; seenBodyEnd = true; } break; case ProcessingPhase.Files: if (string.IsNullOrEmpty(line)) { ReturnGitLogEntry(); return(false); } if (line.IndexOf("---GHUBODYEND---", StringComparison.InvariantCulture) >= 0) { seenBodyEnd = true; return(false); } var proc = new LineParser(line); string file = null; GitFileStatus status = GitFileStatus.None; string originalPath = null; if (proc.IsAtEnd) { // there's no files on this commit, it's a new one! ReturnGitLogEntry(); return(false); } else { status = GitStatusEntry.ParseStatusMarker(proc.ReadChar()); } if (status == GitFileStatus.None) { HandleUnexpected(line); return(false); } proc.ReadUntilWhitespace(); if (status == GitFileStatus.Copied || status == GitFileStatus.Renamed) { var files = proc.ReadToEnd().Trim() .Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries) .Select(s => s.Trim()) .Select(s => s.Trim('"')) .ToArray(); originalPath = files[0]; file = files[1]; } else { file = proc.ReadToEnd().Trim().Trim('"'); } changes.Add(gitObjectFactory.CreateGitStatusEntry(file, status, GitFileStatus.None, originalPath)); break; default: HandleUnexpected(line); break; } return(false); }