ParseReference parses `line` (a non-LF-terminated line) into a `Reference`. It is assumed that `line` is formatted like the output of git for-each-ref --format='%(objectname) %(objecttype) %(objectsize) %(refname)'
(line string)
| 29 | // |
| 30 | // git for-each-ref --format='%(objectname) %(objecttype) %(objectsize) %(refname)' |
| 31 | func ParseReference(line string) (Reference, error) { |
| 32 | words := strings.Split(line, " ") |
| 33 | if len(words) != 4 { |
| 34 | return Reference{}, fmt.Errorf("line improperly formatted: %#v", line) |
| 35 | } |
| 36 | oid, err := NewOID(words[0]) |
| 37 | if err != nil { |
| 38 | return Reference{}, fmt.Errorf("SHA-1 improperly formatted: %#v", words[0]) |
| 39 | } |
| 40 | objectType := ObjectType(words[1]) |
| 41 | objectSize, err := strconv.ParseUint(words[2], 10, 32) |
| 42 | if err != nil { |
| 43 | return Reference{}, fmt.Errorf("object size improperly formatted: %#v", words[2]) |
| 44 | } |
| 45 | refname := words[3] |
| 46 | return Reference{ |
| 47 | Refname: refname, |
| 48 | ObjectType: objectType, |
| 49 | ObjectSize: counts.Count32(objectSize), |
| 50 | OID: oid, |
| 51 | }, nil |
| 52 | } |
no test coverage detected