2024-02-05 23:08:37 -08:00
|
|
|
|
using System;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.Commands
|
|
|
|
|
{
|
|
|
|
|
public partial class QueryStashes : Command
|
|
|
|
|
{
|
|
|
|
|
|
2024-03-16 02:09:27 -07:00
|
|
|
|
[GeneratedRegex(@"^Reflog: refs/(stash@\{\d+\}).*$")]
|
|
|
|
|
private static partial Regex REG_STASH();
|
2024-03-17 18:37:06 -07:00
|
|
|
|
|
|
|
|
|
public QueryStashes(string repo)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
WorkingDirectory = repo;
|
|
|
|
|
Context = repo;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
Args = "stash list --pretty=raw";
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public List<Models.Stash> Result()
|
|
|
|
|
{
|
2021-04-29 05:05:55 -07:00
|
|
|
|
Exec();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
if (_current != null) _stashes.Add(_current);
|
|
|
|
|
return _stashes;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
protected override void OnReadline(string line)
|
|
|
|
|
{
|
|
|
|
|
if (line.StartsWith("commit ", StringComparison.Ordinal))
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
if (_current != null && !string.IsNullOrEmpty(_current.Name)) _stashes.Add(_current);
|
|
|
|
|
_current = new Models.Stash() { SHA = line.Substring(7, 8) };
|
2021-04-29 05:05:55 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
if (_current == null) return;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (line.StartsWith("Reflog: refs/stash@", StringComparison.Ordinal))
|
|
|
|
|
{
|
2024-03-16 02:09:27 -07:00
|
|
|
|
var match = REG_STASH().Match(line);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
if (match.Success) _current.Name = match.Groups[1].Value;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else if (line.StartsWith("Reflog message: ", StringComparison.Ordinal))
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_current.Message = line.Substring(16);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else if (line.StartsWith("author ", StringComparison.Ordinal))
|
|
|
|
|
{
|
2023-10-09 20:25:57 -07:00
|
|
|
|
Models.User user = Models.User.Invalid;
|
|
|
|
|
ulong time = 0;
|
2023-10-11 21:02:41 -07:00
|
|
|
|
Models.Commit.ParseUserAndTime(line.Substring(7), ref user, ref time);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_current.Author = user;
|
|
|
|
|
_current.Time = time;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private readonly List<Models.Stash> _stashes = new List<Models.Stash>();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
private Models.Stash _current = null;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|