MCPcopy Index your code
hub / github.com/github/git-sizer / NewObjectHeaderIter

Function NewObjectHeaderIter

git/obj_head_iter.go:23–37  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

21// without comments, so don't insist on a blank line. `name` is used
22// in error messages.
23func 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.
40func (iter *ObjectHeaderIter) HasNext() bool {

Callers 2

ParseTagFunction · 0.85
ParseCommitFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected