2024-03-17 18:37:06 -07:00
|
|
|
|
using System;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
using Avalonia;
|
2024-07-17 19:46:39 -07:00
|
|
|
|
using Avalonia.Media;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
|
|
|
|
|
namespace SourceGit.Models
|
|
|
|
|
{
|
2024-07-23 02:41:33 -07:00
|
|
|
|
public class Commit: IObjectId
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-07-17 19:46:39 -07:00
|
|
|
|
public static double OpacityForNotMerged
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
2024-07-18 18:29:16 -07:00
|
|
|
|
} = 0.65;
|
2024-07-17 19:46:39 -07:00
|
|
|
|
|
2023-10-09 20:25:57 -07:00
|
|
|
|
public string SHA { get; set; } = string.Empty;
|
|
|
|
|
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;
|
2024-06-07 21:19:48 -07:00
|
|
|
|
public string Subject { get; set; } = string.Empty;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
public List<string> Parents { get; set; } = new List<string>();
|
|
|
|
|
public List<Decorator> Decorators { get; set; } = new List<Decorator>();
|
|
|
|
|
public bool HasDecorators => Decorators.Count > 0;
|
2024-07-18 18:29:16 -07:00
|
|
|
|
|
2021-04-29 05:05:55 -07:00
|
|
|
|
public bool IsMerged { get; set; } = false;
|
2024-07-18 18:29:16 -07:00
|
|
|
|
public bool CanPushToUpstream { get; set; } = false;
|
|
|
|
|
public bool CanPullFromUpstream { get; set; } = false;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
public Thickness Margin { get; set; } = new Thickness(0);
|
2023-10-09 20:25:57 -07:00
|
|
|
|
|
2024-07-01 21:30:12 -07:00
|
|
|
|
public string AuthorTimeStr => DateTime.UnixEpoch.AddSeconds(AuthorTime).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss");
|
|
|
|
|
public string CommitterTimeStr => DateTime.UnixEpoch.AddSeconds(CommitterTime).ToLocalTime().ToString("yyyy/MM/dd HH:mm:ss");
|
|
|
|
|
public string AuthorTimeShortStr => DateTime.UnixEpoch.AddSeconds(AuthorTime).ToLocalTime().ToString("yyyy/MM/dd");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-07-14 09:30:31 -07:00
|
|
|
|
public bool IsCommitterVisible => !Author.Equals(Committer) || AuthorTime != CommitterTime;
|
2024-06-06 05:59:09 -07:00
|
|
|
|
public bool IsCurrentHead => Decorators.Find(x => x.Type is DecoratorType.CurrentBranchHead or DecoratorType.CurrentCommitHead) != null;
|
2024-07-17 19:46:39 -07:00
|
|
|
|
|
|
|
|
|
public double Opacity => IsMerged ? 1 : OpacityForNotMerged;
|
|
|
|
|
public FontWeight FontWeight => IsCurrentHead ? FontWeight.Bold : FontWeight.Regular;
|
2024-07-18 18:29:16 -07:00
|
|
|
|
|
|
|
|
|
public void ParseDecorators(string data)
|
|
|
|
|
{
|
|
|
|
|
if (data.Length < 3)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var subs = data.Split(',', StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
foreach (var sub in subs)
|
|
|
|
|
{
|
|
|
|
|
var d = sub.Trim();
|
|
|
|
|
if (d.EndsWith("/HEAD", StringComparison.Ordinal))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (d.StartsWith("tag: refs/tags/", StringComparison.Ordinal))
|
|
|
|
|
{
|
|
|
|
|
Decorators.Add(new Decorator()
|
|
|
|
|
{
|
|
|
|
|
Type = DecoratorType.Tag,
|
|
|
|
|
Name = d.Substring(15),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (d.StartsWith("HEAD -> refs/heads/", StringComparison.Ordinal))
|
|
|
|
|
{
|
|
|
|
|
IsMerged = true;
|
|
|
|
|
Decorators.Add(new Decorator()
|
|
|
|
|
{
|
|
|
|
|
Type = DecoratorType.CurrentBranchHead,
|
|
|
|
|
Name = d.Substring(19),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (d.Equals("HEAD"))
|
|
|
|
|
{
|
|
|
|
|
IsMerged = true;
|
|
|
|
|
Decorators.Add(new Decorator()
|
|
|
|
|
{
|
|
|
|
|
Type = DecoratorType.CurrentCommitHead,
|
|
|
|
|
Name = d,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (d.StartsWith("refs/heads/", StringComparison.Ordinal))
|
|
|
|
|
{
|
|
|
|
|
Decorators.Add(new Decorator()
|
|
|
|
|
{
|
|
|
|
|
Type = DecoratorType.LocalBranchHead,
|
|
|
|
|
Name = d.Substring(11),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (d.StartsWith("refs/remotes/", StringComparison.Ordinal))
|
|
|
|
|
{
|
|
|
|
|
Decorators.Add(new Decorator()
|
|
|
|
|
{
|
|
|
|
|
Type = DecoratorType.RemoteBranchHead,
|
|
|
|
|
Name = d.Substring(13),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Decorators.Sort((l, r) =>
|
|
|
|
|
{
|
|
|
|
|
if (l.Type != r.Type)
|
|
|
|
|
return (int)l.Type - (int)r.Type;
|
|
|
|
|
else
|
|
|
|
|
return string.Compare(l.Name, r.Name, StringComparison.Ordinal);
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|