mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-23 21:24:59 +00:00
optimize<*>: reduce repository loading time
This commit is contained in:
parent
738daddbc7
commit
918eb48663
8 changed files with 38 additions and 43 deletions
|
@ -9,8 +9,7 @@ namespace SourceGit.Commands {
|
|||
public class Branches : Command {
|
||||
private static readonly string PREFIX_LOCAL = "refs/heads/";
|
||||
private static readonly string PREFIX_REMOTE = "refs/remotes/";
|
||||
private static readonly string CMD = "branch -l --all -v --format=\"$%(refname)$%(objectname)$%(HEAD)$%(upstream)$%(upstream:track)$%(contents:subject)\"";
|
||||
private static readonly Regex REG_FORMAT = new Regex(@"\$(.*)\$(.*)\$([\* ])\$(.*)\$(.*?)\$(.*)");
|
||||
private static readonly string CMD = "branch -l --all -v --format=\"%(refname)$%(objectname)$%(HEAD)$%(upstream)$%(upstream:track)\"";
|
||||
private static readonly Regex REG_AHEAD = new Regex(@"ahead (\d+)");
|
||||
private static readonly Regex REG_BEHIND = new Regex(@"behind (\d+)");
|
||||
|
||||
|
@ -27,11 +26,11 @@ namespace SourceGit.Commands {
|
|||
}
|
||||
|
||||
public override void OnReadline(string line) {
|
||||
var match = REG_FORMAT.Match(line);
|
||||
if (!match.Success) return;
|
||||
var parts = line.Split('$');
|
||||
if (parts.Length != 5) return;
|
||||
|
||||
var branch = new Models.Branch();
|
||||
var refName = match.Groups[1].Value;
|
||||
var refName = parts[0];
|
||||
if (refName.EndsWith("/HEAD")) return;
|
||||
|
||||
if (refName.StartsWith(PREFIX_LOCAL, StringComparison.Ordinal)) {
|
||||
|
@ -51,11 +50,10 @@ namespace SourceGit.Commands {
|
|||
}
|
||||
|
||||
branch.FullName = refName;
|
||||
branch.Head = match.Groups[2].Value;
|
||||
branch.IsCurrent = match.Groups[3].Value == "*";
|
||||
branch.Upstream = match.Groups[4].Value;
|
||||
branch.UpstreamTrackStatus = ParseTrackStatus(match.Groups[5].Value);
|
||||
branch.HeadSubject = match.Groups[6].Value;
|
||||
branch.Head = parts[1];
|
||||
branch.IsCurrent = parts[2] == "*";
|
||||
branch.Upstream = parts[3];
|
||||
branch.UpstreamTrackStatus = ParseTrackStatus(parts[4]);
|
||||
|
||||
loaded.Add(branch);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace SourceGit.Commands {
|
|||
/// 命令接口
|
||||
/// </summary>
|
||||
public class Command {
|
||||
private static readonly Regex PROGRESS_REG = new Regex(@"\d+%");
|
||||
|
||||
/// <summary>
|
||||
/// 读取全部输出时的结果
|
||||
|
@ -68,7 +69,6 @@ namespace SourceGit.Commands {
|
|||
|
||||
if (!string.IsNullOrEmpty(Cwd)) start.WorkingDirectory = Cwd;
|
||||
|
||||
var progressFilter = new Regex(@"\s\d+%\s");
|
||||
var errs = new List<string>();
|
||||
var proc = new Process() { StartInfo = start };
|
||||
var isCancelled = false;
|
||||
|
@ -97,8 +97,12 @@ namespace SourceGit.Commands {
|
|||
if (string.IsNullOrEmpty(e.Data)) return;
|
||||
if (TraitErrorAsOutput) OnReadline(e.Data);
|
||||
|
||||
if (progressFilter.IsMatch(e.Data)) return;
|
||||
// 错误信息中忽略进度相关的输出
|
||||
if (e.Data.StartsWith("remote: Enumerating objects:", StringComparison.Ordinal)) return;
|
||||
if (e.Data.StartsWith("remote: Counting objects:", StringComparison.Ordinal)) return;
|
||||
if (e.Data.StartsWith("remote: Compressing objects:", StringComparison.Ordinal)) return;
|
||||
if (e.Data.StartsWith("Filtering content:", StringComparison.Ordinal)) return;
|
||||
if (PROGRESS_REG.IsMatch(e.Data)) return;
|
||||
errs.Add(e.Data);
|
||||
};
|
||||
|
||||
|
|
|
@ -77,13 +77,13 @@ namespace SourceGit.Commands {
|
|||
} else if (line.StartsWith("author ", StringComparison.Ordinal)) {
|
||||
Models.User user = Models.User.Invalid;
|
||||
ulong time = 0;
|
||||
Models.Commit.ParseUserAndTime(line, ref user, ref time);
|
||||
Models.Commit.ParseUserAndTime(line.Substring(7), ref user, ref time);
|
||||
current.Author = user;
|
||||
current.AuthorTime = time;
|
||||
} else if (line.StartsWith("committer ", StringComparison.Ordinal)) {
|
||||
Models.User user = Models.User.Invalid;
|
||||
ulong time = 0;
|
||||
Models.Commit.ParseUserAndTime(line, ref user, ref time);
|
||||
Models.Commit.ParseUserAndTime(line.Substring(10), ref user, ref time);
|
||||
current.Committer = user;
|
||||
current.CommitterTime = time;
|
||||
} else if (string.IsNullOrEmpty(current.Subject)) {
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace SourceGit.Commands {
|
|||
} else if (line.StartsWith("author ", StringComparison.Ordinal)) {
|
||||
Models.User user = Models.User.Invalid;
|
||||
ulong time = 0;
|
||||
Models.Commit.ParseUserAndTime(line, ref user, ref time);
|
||||
Models.Commit.ParseUserAndTime(line.Substring(7), ref user, ref time);
|
||||
current.Author = user;
|
||||
current.Time = time;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SourceGit.Commands {
|
||||
/// <summary>
|
||||
|
@ -7,8 +7,6 @@ namespace SourceGit.Commands {
|
|||
/// </summary>
|
||||
public class Tags : Command {
|
||||
public static readonly string CMD = "for-each-ref --sort=-creatordate --format=\"$%(refname:short)$%(objectname)$%(*objectname)\" refs/tags";
|
||||
public static readonly Regex REG_FORMAT = new Regex(@"\$(.*)\$(.*)\$(.*)");
|
||||
|
||||
private List<Models.Tag> loaded = new List<Models.Tag>();
|
||||
|
||||
public Tags(string path) {
|
||||
|
@ -22,22 +20,16 @@ namespace SourceGit.Commands {
|
|||
}
|
||||
|
||||
public override void OnReadline(string line) {
|
||||
var match = REG_FORMAT.Match(line);
|
||||
if (!match.Success) return;
|
||||
|
||||
var name = match.Groups[1].Value;
|
||||
var commit = match.Groups[2].Value;
|
||||
var dereference = match.Groups[3].Value;
|
||||
|
||||
if (string.IsNullOrEmpty(dereference)) {
|
||||
var subs = line.Split(new char[] { '$' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (subs.Length == 2) {
|
||||
loaded.Add(new Models.Tag() {
|
||||
Name = name,
|
||||
SHA = commit,
|
||||
Name = subs[0],
|
||||
SHA = subs[1],
|
||||
});
|
||||
} else {
|
||||
} else if (subs.Length == 3) {
|
||||
loaded.Add(new Models.Tag() {
|
||||
Name = name,
|
||||
SHA = dereference,
|
||||
Name = subs[0],
|
||||
SHA = subs[2],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue