-
Notifications
You must be signed in to change notification settings - Fork 385
Expand file tree
/
Copy pathCommit.cs
More file actions
128 lines (114 loc) · 4.35 KB
/
Commit.cs
File metadata and controls
128 lines (114 loc) · 4.35 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
127
128
using System;
using System.Collections.Generic;
namespace SourceGit.Models
{
public enum CommitSearchMethod
{
BySHA = 0,
ByAuthor,
ByCommitter,
ByMessage,
ByPath,
ByContent,
}
public class Commit
{
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;
public string Subject { get; set; } = string.Empty;
public List<string> Parents { get; set; } = new();
public List<Decorator> Decorators { get; set; } = new();
public bool IsMerged { get; set; } = false;
public int Color { get; set; } = 0;
public double LeftMargin { get; set; } = 0;
public bool IsCommitterVisible => !Author.Equals(Committer) || AuthorTime != CommitterTime;
public bool IsCurrentHead => Decorators.Find(x => x.Type is DecoratorType.CurrentBranchHead or DecoratorType.CurrentCommitHead) != null;
public bool HasDecorators => Decorators.Count > 0;
public string FirstParentToCompare => Parents.Count > 0 ? $"{SHA}^" : EmptyTreeHash.Guess(SHA);
public string GetFriendlyName()
{
var branchDecorator = Decorators.Find(x => x.Type is DecoratorType.LocalBranchHead or DecoratorType.RemoteBranchHead);
if (branchDecorator != null)
return branchDecorator.Name;
var tagDecorator = Decorators.Find(x => x.Type is DecoratorType.Tag);
if (tagDecorator != null)
return tagDecorator.Name;
return SHA[..10];
}
public void ParseParents(string data)
{
if (data.Length < 8)
return;
Parents.AddRange(data.Split(' ', StringSplitOptions.RemoveEmptyEntries));
}
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();
}
}