Fast implementation of Git in pure Go codeberg.org/lindenii/furgit
git go
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

object/type: Use table structure

Runxi Yu 301bb73d 0109f090

+66 -64
+10
object/type/details.go
··· 1 + package objecttype 2 + 3 + type typeDetails struct { 4 + name string 5 + isBaseObject bool 6 + } 7 + 8 + func (ty Type) details() typeDetails { 9 + return typeTable[ty] 10 + }
+7
object/type/is_base.go
··· 1 + package objecttype 2 + 3 + // IsBaseObject reports whether ty is one of the four canonical Git object 4 + // types encoded directly in pack entries. 5 + func (ty Type) IsBaseObject() bool { 6 + return ty.details().isBaseObject 7 + }
+4 -35
object/type/name.go
··· 1 1 package objecttype 2 2 3 - const ( 4 - typeNameBlob = "blob" 5 - typeNameTree = "tree" 6 - typeNameCommit = "commit" 7 - typeNameTag = "tag" 8 - ) 9 - 10 - // Parse parses a canonical Git object type name. 11 - func Parse(name string) (Type, bool) { 12 - switch name { 13 - case typeNameBlob: 14 - return TypeBlob, true 15 - case typeNameTree: 16 - return TypeTree, true 17 - case typeNameCommit: 18 - return TypeCommit, true 19 - case typeNameTag: 20 - return TypeTag, true 21 - default: 22 - return TypeInvalid, false 23 - } 24 - } 25 - 26 3 // Name returns the canonical Git object type name. 27 4 func (ty Type) Name() (string, bool) { 28 - switch ty { 29 - case TypeBlob: 30 - return typeNameBlob, true 31 - case TypeTree: 32 - return typeNameTree, true 33 - case TypeCommit: 34 - return typeNameCommit, true 35 - case TypeTag: 36 - return typeNameTag, true 37 - case TypeInvalid, TypeFuture, TypeOfsDelta, TypeRefDelta: 38 - return "", false 39 - default: 5 + details := ty.details() 6 + if details.name == "" { 40 7 return "", false 41 8 } 9 + 10 + return details.name, true 42 11 }
-29
object/type/objecttype.go
··· 1 - // Package objecttype provides Git object type tags and names. 2 - package objecttype 3 - 4 - // Type mirrors Git object type tags in packfiles. 5 - type Type uint8 6 - 7 - const ( 8 - TypeInvalid Type = 0 9 - TypeCommit Type = 1 10 - TypeTree Type = 2 11 - TypeBlob Type = 3 12 - TypeTag Type = 4 13 - TypeFuture Type = 5 14 - TypeOfsDelta Type = 6 15 - TypeRefDelta Type = 7 16 - ) 17 - 18 - // IsBaseObject reports whether ty is one of the four canonical Git object 19 - // types encoded directly in pack entries. 20 - func (ty Type) IsBaseObject() bool { 21 - switch ty { 22 - case TypeCommit, TypeTree, TypeBlob, TypeTag: 23 - return true 24 - case TypeInvalid, TypeFuture, TypeOfsDelta, TypeRefDelta: 25 - return false 26 - default: 27 - return false 28 - } 29 - }
+8
object/type/parse.go
··· 1 + package objecttype 2 + 3 + // Parse parses a canonical Git object type name. 4 + func Parse(name string) (Type, bool) { 5 + ty, ok := typeByName[name] 6 + 7 + return ty, ok 8 + }
+21
object/type/table.go
··· 1 + package objecttype 2 + 3 + //nolint:gochecknoglobals 4 + var typeTable = [...]typeDetails{ 5 + TypeInvalid: {}, 6 + TypeCommit: {name: "commit", isBaseObject: true}, 7 + TypeTree: {name: "tree", isBaseObject: true}, 8 + TypeBlob: {name: "blob", isBaseObject: true}, 9 + TypeTag: {name: "tag", isBaseObject: true}, 10 + TypeFuture: {}, 11 + TypeOfsDelta: {}, 12 + TypeRefDelta: {}, 13 + } 14 + 15 + //nolint:gochecknoglobals 16 + var typeByName = map[string]Type{ 17 + typeTable[TypeCommit].name: TypeCommit, 18 + typeTable[TypeTree].name: TypeTree, 19 + typeTable[TypeBlob].name: TypeBlob, 20 + typeTable[TypeTag].name: TypeTag, 21 + }
+16
object/type/type.go
··· 1 + // Package objecttype provides Git object type tags and names. 2 + package objecttype 3 + 4 + // Type mirrors Git object type tags in packfiles. 5 + type Type uint8 6 + 7 + const ( 8 + TypeInvalid Type = 0 9 + TypeCommit Type = 1 10 + TypeTree Type = 2 11 + TypeBlob Type = 3 12 + TypeTag Type = 4 13 + TypeFuture Type = 5 14 + TypeOfsDelta Type = 6 15 + TypeRefDelta Type = 7 16 + )