mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 12:15:00 +00:00
optimize<User>: reduce memory used by commit's author/committer data
This commit is contained in:
parent
d9afb798db
commit
766f24f4b0
14 changed files with 91 additions and 41 deletions
|
@ -8,6 +8,8 @@ namespace SourceGit.Commands {
|
|||
/// </summary>
|
||||
public class Blame : Command {
|
||||
private static readonly Regex REG_FORMAT = new Regex(@"^\^?([0-9a-f]+)\s+.*\((.*)\s+(\d+)\s+[\-\+]?\d+\s+\d+\) (.*)");
|
||||
private static readonly DateTime UTC_START = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime();
|
||||
|
||||
private Data data = new Data();
|
||||
private bool needUnifyCommitSHA = false;
|
||||
private int minSHALen = 0;
|
||||
|
@ -53,7 +55,7 @@ namespace SourceGit.Commands {
|
|||
var author = match.Groups[2].Value;
|
||||
var timestamp = int.Parse(match.Groups[3].Value);
|
||||
var content = match.Groups[4].Value;
|
||||
var when = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(timestamp).ToLocalTime().ToString("yyyy/MM/dd");
|
||||
var when = UTC_START.AddSeconds(timestamp).ToString("yyyy/MM/dd");
|
||||
|
||||
var blameLine = new Models.BlameLine() {
|
||||
LineNumber = $"{data.Lines.Count + 1}",
|
||||
|
|
|
@ -61,9 +61,9 @@ namespace SourceGit.Commands {
|
|||
}
|
||||
|
||||
private string ParseTrackStatus(string data) {
|
||||
if (string.IsNullOrEmpty(data)) return "";
|
||||
if (string.IsNullOrEmpty(data)) return string.Empty;
|
||||
|
||||
string track = "";
|
||||
string track = string.Empty;
|
||||
|
||||
var ahead = REG_AHEAD.Match(data);
|
||||
if (ahead.Success) {
|
||||
|
|
|
@ -145,7 +145,7 @@ namespace SourceGit.Commands {
|
|||
proc.Start();
|
||||
} catch (Exception e) {
|
||||
return new ReadToEndResult() {
|
||||
Output = "",
|
||||
Output = string.Empty,
|
||||
Error = e.Message,
|
||||
IsSuccess = false,
|
||||
};
|
||||
|
|
|
@ -75,9 +75,17 @@ namespace SourceGit.Commands {
|
|||
} else if (line.StartsWith("parent ", StringComparison.Ordinal)) {
|
||||
current.Parents.Add(line.Substring("parent ".Length));
|
||||
} else if (line.StartsWith("author ", StringComparison.Ordinal)) {
|
||||
current.Author.Parse(line);
|
||||
Models.User user = Models.User.Invalid;
|
||||
ulong time = 0;
|
||||
Models.Commit.ParseUserAndTime(line, ref user, ref time);
|
||||
current.Author = user;
|
||||
current.AuthorTime = time;
|
||||
} else if (line.StartsWith("committer ", StringComparison.Ordinal)) {
|
||||
current.Committer.Parse(line);
|
||||
Models.User user = Models.User.Invalid;
|
||||
ulong time = 0;
|
||||
Models.Commit.ParseUserAndTime(line, ref user, ref time);
|
||||
current.Committer = user;
|
||||
current.CommitterTime = time;
|
||||
} else if (string.IsNullOrEmpty(current.Subject)) {
|
||||
current.Subject = line.Trim();
|
||||
} else {
|
||||
|
@ -129,7 +137,7 @@ namespace SourceGit.Commands {
|
|||
}
|
||||
|
||||
private void MarkFirstMerged() {
|
||||
Args = $"log --since=\"{commits.Last().Committer.Time}\" --format=\"%H\"";
|
||||
Args = $"log --since=\"{commits.Last().CommitterTimeStr}\" --format=\"%H\"";
|
||||
|
||||
var rs = ReadToEnd();
|
||||
var shas = rs.Output.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
|
|
@ -37,7 +37,11 @@ namespace SourceGit.Commands {
|
|||
} else if (line.StartsWith("Reflog message: ", StringComparison.Ordinal)) {
|
||||
current.Message = line.Substring(16);
|
||||
} else if (line.StartsWith("author ", StringComparison.Ordinal)) {
|
||||
current.Author.Parse(line);
|
||||
Models.User user = Models.User.Invalid;
|
||||
ulong time = 0;
|
||||
Models.Commit.ParseUserAndTime(line, ref user, ref time);
|
||||
current.Author = user;
|
||||
current.Time = time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue