NewObjectHeaderIter returns an `ObjectHeaderIter` that iterates over the headers in a commit or tag object. `data` should be the object's contents, which is usually terminated by a blank line that separates the header from the comment. However, annotated tags don't always include comments, and Git e
(name string, data []byte)
| 21 | // without comments, so don't insist on a blank line. `name` is used |
| 22 | // in error messages. |
| 23 | func NewObjectHeaderIter(name string, data []byte) (ObjectHeaderIter, error) { |
| 24 | headerEnd := bytes.Index(data, []byte("\n\n")) |
| 25 | if headerEnd == -1 { |
| 26 | if len(data) == 0 { |
| 27 | return ObjectHeaderIter{}, fmt.Errorf("%s has zero length", name) |
| 28 | } |
| 29 | |
| 30 | if data[len(data)-1] != '\n' { |
| 31 | return ObjectHeaderIter{}, fmt.Errorf("%s has no terminating LF", name) |
| 32 | } |
| 33 | |
| 34 | return ObjectHeaderIter{name, string(data)}, nil |
| 35 | } |
| 36 | return ObjectHeaderIter{name, string(data[:headerEnd+1])}, nil |
| 37 | } |
| 38 | |
| 39 | // HasNext returns true iff there are more headers to retrieve. |
| 40 | func (iter *ObjectHeaderIter) HasNext() bool { |
no outgoing calls
no test coverage detected