mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-06 11:34:59 +00:00
perf: only update uninited or outdated submodules
Some checks are pending
Some checks are pending
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
1872740265
commit
1fef7a7baa
8 changed files with 55 additions and 36 deletions
40
src/Commands/QueryUpdatableSubmodules.cs
Normal file
40
src/Commands/QueryUpdatableSubmodules.cs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace SourceGit.Commands
|
||||||
|
{
|
||||||
|
public partial class QueryUpdatableSubmodules : Command
|
||||||
|
{
|
||||||
|
[GeneratedRegex(@"^([U\-\+ ])([0-9a-f]+)\s(.*?)(\s\(.*\))?$")]
|
||||||
|
private static partial Regex REG_FORMAT_STATUS();
|
||||||
|
|
||||||
|
public QueryUpdatableSubmodules(string repo)
|
||||||
|
{
|
||||||
|
WorkingDirectory = repo;
|
||||||
|
Context = repo;
|
||||||
|
Args = "submodule status";
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<string> Result()
|
||||||
|
{
|
||||||
|
var submodules = new List<string>();
|
||||||
|
var rs = ReadToEnd();
|
||||||
|
|
||||||
|
var lines = rs.StdOut.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
foreach (var line in lines)
|
||||||
|
{
|
||||||
|
var match = REG_FORMAT_STATUS().Match(line);
|
||||||
|
if (match.Success)
|
||||||
|
{
|
||||||
|
var stat = match.Groups[1].Value;
|
||||||
|
var path = match.Groups[3].Value;
|
||||||
|
if (!stat.StartsWith(' '))
|
||||||
|
submodules.Add(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return submodules;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,23 +29,7 @@ namespace SourceGit.Commands
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Update(string module, bool init, bool recursive, bool useRemote)
|
public bool Update(List<string> modules, bool init, bool recursive, bool useRemote = false)
|
||||||
{
|
|
||||||
Args = "submodule update";
|
|
||||||
|
|
||||||
if (init)
|
|
||||||
Args += " --init";
|
|
||||||
if (recursive)
|
|
||||||
Args += " --recursive";
|
|
||||||
if (useRemote)
|
|
||||||
Args += " --remote";
|
|
||||||
if (!string.IsNullOrEmpty(module))
|
|
||||||
Args += $" -- \"{module}\"";
|
|
||||||
|
|
||||||
return Exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Update(List<Models.Submodule> modules, bool init, bool recursive, bool useRemote)
|
|
||||||
{
|
{
|
||||||
var builder = new StringBuilder();
|
var builder = new StringBuilder();
|
||||||
builder.Append("submodule update");
|
builder.Append("submodule update");
|
||||||
|
@ -60,7 +44,7 @@ namespace SourceGit.Commands
|
||||||
{
|
{
|
||||||
builder.Append(" --");
|
builder.Append(" --");
|
||||||
foreach (var module in modules)
|
foreach (var module in modules)
|
||||||
builder.Append($" \"{module.Path}\"");
|
builder.Append($" \"{module}\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
Args = builder.ToString();
|
Args = builder.ToString();
|
||||||
|
|
|
@ -74,9 +74,9 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
if (updateSubmodules)
|
if (updateSubmodules)
|
||||||
{
|
{
|
||||||
var submodules = new Commands.QuerySubmodules(_repo.FullPath).Result();
|
var submodules = new Commands.QueryUpdatableSubmodules(_repo.FullPath).Result();
|
||||||
if (submodules.Count > 0)
|
if (submodules.Count > 0)
|
||||||
new Commands.Submodule(_repo.FullPath).Use(log).Update(submodules, true, true, false);
|
new Commands.Submodule(_repo.FullPath).Use(log).Update(submodules, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needPopStash)
|
if (needPopStash)
|
||||||
|
|
|
@ -74,9 +74,9 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
if (updateSubmodules)
|
if (updateSubmodules)
|
||||||
{
|
{
|
||||||
var submodules = new Commands.QuerySubmodules(_repo.FullPath).Result();
|
var submodules = new Commands.QueryUpdatableSubmodules(_repo.FullPath).Result();
|
||||||
if (submodules.Count > 0)
|
if (submodules.Count > 0)
|
||||||
new Commands.Submodule(_repo.FullPath).Use(log).Update(submodules, true, true, false);
|
new Commands.Submodule(_repo.FullPath).Use(log).Update(submodules, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needPop)
|
if (needPop)
|
||||||
|
|
|
@ -140,9 +140,9 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
if (InitAndUpdateSubmodules)
|
if (InitAndUpdateSubmodules)
|
||||||
{
|
{
|
||||||
var submodules = new Commands.QuerySubmodules(path).Result();
|
var submodules = new Commands.QueryUpdatableSubmodules(path).Result();
|
||||||
if (submodules.Count > 0)
|
if (submodules.Count > 0)
|
||||||
new Commands.Submodule(path).Use(log).Update(submodules, true, true, false);
|
new Commands.Submodule(path).Use(log).Update(submodules, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Complete();
|
log.Complete();
|
||||||
|
|
|
@ -144,9 +144,9 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
if (updateSubmodules)
|
if (updateSubmodules)
|
||||||
{
|
{
|
||||||
var submodules = new Commands.QuerySubmodules(_repo.FullPath).Result();
|
var submodules = new Commands.QueryUpdatableSubmodules(_repo.FullPath).Result();
|
||||||
if (submodules.Count > 0)
|
if (submodules.Count > 0)
|
||||||
new Commands.Submodule(_repo.FullPath).Use(log).Update(submodules, true, true, false);
|
new Commands.Submodule(_repo.FullPath).Use(log).Update(submodules, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needPopStash)
|
if (needPopStash)
|
||||||
|
|
|
@ -153,9 +153,9 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
if (updateSubmodules)
|
if (updateSubmodules)
|
||||||
{
|
{
|
||||||
var submodules = new Commands.QuerySubmodules(_repo.FullPath).Result();
|
var submodules = new Commands.QueryUpdatableSubmodules(_repo.FullPath).Result();
|
||||||
if (submodules.Count > 0)
|
if (submodules.Count > 0)
|
||||||
new Commands.Submodule(_repo.FullPath).Use(log).Update(submodules, true, true, false);
|
new Commands.Submodule(_repo.FullPath).Use(log).Update(submodules, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needPopStash)
|
if (needPopStash)
|
||||||
|
|
|
@ -65,14 +65,9 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
return Task.Run(() =>
|
return Task.Run(() =>
|
||||||
{
|
{
|
||||||
foreach (var submodule in targets)
|
new Commands.Submodule(_repo.FullPath)
|
||||||
{
|
.Use(log)
|
||||||
new Commands.Submodule(_repo.FullPath).Use(log).Update(
|
.Update(targets, EnableInit, EnableRecursive, EnableRemote);
|
||||||
submodule,
|
|
||||||
EnableInit,
|
|
||||||
EnableRecursive,
|
|
||||||
EnableRemote);
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Complete();
|
log.Complete();
|
||||||
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue