Parse a `cat-file --batch[-check]` output header line (including the trailing LF). `spec`, if not "", is used in error messages.
(spec string, header string)
| 21 | // Parse a `cat-file --batch[-check]` output header line (including |
| 22 | // the trailing LF). `spec`, if not "", is used in error messages. |
| 23 | func ParseBatchHeader(spec string, header string) (BatchHeader, error) { |
| 24 | header = header[:len(header)-1] |
| 25 | words := strings.Split(header, " ") |
| 26 | if words[len(words)-1] == "missing" { |
| 27 | if spec == "" { |
| 28 | spec = words[0] |
| 29 | } |
| 30 | return missingHeader, fmt.Errorf("missing object %s", spec) |
| 31 | } |
| 32 | |
| 33 | oid, err := NewOID(words[0]) |
| 34 | if err != nil { |
| 35 | return missingHeader, err |
| 36 | } |
| 37 | |
| 38 | size, err := strconv.ParseUint(words[2], 10, 0) |
| 39 | if err != nil { |
| 40 | return missingHeader, err |
| 41 | } |
| 42 | return BatchHeader{ |
| 43 | OID: oid, |
| 44 | ObjectType: ObjectType(words[1]), |
| 45 | ObjectSize: counts.NewCount32(size), |
| 46 | }, nil |
| 47 | } |
no test coverage detected