forked from sourcegit-scm/sourcegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommit.cs
More file actions
126 lines (113 loc) · 4.62 KB
/
Commit.cs
File metadata and controls
126 lines (113 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using System.Collections.Generic;
using Avalonia;
using Avalonia.Media;
namespace SourceGit.Models
{
public enum CommitSearchMethod
{
BySHA = 0,
ByAuthor,
ByCommitter,
ByMessage,
ByPath,
ByContent,
}
public class Commit
{
// As retrieved by: git mktree </dev/null
public const string EmptyTreeSHA1 = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
public static double OpacityForNotMerged
{
get;
set;
} = 0.65;
public string SHA { get; set; } = string.Empty;
public User Author { get; set; } = User.Invalid;
public ulong AuthorTime { get; set; }
public User Committer { get; set; } = User.Invalid;
public ulong CommitterTime { get; set; }
public string Subject { get; set; } = string.Empty;
public List<string> Parents { get; set; } = new();
public List<Decorator> Decorators { get; set; } = new();
public bool HasDecorators => Decorators.Count > 0;
public string AuthorTimeStr => DateTime.UnixEpoch.AddSeconds(AuthorTime).ToLocalTime().ToString(DateTimeFormat.Active.DateTime);
public string CommitterTimeStr => DateTime.UnixEpoch.AddSeconds(CommitterTime).ToLocalTime().ToString(DateTimeFormat.Active.DateTime);
public string AuthorTimeShortStr => DateTime.UnixEpoch.AddSeconds(AuthorTime).ToLocalTime().ToString(DateTimeFormat.Active.DateOnly);
public string CommitterTimeShortStr => DateTime.UnixEpoch.AddSeconds(CommitterTime).ToLocalTime().ToString(DateTimeFormat.Active.DateOnly);
public bool IsMerged { get; set; }
public bool IsCommitterVisible => !Author.Equals(Committer) || AuthorTime != CommitterTime;
public bool IsCurrentHead => Decorators.Find(x => x.Type is DecoratorType.CurrentBranchHead or DecoratorType.CurrentCommitHead) != null;
public int Color { get; set; }
public double Opacity => IsMerged ? 1 : OpacityForNotMerged;
public FontWeight FontWeight => IsCurrentHead ? FontWeight.Bold : FontWeight.Regular;
public Thickness Margin { get; set; } = new(0);
public IBrush Brush => CommitGraph.Pens[Color].Brush;
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) =>
{
var delta = (int)l.Type - (int)r.Type;
if (delta != 0)
return delta;
return NumericSort.Compare(l.Name, r.Name);
});
}
}
public class CommitFullMessage
{
public string Message { get; set; } = string.Empty;
public InlineElementCollector Inlines { get; set; } = new();
}
}