ref: 9da262c92189e4007834bf2023f0c032f2a1a0d9
parent: bf477ba2743c622372f1dd2bd8c6fc7fb6661f96
author: Runxi Yu <runxiyu@umich.edu>
date: Sun Mar 29 06:55:24 EDT 2026
object{,/type}: Fix up API shape
--- a/cmd/show-object/main.go
+++ b/cmd/show-object/main.go
@@ -15,7 +15,6 @@
"codeberg.org/lindenii/furgit/object/stored"
"codeberg.org/lindenii/furgit/object/tag"
"codeberg.org/lindenii/furgit/object/tree"
- objecttype "codeberg.org/lindenii/furgit/object/type"
"codeberg.org/lindenii/furgit/repository"
)
@@ -92,7 +91,7 @@
id := s.ID()
ty := s.Object().ObjectType()
- tyName, ok := objecttype.Name(ty)
+ tyName, ok := ty.Name()
if !ok { tyName = fmt.Sprintf("type %d", ty)}
@@ -126,7 +125,7 @@
case *tag.Tag:
tag := obj
- targetTy, ok := objecttype.Name(tag.TargetType)
+ targetTy, ok := tag.TargetType.Name()
if !ok { targetTy = fmt.Sprintf("type %d", tag.TargetType)}
--- a/commitquery/ancestor_unit_test.go
+++ b/commitquery/ancestor_unit_test.go
@@ -29,7 +29,7 @@
// ancestorTagBody serializes one minimal annotated tag body.
func ancestorTagBody(target objectid.ObjectID, targetType objecttype.Type) []byte {- targetName, ok := objecttype.Name(targetType)
+ targetName, ok := targetType.Name()
if !ok { panic("invalid tag target type")}
--- a/commitquery/mergebase_unit_test.go
+++ b/commitquery/mergebase_unit_test.go
@@ -30,7 +30,7 @@
// tagBody serializes one minimal annotated tag body.
func tagBody(target objectid.ObjectID, targetType objecttype.Type) []byte {- targetName, ok := objecttype.Name(targetType)
+ targetName, ok := targetType.Name()
if !ok { panic("invalid tag target type")}
--- a/errors/type.go
+++ b/errors/type.go
@@ -17,12 +17,12 @@
// Error implements error.
func (e *ObjectTypeError) Error() string {- gotName, gotOK := objecttype.Name(e.Got)
+ gotName, gotOK := e.Got.Name()
if !gotOK { gotName = fmt.Sprintf("type(%d)", e.Got)}
- wantName, wantOK := objecttype.Name(e.Want)
+ wantName, wantOK := e.Want.Name()
if !wantOK { wantName = fmt.Sprintf("type(%d)", e.Want)}
--- a/object/fetch/object_parse.go
+++ b/object/fetch/object_parse.go
@@ -5,7 +5,6 @@
"codeberg.org/lindenii/furgit/object"
objectid "codeberg.org/lindenii/furgit/object/id"
- objecttype "codeberg.org/lindenii/furgit/object/type"
)
func (r *Fetcher) parseObject(id objectid.ObjectID) (object.Object, error) {@@ -14,9 +13,9 @@
return nil, err
}
- parsed, err := object.ParseObjectWithoutHeader(ty, content, id.Algorithm())
+ parsed, err := object.ParseWithoutHeader(ty, content, id.Algorithm())
if err != nil {- tyName, ok := objecttype.Name(ty)
+ tyName, ok := ty.Name()
if !ok { tyName = fmt.Sprintf("type %d", ty)}
--- a/object/header/append.go
+++ b/object/header/append.go
@@ -12,7 +12,7 @@
return nil, false
}
- tyName, ok := objecttype.Name(ty)
+ tyName, ok := ty.Name()
if !ok {return nil, false
}
--- a/object/header/parse.go
+++ b/object/header/parse.go
@@ -23,7 +23,7 @@
nul := space + 1 + nulRel
- ty, ok := objecttype.ParseName(string(data[:space]))
+ ty, ok := objecttype.Parse(string(data[:space]))
if !ok {return objecttype.TypeInvalid, 0, 0, false
}
--- a/object/parse_with_header.go
+++ b/object/parse_with_header.go
@@ -7,10 +7,10 @@
objectid "codeberg.org/lindenii/furgit/object/id"
)
-// ParseObjectWithHeader parses a loose object in "type size\x00body" format.
+// ParseWithHeader parses a loose object in "type size\x00body" format.
//
//nolint:ireturn
-func ParseObjectWithHeader(raw []byte, algo objectid.Algorithm) (Object, error) {+func ParseWithHeader(raw []byte, algo objectid.Algorithm) (Object, error) {ty, size, headerLen, ok := objectheader.Parse(raw)
if !ok { return nil, fmt.Errorf("object: malformed object header")@@ -21,5 +21,5 @@
return nil, fmt.Errorf("object: size mismatch: header says %d bytes, body has %d", size, len(body))}
- return ParseObjectWithoutHeader(ty, body, algo)
+ return ParseWithoutHeader(ty, body, algo)
}
--- a/object/parse_without_header.go
+++ b/object/parse_without_header.go
@@ -11,10 +11,10 @@
objecttype "codeberg.org/lindenii/furgit/object/type"
)
-// ParseObjectWithoutHeader parses a typed object body.
+// ParseWithoutHeader parses a typed object body.
//
//nolint:ireturn
-func ParseObjectWithoutHeader(ty objecttype.Type, body []byte, algo objectid.Algorithm) (Object, error) {+func ParseWithoutHeader(ty objecttype.Type, body []byte, algo objectid.Algorithm) (Object, error) { switch ty {case objecttype.TypeBlob:
return blob.Parse(body)
--- a/object/store/loose/helpers_test.go
+++ b/object/store/loose/helpers_test.go
@@ -48,7 +48,7 @@
typeName := testRepo.Run(t, "cat-file", "-t", id.String())
- ty, ok := objecttype.ParseName(typeName)
+ ty, ok := objecttype.Parse(typeName)
if !ok { t.Fatalf("ParseName(%q) failed", typeName)}
--- a/object/store/packed/helpers_test.go
+++ b/object/store/packed/helpers_test.go
@@ -50,7 +50,7 @@
typeName := testRepo.Run(t, "cat-file", "-t", id.String())
- ty, ok := objecttype.ParseName(typeName)
+ ty, ok := objecttype.Parse(typeName)
if !ok { t.Fatalf("ParseName(%q) failed", typeName)}
--- a/object/tag/parse.go
+++ b/object/tag/parse.go
@@ -45,7 +45,7 @@
t.Target = id
haveTarget = true
case "type":
- ty, ok := objecttype.ParseName(string(value))
+ ty, ok := objecttype.Parse(string(value))
if !ok { return nil, errors.New("object: tag: unknown target type")}
--- a/object/tag/serialize.go
+++ b/object/tag/serialize.go
@@ -18,7 +18,7 @@
var buf bytes.Buffer
fmt.Fprintf(&buf, "object %s\n", tag.Target.String())
- tyName, ok := objecttype.Name(tag.TargetType)
+ tyName, ok := tag.TargetType.Name()
if !ok { return nil, fmt.Errorf("object: tag: invalid target type %d", tag.TargetType)}
--- a/object/type/name.go
+++ b/object/type/name.go
@@ -7,8 +7,8 @@
typeNameTag = "tag"
)
-// ParseName parses a canonical Git object type name.
-func ParseName(name string) (Type, bool) {+// Parse parses a canonical Git object type name.
+func Parse(name string) (Type, bool) { switch name {case typeNameBlob:
return TypeBlob, true
@@ -24,7 +24,7 @@
}
// Name returns the canonical Git object type name.
-func Name(ty Type) (string, bool) {+func (ty Type) Name() (string, bool) { switch ty {case TypeBlob:
return typeNameBlob, true
--- a/reachability/unit_test.go
+++ b/reachability/unit_test.go
@@ -49,7 +49,7 @@
}
func tagBody(target objectid.ObjectID, targetType objecttype.Type) []byte {- targetName, ok := objecttype.Name(targetType)
+ targetName, ok := targetType.Name()
if !ok { panic("invalid tag target type")}
--
⑨