1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
package git
import (
"fmt"
"strconv"
"strings"
"github.com/github/git-sizer/counts"
)
type BatchHeader struct {
OID OID
ObjectType ObjectType
ObjectSize counts.Count32
}
var missingHeader = BatchHeader{
ObjectType: "missing",
}
// Parse a `cat-file --batch[-check]` output header line (including
// the trailing LF). `spec`, if not "", is used in error messages.
func ParseBatchHeader(spec string, header string) (BatchHeader, error) {
header = header[:len(header)-1]
words := strings.Split(header, " ")
if words[len(words)-1] == "missing" {
if spec == "" {
spec = words[0]
}
return missingHeader, fmt.Errorf("missing object %s", spec)
}
oid, err := NewOID(words[0])
if err != nil {
return missingHeader, err
}
size, err := strconv.ParseUint(words[2], 10, 0)
if err != nil {
return missingHeader, err
}
return BatchHeader{
OID: oid,
ObjectType: ObjectType(words[1]),
ObjectSize: counts.NewCount32(size),
}, nil
}
|