@@ -19,6 +19,7 @@ public static class GitCommitReader
19
19
private static readonly byte [ ] TreeStart = GitRepository . Encoding . GetBytes ( "tree " ) ;
20
20
private static readonly byte [ ] ParentStart = GitRepository . Encoding . GetBytes ( "parent " ) ;
21
21
private static readonly byte [ ] AuthorStart = GitRepository . Encoding . GetBytes ( "author " ) ;
22
+ private static readonly byte [ ] CommitterStart = GitRepository . Encoding . GetBytes ( "committer " ) ;
22
23
23
24
/// <summary>
24
25
/// Reads a <see cref="GitCommit"/> object from a <see cref="Stream"/>.
@@ -30,7 +31,7 @@ public static class GitCommitReader
30
31
/// The <see cref="GitObjectId"/> of the commit.
31
32
/// </param>
32
33
/// <param name="readAuthor">
33
- /// A value indicating whether to populate the <see cref="GitCommit.Author"/> field .
34
+ /// A value indicating whether to populate the <see cref="GitCommit.Author"/> and <see cref="GitCommit.Committer"/> fields .
34
35
/// </param>
35
36
/// <returns>
36
37
/// The <see cref="GitCommit"/>.
@@ -67,7 +68,7 @@ public static GitCommit Read(Stream stream, GitObjectId sha, bool readAuthor = f
67
68
/// The <see cref="GitObjectId"/> of the commit.
68
69
/// </param>
69
70
/// <param name="readAuthor">
70
- /// A value indicating whether to populate the <see cref="GitCommit.Author"/> field .
71
+ /// A value indicating whether to populate the <see cref="GitCommit.Author"/> and <see cref="GitCommit.Committer"/> fields .
71
72
/// </param>
72
73
/// <returns>
73
74
/// The <see cref="GitCommit"/>.
@@ -102,11 +103,22 @@ public static GitCommit Read(ReadOnlySpan<byte> commit, GitObjectId sha, bool re
102
103
buffer = buffer . Slice ( ParentLineLength ) ;
103
104
}
104
105
105
- GitSignature signature = default ;
106
+ GitSignature author = default ;
107
+ GitSignature committer = default ;
106
108
107
- if ( readAuthor && ! TryReadAuthor ( buffer , out signature ) )
109
+ if ( readAuthor )
108
110
{
109
- throw new GitException ( ) ;
111
+ if ( ! TryReadAuthor ( buffer , out author , out int lineLength ) )
112
+ {
113
+ throw new GitException ( ) ;
114
+ }
115
+
116
+ buffer = buffer . Slice ( lineLength ) ;
117
+
118
+ if ( ! TryReadCommitter ( buffer , out committer ) )
119
+ {
120
+ throw new GitException ( ) ;
121
+ }
110
122
}
111
123
112
124
return new GitCommit ( )
@@ -116,7 +128,8 @@ public static GitCommit Read(ReadOnlySpan<byte> commit, GitObjectId sha, bool re
116
128
SecondParent = secondParent ,
117
129
AdditionalParents = additionalParents ,
118
130
Tree = tree ,
119
- Author = readAuthor ? signature : null ,
131
+ Author = readAuthor ? author : null ,
132
+ Committer = readAuthor ? committer : null ,
120
133
} ;
121
134
}
122
135
@@ -153,16 +166,27 @@ private static bool TryReadParent(ReadOnlySpan<byte> line, out GitObjectId paren
153
166
return true ;
154
167
}
155
168
156
- private static bool TryReadAuthor ( ReadOnlySpan < byte > line , out GitSignature signature )
169
+ private static bool TryReadAuthor ( ReadOnlySpan < byte > line , out GitSignature signature , out int lineLength )
170
+ {
171
+ return TryReadSignature ( line , AuthorStart , out signature , out lineLength ) ;
172
+ }
173
+
174
+ private static bool TryReadCommitter ( ReadOnlySpan < byte > line , out GitSignature signature )
175
+ {
176
+ return TryReadSignature ( line , CommitterStart , out signature , out _ ) ;
177
+ }
178
+
179
+ private static bool TryReadSignature ( ReadOnlySpan < byte > line , byte [ ] signatureStart , out GitSignature signature , out int lineLength )
157
180
{
158
181
signature = default ;
182
+ lineLength = default ;
159
183
160
- if ( ! line . Slice ( 0 , AuthorStart . Length ) . SequenceEqual ( AuthorStart ) )
184
+ if ( ! line . Slice ( 0 , signatureStart . Length ) . SequenceEqual ( signatureStart ) )
161
185
{
162
186
return false ;
163
187
}
164
188
165
- line = line . Slice ( AuthorStart . Length ) ;
189
+ line = line . Slice ( signatureStart . Length ) ;
166
190
167
191
int emailStart = line . IndexOf ( ( byte ) '<' ) ;
168
192
int emailEnd = line . IndexOf ( ( byte ) '>' ) ;
@@ -179,6 +203,7 @@ private static bool TryReadAuthor(ReadOnlySpan<byte> line, out GitSignature sign
179
203
long ticks = long . Parse ( GitRepository . GetString ( time . Slice ( 0 , offsetStart ) ) ) ;
180
204
signature . Date = DateTimeOffset . FromUnixTimeSeconds ( ticks ) ;
181
205
206
+ lineLength = signatureStart . Length + lineEnd + 1 ;
182
207
return true ;
183
208
}
184
209
}
0 commit comments