mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
refactor: combine Commands.UpdateSubmoduleStatus
into Commands.QuerySubmodules
This commit is contained in:
parent
3969111393
commit
71d2b295da
2 changed files with 49 additions and 59 deletions
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SourceGit.Commands
|
namespace SourceGit.Commands
|
||||||
|
@ -9,6 +10,8 @@ namespace SourceGit.Commands
|
||||||
private static partial Regex REG_FORMAT1();
|
private static partial Regex REG_FORMAT1();
|
||||||
[GeneratedRegex(@"^[\-\+ ][0-9a-f]+\s(.*)$")]
|
[GeneratedRegex(@"^[\-\+ ][0-9a-f]+\s(.*)$")]
|
||||||
private static partial Regex REG_FORMAT2();
|
private static partial Regex REG_FORMAT2();
|
||||||
|
[GeneratedRegex(@"^\s?[\w\?]{1,4}\s+(.+)$")]
|
||||||
|
private static partial Regex REG_FORMAT_STATUS();
|
||||||
|
|
||||||
public QuerySubmodules(string repo)
|
public QuerySubmodules(string repo)
|
||||||
{
|
{
|
||||||
|
@ -19,27 +22,57 @@ namespace SourceGit.Commands
|
||||||
|
|
||||||
public List<Models.Submodule> Result()
|
public List<Models.Submodule> Result()
|
||||||
{
|
{
|
||||||
Exec();
|
var submodules = new List<Models.Submodule>();
|
||||||
new UpdateSubmoduleStatus(WorkingDirectory, _submodules).Result();
|
var rs = ReadToEnd();
|
||||||
return _submodules;
|
if (!rs.IsSuccess)
|
||||||
}
|
return submodules;
|
||||||
|
|
||||||
protected override void OnReadline(string line)
|
var builder = new StringBuilder();
|
||||||
{
|
var lines = rs.StdOut.Split('\n', System.StringSplitOptions.RemoveEmptyEntries);
|
||||||
var match = REG_FORMAT1().Match(line);
|
foreach (var line in lines)
|
||||||
if (match.Success)
|
|
||||||
{
|
{
|
||||||
_submodules.Add(new Models.Submodule() { Path = match.Groups[1].Value });
|
var match = REG_FORMAT1().Match(line);
|
||||||
return;
|
if (match.Success)
|
||||||
|
{
|
||||||
|
var path = match.Groups[1].Value;
|
||||||
|
builder.Append($"\"{path}\" ");
|
||||||
|
submodules.Add(new Models.Submodule() { Path = path });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
match = REG_FORMAT2().Match(line);
|
||||||
|
if (match.Success)
|
||||||
|
{
|
||||||
|
var path = match.Groups[1].Value;
|
||||||
|
builder.Append($"\"{path}\" ");
|
||||||
|
submodules.Add(new Models.Submodule() { Path = path });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match = REG_FORMAT2().Match(line);
|
if (submodules.Count > 0)
|
||||||
if (match.Success)
|
|
||||||
{
|
{
|
||||||
_submodules.Add(new Models.Submodule() { Path = match.Groups[1].Value });
|
Args = $"status -uno --porcelain -- {builder}";
|
||||||
}
|
rs = ReadToEnd();
|
||||||
}
|
if (!rs.IsSuccess)
|
||||||
|
return submodules;
|
||||||
|
|
||||||
private readonly List<Models.Submodule> _submodules = new List<Models.Submodule>();
|
var dirty = new HashSet<string>();
|
||||||
|
lines = rs.StdOut.Split('\n', System.StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
foreach (var line in lines)
|
||||||
|
{
|
||||||
|
var match = REG_FORMAT_STATUS().Match(line);
|
||||||
|
if (match.Success)
|
||||||
|
{
|
||||||
|
var path = match.Groups[1].Value;
|
||||||
|
dirty.Add(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var submodule in submodules)
|
||||||
|
submodule.IsDirty = dirty.Contains(submodule.Path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return submodules;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace SourceGit.Commands
|
|
||||||
{
|
|
||||||
public partial class UpdateSubmoduleStatus : Command
|
|
||||||
{
|
|
||||||
[GeneratedRegex(@"^\s?[\w\?]{1,4}\s+(.+)$")]
|
|
||||||
private static partial Regex REG_FORMAT();
|
|
||||||
|
|
||||||
public UpdateSubmoduleStatus(string repo, List<Models.Submodule> submodules)
|
|
||||||
{
|
|
||||||
var pathes = new StringBuilder();
|
|
||||||
foreach (var submodule in submodules)
|
|
||||||
pathes.Append($"\"{submodule.Path}\" ");
|
|
||||||
|
|
||||||
_submodules = submodules;
|
|
||||||
|
|
||||||
WorkingDirectory = repo;
|
|
||||||
Context = repo;
|
|
||||||
Args = $"status -uno --porcelain -- {pathes}";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Result()
|
|
||||||
{
|
|
||||||
Exec();
|
|
||||||
|
|
||||||
foreach (var submodule in _submodules)
|
|
||||||
submodule.IsDirty = _changed.Contains(submodule.Path);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnReadline(string line)
|
|
||||||
{
|
|
||||||
var match = REG_FORMAT().Match(line);
|
|
||||||
if (match.Success)
|
|
||||||
_changed.Add(match.Groups[1].Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Models.Submodule> _submodules = null;
|
|
||||||
private HashSet<string> _changed = new HashSet<string>();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue