@@ -11,22 +11,54 @@ public struct GitLogEntry
11
11
private const string Today = "Today" ;
12
12
private const string Yesterday = "Yesterday" ;
13
13
14
- public string CommitID ;
15
- public string MergeA ;
16
- public string MergeB ;
17
- public string AuthorName ;
18
- public string AuthorEmail ;
19
- public string CommitEmail ;
20
- public string CommitName ;
21
- public string Summary ;
22
- public string Description ;
23
- public string TimeString ;
24
- public string CommitTimeString ;
25
- public List < GitStatusEntry > Changes ;
26
-
27
- public string ShortID
14
+ public static GitLogEntry Default = new GitLogEntry ( String . Empty , String . Empty , String . Empty , String . Empty , String . Empty , String . Empty , String . Empty , DateTimeOffset . MinValue , DateTimeOffset . MinValue , new List < GitStatusEntry > ( ) , String . Empty , String . Empty ) ;
15
+
16
+ public string commitID ;
17
+ public string mergeA ;
18
+ public string mergeB ;
19
+ public string authorName ;
20
+ public string authorEmail ;
21
+ public string commitEmail ;
22
+ public string commitName ;
23
+ public string summary ;
24
+ public string description ;
25
+ public string timeString ;
26
+ public string commitTimeString ;
27
+ public List < GitStatusEntry > changes ;
28
+
29
+ public GitLogEntry ( string commitID ,
30
+ string authorName , string authorEmail ,
31
+ string commitName , string commitEmail ,
32
+ string summary ,
33
+ string description ,
34
+ DateTimeOffset time , DateTimeOffset commitTime ,
35
+ List < GitStatusEntry > changes ,
36
+ string mergeA = null , string mergeB = null ) : this ( )
28
37
{
29
- get { return CommitID . Length < 7 ? CommitID : CommitID . Substring ( 0 , 7 ) ; }
38
+ Guard . ArgumentNotNull ( commitID , "commitID" ) ;
39
+ Guard . ArgumentNotNull ( authorName , "authorName" ) ;
40
+ Guard . ArgumentNotNull ( authorEmail , "authorEmail" ) ;
41
+ Guard . ArgumentNotNull ( commitEmail , "commitEmail" ) ;
42
+ Guard . ArgumentNotNull ( commitName , "commitName" ) ;
43
+ Guard . ArgumentNotNull ( summary , "summary" ) ;
44
+ Guard . ArgumentNotNull ( description , "description" ) ;
45
+ Guard . ArgumentNotNull ( changes , "changes" ) ;
46
+
47
+ this . commitID = commitID ;
48
+ this . authorName = authorName ;
49
+ this . authorEmail = authorEmail ;
50
+ this . commitEmail = commitEmail ;
51
+ this . commitName = commitName ;
52
+ this . summary = summary ;
53
+ this . description = description ;
54
+
55
+ Time = time ;
56
+ CommitTime = commitTime ;
57
+
58
+ this . changes = changes ;
59
+
60
+ this . mergeA = mergeA ?? string . Empty ;
61
+ this . mergeB = mergeB ?? string . Empty ;
30
62
}
31
63
32
64
public string PrettyTimeString
@@ -49,37 +81,78 @@ public DateTimeOffset Time
49
81
{
50
82
if ( ! timeValue . HasValue )
51
83
{
52
- timeValue = DateTimeOffset . Parse ( TimeString ) ;
84
+ DateTimeOffset result ;
85
+ if ( DateTimeOffset . TryParseExact ( TimeString , Constants . Iso8601Format , CultureInfo . InvariantCulture , DateTimeStyles . None , out result ) )
86
+ {
87
+ timeValue = result ;
88
+ }
89
+ else
90
+ {
91
+ Time = DateTimeOffset . MinValue ;
92
+ }
53
93
}
54
-
94
+
55
95
return timeValue . Value ;
56
96
}
97
+ private set
98
+ {
99
+ timeString = value . ToString ( Constants . Iso8601Format ) ;
100
+ timeValue = value ;
101
+ }
57
102
}
58
103
59
104
[ NonSerialized ] private DateTimeOffset ? commitTimeValue ;
60
- public DateTimeOffset ? CommitTime
105
+ public DateTimeOffset CommitTime
61
106
{
62
107
get
63
108
{
64
- if ( ! timeValue . HasValue && ! string . IsNullOrEmpty ( CommitTimeString ) )
109
+ if ( ! commitTimeValue . HasValue )
65
110
{
66
- commitTimeValue = DateTimeOffset . Parse ( CommitTimeString ) ;
111
+ DateTimeOffset result ;
112
+ if ( DateTimeOffset . TryParseExact ( CommitTimeString , Constants . Iso8601Format , CultureInfo . InvariantCulture , DateTimeStyles . None , out result ) )
113
+ {
114
+ commitTimeValue = result ;
115
+ }
116
+ else
117
+ {
118
+ CommitTime = DateTimeOffset . MinValue ;
119
+ }
67
120
}
68
121
69
- return commitTimeValue ;
122
+ return commitTimeValue . Value ;
123
+ }
124
+ private set
125
+ {
126
+ commitTimeString = value . ToString ( Constants . Iso8601Format ) ;
127
+ commitTimeValue = value ;
70
128
}
71
129
}
72
130
73
- public void Clear ( )
74
- {
75
- CommitID = MergeA = MergeB = AuthorName = AuthorEmail = Summary = Description = "" ;
131
+ public string ShortID => CommitID . Length < 7 ? CommitID : CommitID . Substring ( 0 , 7 ) ;
76
132
77
- timeValue = DateTimeOffset . MinValue ;
78
- TimeString = timeValue . Value . ToString ( DateTimeFormatInfo . CurrentInfo ) ;
133
+ public string CommitID => commitID ;
79
134
80
- commitTimeValue = null ;
81
- CommitTimeString = null ;
82
- }
135
+ public string MergeA => mergeA ;
136
+
137
+ public string MergeB => mergeB ;
138
+
139
+ public string AuthorName => authorName ;
140
+
141
+ public string AuthorEmail => authorEmail ;
142
+
143
+ public string CommitEmail => commitEmail ;
144
+
145
+ public string CommitName => commitName ;
146
+
147
+ public string Summary => summary ;
148
+
149
+ public string Description => description ;
150
+
151
+ public string TimeString => timeString ;
152
+
153
+ public string CommitTimeString => commitTimeString ;
154
+
155
+ public List < GitStatusEntry > Changes => changes ;
83
156
84
157
public override string ToString ( )
85
158
{
0 commit comments