@@ -576,13 +576,24 @@ type ObjectHeaderIter struct {
576576 data string
577577}
578578
579- // Iterate over an object header. `data` should be the object's
580- // contents, including the "\n\n" that separates the header from the
581- // rest of the contents. `name` is used in error messages.
579+ // Iterate over a commit or tag object header. `data` should be the
580+ // object's contents, which is usually terminated by a blank line that
581+ // separates the header from the comment. However, annotated tags
582+ // don't always include comments, and Git even tolerates commits
583+ // without comments, so don't insist on a blank line. `name` is used
584+ // in error messages.
582585func NewObjectHeaderIter (name string , data []byte ) (ObjectHeaderIter , error ) {
583586 headerEnd := bytes .Index (data , []byte ("\n \n " ))
584587 if headerEnd == - 1 {
585- return ObjectHeaderIter {}, fmt .Errorf ("%s has no header separator" , name )
588+ if len (data ) == 0 {
589+ return ObjectHeaderIter {}, fmt .Errorf ("%s has zero length" , name )
590+ }
591+
592+ if data [len (data )- 1 ] != '\n' {
593+ return ObjectHeaderIter {}, fmt .Errorf ("%s has no terminating LF" , name )
594+ }
595+
596+ return ObjectHeaderIter {name , string (data )}, nil
586597 }
587598 return ObjectHeaderIter {name , string (data [:headerEnd + 1 ])}, nil
588599}
0 commit comments