aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-06-06 22:00:12 +0000
committerGravatar Runxi Yu2026-06-06 22:06:05 +0000
commit231b014b99e566f80f5ce20e841a6dd17a429512 (patch)
tree4098dc6d04f3fb5a1c3ff0455ab66e18e8e4752d
parentobject/signature: Detailed along with sentinel (diff)
signatureNo signature
object/commit: Sentilnel with description
-rw-r--r--object/commit/parse.go10
-rw-r--r--object/parse.go2
2 files changed, 8 insertions, 4 deletions
diff --git a/object/commit/parse.go b/object/commit/parse.go
index febd34e3..1e99ec48 100644
--- a/object/commit/parse.go
+++ b/object/commit/parse.go
@@ -18,9 +18,11 @@ func Parse(body []byte, objectFormat id.ObjectFormat) (*Commit, error) {
i := 0
for i < len(body) {
+ lineStart := i
+
rel := bytes.IndexByte(body[i:], '\n')
if rel < 0 {
- return nil, ErrInvalidCommit
+ return nil, fmt.Errorf("%w: unterminated header line at offset %d", ErrInvalidCommit, lineStart)
}
line := body[i : i+rel]
@@ -32,7 +34,7 @@ func Parse(body []byte, objectFormat id.ObjectFormat) (*Commit, error) {
key, value, found := bytes.Cut(line, []byte{' '})
if !found {
- return nil, ErrInvalidCommit
+ return nil, fmt.Errorf("%w: header line at offset %d has no ' ' separator", ErrInvalidCommit, lineStart)
}
switch string(key) {
@@ -70,7 +72,7 @@ func Parse(body []byte, objectFormat id.ObjectFormat) (*Commit, error) {
for i < len(body) {
nextRel := bytes.IndexByte(body[i:], '\n')
if nextRel < 0 {
- return nil, ErrInvalidCommit
+ return nil, fmt.Errorf("%w: unterminated signature header at offset %d", ErrInvalidCommit, i)
}
if body[i] != ' ' {
@@ -88,7 +90,7 @@ func Parse(body []byte, objectFormat id.ObjectFormat) (*Commit, error) {
}
if i > len(body) {
- return nil, ErrInvalidCommit
+ return nil, fmt.Errorf("%w: header section extends past end of body", ErrInvalidCommit)
}
c.Message = append([]byte(nil), body[i:]...)
diff --git a/object/parse.go b/object/parse.go
index b488eb49..6a60407c 100644
--- a/object/parse.go
+++ b/object/parse.go
@@ -47,6 +47,8 @@ func ParseWithoutHeader(ty typ.Type, body []byte, objectFormat id.ObjectFormat)
return commit.Parse(body, objectFormat) //nolint:wrapcheck
case typ.TypeTag:
panic("TODO")
+ case typ.TypeUnknown:
+ return nil, typ.ErrInvalidType
default:
return nil, typ.ErrInvalidType
}