using System; using System.Collections.Generic; using System.Text.RegularExpressions; namespace SourceGit.Commands { /// /// 解析当前仓库中的贮藏 /// public class Stashes : Command { private static readonly Regex REG_STASH = new Regex(@"^Reflog: refs/(stash@\{\d+\}).*$"); private List parsed = new List(); private Models.Stash current = null; public Stashes(string path) { Cwd = path; Args = "stash list --pretty=raw"; } public List Result() { Exec(); if (current != null) parsed.Add(current); return parsed; } public override void OnReadline(string line) { if (line.StartsWith("commit ", StringComparison.Ordinal)) { if (current != null && !string.IsNullOrEmpty(current.Name)) parsed.Add(current); current = new Models.Stash() { SHA = line.Substring(7, 8) }; return; } if (current == null) return; if (line.StartsWith("Reflog: refs/stash@", StringComparison.Ordinal)) { var match = REG_STASH.Match(line); if (match.Success) current.Name = match.Groups[1].Value; } else if (line.StartsWith("Reflog message: ", StringComparison.Ordinal)) { current.Message = line.Substring(16); } else if (line.StartsWith("author ", StringComparison.Ordinal)) { current.Author.Parse(line); } } } }