@@ -19,6 +19,7 @@ public static class GitCommitReader
1919 private static readonly byte [ ] TreeStart = GitRepository . Encoding . GetBytes ( "tree " ) ;
2020 private static readonly byte [ ] ParentStart = GitRepository . Encoding . GetBytes ( "parent " ) ;
2121 private static readonly byte [ ] AuthorStart = GitRepository . Encoding . GetBytes ( "author " ) ;
22+ private static readonly byte [ ] CommitterStart = GitRepository . Encoding . GetBytes ( "committer " ) ;
2223
2324 /// <summary>
2425 /// Reads a <see cref="GitCommit"/> object from a <see cref="Stream"/>.
@@ -30,7 +31,7 @@ public static class GitCommitReader
3031 /// The <see cref="GitObjectId"/> of the commit.
3132 /// </param>
3233 /// <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 .
3435 /// </param>
3536 /// <returns>
3637 /// The <see cref="GitCommit"/>.
@@ -67,7 +68,7 @@ public static GitCommit Read(Stream stream, GitObjectId sha, bool readAuthor = f
6768 /// The <see cref="GitObjectId"/> of the commit.
6869 /// </param>
6970 /// <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 .
7172 /// </param>
7273 /// <returns>
7374 /// The <see cref="GitCommit"/>.
@@ -102,11 +103,22 @@ public static GitCommit Read(ReadOnlySpan<byte> commit, GitObjectId sha, bool re
102103 buffer = buffer . Slice ( ParentLineLength ) ;
103104 }
104105
105- GitSignature signature = default ;
106+ GitSignature author = default ;
107+ GitSignature committer = default ;
106108
107- if ( readAuthor && ! TryReadAuthor ( buffer , out signature ) )
109+ if ( readAuthor )
108110 {
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+ }
110122 }
111123
112124 return new GitCommit ( )
@@ -116,7 +128,8 @@ public static GitCommit Read(ReadOnlySpan<byte> commit, GitObjectId sha, bool re
116128 SecondParent = secondParent ,
117129 AdditionalParents = additionalParents ,
118130 Tree = tree ,
119- Author = readAuthor ? signature : null ,
131+ Author = readAuthor ? author : null ,
132+ Committer = readAuthor ? committer : null ,
120133 } ;
121134 }
122135
@@ -153,16 +166,27 @@ private static bool TryReadParent(ReadOnlySpan<byte> line, out GitObjectId paren
153166 return true ;
154167 }
155168
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 )
157180 {
158181 signature = default ;
182+ lineLength = default ;
159183
160- if ( ! line . Slice ( 0 , AuthorStart . Length ) . SequenceEqual ( AuthorStart ) )
184+ if ( ! line . Slice ( 0 , signatureStart . Length ) . SequenceEqual ( signatureStart ) )
161185 {
162186 return false ;
163187 }
164188
165- line = line . Slice ( AuthorStart . Length ) ;
189+ line = line . Slice ( signatureStart . Length ) ;
166190
167191 int emailStart = line . IndexOf ( ( byte ) '<' ) ;
168192 int emailEnd = line . IndexOf ( ( byte ) '>' ) ;
@@ -179,6 +203,7 @@ private static bool TryReadAuthor(ReadOnlySpan<byte> line, out GitSignature sign
179203 long ticks = long . Parse ( GitRepository . GetString ( time . Slice ( 0 , offsetStart ) ) ) ;
180204 signature . Date = DateTimeOffset . FromUnixTimeSeconds ( ticks ) ;
181205
206+ lineLength = signatureStart . Length + lineEnd + 1 ;
182207 return true ;
183208 }
184209}
0 commit comments