mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 04:04:59 +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
|
@ -1,4 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
|
||||
namespace SourceGit.Models {
|
||||
|
@ -6,16 +8,32 @@ namespace SourceGit.Models {
|
|||
/// 提交记录
|
||||
/// </summary>
|
||||
public class Commit {
|
||||
public string SHA { get; set; } = "";
|
||||
private static readonly Regex REG_USER_FORMAT = new Regex(@"\w+ (.*) <(.*)> (\d{10}) [\+\-]\d+");
|
||||
private static readonly DateTime UTC_START = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime();
|
||||
|
||||
public string SHA { get; set; } = string.Empty;
|
||||
public string ShortSHA => SHA.Substring(0, 8);
|
||||
public User Author { get; set; } = new User();
|
||||
public User Committer { get; set; } = new User();
|
||||
public string Subject { get; set; } = "";
|
||||
public string Message { get; set; } = "";
|
||||
public User Author { get; set; } = User.Invalid;
|
||||
public ulong AuthorTime { get; set; } = 0;
|
||||
public User Committer { get; set; } = User.Invalid;
|
||||
public ulong CommitterTime { get; set; } = 0;
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
public string Message { get; set; } = string.Empty;
|
||||
public List<string> Parents { get; set; } = new List<string>();
|
||||
public List<Decorator> Decorators { get; set; } = new List<Decorator>();
|
||||
public bool HasDecorators => Decorators.Count > 0;
|
||||
public bool IsMerged { get; set; } = false;
|
||||
public Thickness Margin { get; set; } = new Thickness(0);
|
||||
|
||||
public string AuthorTimeStr => UTC_START.AddSeconds(AuthorTime).ToString("yyyy-MM-dd HH:mm:ss");
|
||||
public string CommitterTimeStr => UTC_START.AddSeconds(CommitterTime).ToString("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
public static void ParseUserAndTime(string data, ref User user, ref ulong time) {
|
||||
var match = REG_USER_FORMAT.Match(data);
|
||||
if (!match.Success) return;
|
||||
|
||||
user = User.FindOrAdd(match.Groups[1].Value, match.Groups[2].Value);
|
||||
time = ulong.Parse(match.Groups[3].Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue