diff --git a/src/Commands/QueryBranches.cs b/src/Commands/QueryBranches.cs index 5f9d31a8..ee82ce88 100644 --- a/src/Commands/QueryBranches.cs +++ b/src/Commands/QueryBranches.cs @@ -19,29 +19,35 @@ namespace SourceGit.Commands public List Result() { - Exec(); + var branches = new List(); + var rs = ReadToEnd(); + if (!rs.IsSuccess) + return branches; - foreach (var b in _needQueryTrackStatus) - b.TrackStatus = new QueryTrackStatus(WorkingDirectory, b.Name, b.Upstream).Result(); + var lines = rs.StdOut.Split('\n', StringSplitOptions.RemoveEmptyEntries); + foreach (var line in lines) + { + var b = ParseLine(line); + if (b != null) + branches.Add(b); + } - return _branches; + return branches; } - protected override void OnReadline(string line) + private Models.Branch ParseLine(string line) { var parts = line.Split('$'); if (parts.Length != 5) - return; + return null; var branch = new Models.Branch(); var refName = parts[0]; if (refName.EndsWith("/HEAD", StringComparison.Ordinal)) - return; + return null; - if (refName.StartsWith(PREFIX_DETACHED_AT, StringComparison.Ordinal) || refName.StartsWith(PREFIX_DETACHED_FROM, StringComparison.Ordinal)) - { - branch.IsDetachedHead = true; - } + branch.IsDetachedHead = refName.StartsWith(PREFIX_DETACHED_AT, StringComparison.Ordinal) || + refName.StartsWith(PREFIX_DETACHED_FROM, StringComparison.Ordinal); if (refName.StartsWith(PREFIX_LOCAL, StringComparison.Ordinal)) { @@ -53,7 +59,7 @@ namespace SourceGit.Commands var name = refName.Substring(PREFIX_REMOTE.Length); var shortNameIdx = name.IndexOf('/', StringComparison.Ordinal); if (shortNameIdx < 0) - return; + return null; branch.Remote = name.Substring(0, shortNameIdx); branch.Name = name.Substring(branch.Remote.Length + 1); @@ -71,14 +77,11 @@ namespace SourceGit.Commands branch.Upstream = parts[3]; if (branch.IsLocal && !string.IsNullOrEmpty(parts[4]) && !parts[4].Equals("=", StringComparison.Ordinal)) - _needQueryTrackStatus.Add(branch); + branch.TrackStatus = new QueryTrackStatus(WorkingDirectory, branch.Name, branch.Upstream).Result(); else branch.TrackStatus = new Models.BranchTrackStatus(); - _branches.Add(branch); + return branch; } - - private readonly List _branches = new List(); - private List _needQueryTrackStatus = new List(); } } diff --git a/src/Commands/QueryTags.cs b/src/Commands/QueryTags.cs index 2abbe277..7da324de 100644 --- a/src/Commands/QueryTags.cs +++ b/src/Commands/QueryTags.cs @@ -14,31 +14,43 @@ namespace SourceGit.Commands public List Result() { - Exec(); - return _loaded; + var tags = new List(); + var rs = ReadToEnd(); + if (!rs.IsSuccess) + return tags; + + var lines = rs.StdOut.Split('\n', StringSplitOptions.RemoveEmptyEntries); + foreach (var line in lines) + { + var tag = ParseLine(line); + if (tag != null) + tags.Add(tag); + } + + return tags; } - protected override void OnReadline(string line) + private Models.Tag ParseLine(string line) { var subs = line.Split('$', StringSplitOptions.RemoveEmptyEntries); if (subs.Length == 2) { - _loaded.Add(new Models.Tag() + return new Models.Tag() { Name = subs[0].Substring(10), SHA = subs[1], - }); + }; } else if (subs.Length == 3) { - _loaded.Add(new Models.Tag() + return new Models.Tag() { Name = subs[0].Substring(10), SHA = subs[2], - }); + }; } - } - private readonly List _loaded = new List(); + return null; + } } }