Documentation
¶
Overview ¶
Package object implements the content-addressed object store for graft, supporting SHA-256 hashed blobs, entities, entity lists, trees, commits, and tags with zlib compression and pack file delta encoding.
Index ¶
- Constants
- func CommitSigningPayload(c *CommitObj) []byte
- func CompressPackPayload(raw []byte) ([]byte, error)
- func MarshalBlob(b *Blob) []byte
- func MarshalCommit(c *CommitObj) []byte
- func MarshalEntity(e *EntityObj) []byte
- func MarshalEntityList(el *EntityListObj) []byte
- func MarshalPackEntityTrailer(entries []PackEntityTrailerEntry) ([]byte, error)
- func MarshalTag(t *TagObj) []byte
- func MarshalTree(tr *TreeObj) []byte
- func ValidateHash(s string) error
- type Blob
- type CommitObj
- type EntityListObj
- type EntityObj
- type GCSummary
- type Hash
- type ObjectType
- type PackEntityTrailer
- type PackEntityTrailerEntry
- type PackEntry
- type PackFile
- type PackHeader
- type PackIndex
- type PackIndexEntry
- type PackObjectType
- type PackWriter
- func (p *PackWriter) CurrentOffset() uint64
- func (p *PackWriter) Finish() (Hash, error)
- func (p *PackWriter) FinishWithEntityTrailer(entries []PackEntityTrailerEntry) (Hash, error)
- func (p *PackWriter) WriteCompressedEntry(objType PackObjectType, rawSize uint64, compressed []byte) error
- func (p *PackWriter) WriteEntry(objType PackObjectType, data []byte) error
- func (p *PackWriter) WriteOfsDelta(baseOffset uint64, baseData, targetData []byte) error
- type Store
- func (s *Store) GC() (*GCSummary, error)
- func (s *Store) GCReachable(roots []Hash) (*GCSummary, error)
- func (s *Store) Has(h Hash) bool
- func (s *Store) InvalidatePackIndexCache()
- func (s *Store) ReachableSet(roots []Hash) (map[Hash]struct{}, error)
- func (s *Store) Read(h Hash) (ObjectType, []byte, error)
- func (s *Store) ReadBlob(h Hash) (*Blob, error)
- func (s *Store) ReadCommit(h Hash) (*CommitObj, error)
- func (s *Store) ReadEntity(h Hash) (*EntityObj, error)
- func (s *Store) ReadEntityList(h Hash) (*EntityListObj, error)
- func (s *Store) ReadTag(h Hash) (*TagObj, error)
- func (s *Store) ReadTree(h Hash) (*TreeObj, error)
- func (s *Store) Verify() (*VerifySummary, error)
- func (s *Store) Write(objType ObjectType, data []byte) (Hash, error)
- func (s *Store) WriteBlob(b *Blob) (Hash, error)
- func (s *Store) WriteCommit(c *CommitObj) (Hash, error)
- func (s *Store) WriteEntity(e *EntityObj) (Hash, error)
- func (s *Store) WriteEntityList(el *EntityListObj) (Hash, error)
- func (s *Store) WriteTag(t *TagObj) (Hash, error)
- func (s *Store) WriteTree(tr *TreeObj) (Hash, error)
- type TagObj
- type TreeEntry
- type TreeObj
- type VerifySummary
Constants ¶
const ( // Tree mode constants compatible with Git's canonical mode strings. TreeModeDir = "40000" TreeModeFile = "100644" TreeModeExecutable = "100755" TreeModeModule = "160000" )
Variables ¶
This section is empty.
Functions ¶
func CommitSigningPayload ¶
CommitSigningPayload returns the canonical bytes that are signed for a commit. The payload intentionally excludes the signature field itself.
func CompressPackPayload ¶
CompressPackPayload zlib-compresses a raw pack payload so callers can parallelize pack preparation before serial pack writing.
func MarshalBlob ¶
MarshalBlob serializes a Blob to raw bytes (identity).
func MarshalCommit ¶
MarshalCommit serializes a CommitObj:
tree H parent H (zero or more) author A timestamp T author_tz TZ (optional) committer C (optional) committer_timestamp T (optional) committer_tz TZ (optional) signature S (optional) message
func MarshalEntity ¶
MarshalEntity serializes an EntityObj to a deterministic text format:
kind X name Y declkind Z receiver R bodyhash H <body bytes>
func MarshalEntityList ¶
func MarshalEntityList(el *EntityListObj) []byte
MarshalEntityList serializes an EntityListObj:
language X path Y hash1 hash2 ...
func MarshalPackEntityTrailer ¶
func MarshalPackEntityTrailer(entries []PackEntityTrailerEntry) ([]byte, error)
MarshalPackEntityTrailer serializes entries to the Graft pack trailer format.
func MarshalTree ¶
MarshalTree serializes a TreeObj. Entries are sorted by Name for deterministic output. Each entry is one line:
name mode blobhash entitylisthash subtreehash
where mode is a Git-compatible mode string (e.g. 40000, 100644, 100755), and empty hashes are represented as "-".
func ValidateHash ¶
ValidateHash checks that s is a well-formed 64-character lowercase hex hash. Returns an error if the hash is invalid.
Types ¶
type Blob ¶
type Blob struct {
Data []byte
}
Blob holds raw file data.
func UnmarshalBlob ¶
UnmarshalBlob deserializes raw bytes into a Blob and copies input data. This preserves ownership semantics for callers that reuse input buffers.
func UnmarshalBlobNoCopy ¶
UnmarshalBlobNoCopy deserializes raw bytes into a Blob without copying. The returned Blob aliases data; callers must keep data immutable while the Blob is in use.
type CommitObj ¶
type CommitObj struct {
TreeHash Hash
Parents []Hash
Author string
Timestamp int64
AuthorTimezone string
Committer string
CommitterTimestamp int64
CommitterTimezone string
Signature string
Message string
}
CommitObj represents a commit pointing to a tree with metadata.
func UnmarshalCommit ¶
UnmarshalCommit parses a CommitObj from its serialized form.
type EntityListObj ¶
type EntityListObj struct {
Language string
Path string
EntityRefs []Hash // ordered refs to EntityObj hashes
}
EntityListObj is an ordered list of entity references for a file.
func UnmarshalEntityList ¶
func UnmarshalEntityList(data []byte) (*EntityListObj, error)
UnmarshalEntityList parses an EntityListObj from its serialized form.
type EntityObj ¶
type EntityObj struct {
Kind string // e.g. "function", "type", "method"
Name string
DeclKind string // language-specific declaration kind
Receiver string // method receiver, empty for non-methods
Body []byte
BodyHash Hash
}
EntityObj represents a single code entity (function, type, etc.).
func UnmarshalEntity ¶
UnmarshalEntity parses an EntityObj from its serialized form.
type Hash ¶
type Hash string
Hash is a 64-character hex-encoded SHA-256 digest.
func HashBytes ¶
HashBytes computes the raw SHA-256 hash of data and returns it as a lowercase hex-encoded Hash.
func HashObject ¶
func HashObject(objType ObjectType, data []byte) Hash
HashObject computes the SHA-256 of the envelope "type len\0content", mirroring Git's object hashing but with SHA-256.
func WritePackEntityTrailer ¶
func WritePackEntityTrailer(w io.Writer, entries []PackEntityTrailerEntry) (Hash, error)
WritePackEntityTrailer writes the encoded trailer and returns its checksum.
func WritePackIndex ¶
WritePackIndex writes a Git idx v2 style index for the provided entries and pack checksum. It returns the hex-encoded index checksum.
type ObjectType ¶
type ObjectType string
ObjectType identifies the kind of object stored.
const ( TypeBlob ObjectType = "blob" TypeTag ObjectType = "tag" TypeEntity ObjectType = "entity" TypeEntityList ObjectType = "entitylist" TypeTree ObjectType = "tree" TypeCommit ObjectType = "commit" )
type PackEntityTrailer ¶
type PackEntityTrailer struct {
Version uint16
Entries []PackEntityTrailerEntry
Checksum Hash
}
PackEntityTrailer is the parsed Graft-specific pack extension trailer.
func ReadPackEntityTrailer ¶
func ReadPackEntityTrailer(data []byte) (*PackEntityTrailer, error)
ReadPackEntityTrailer parses and validates a full trailer byte slice.
type PackEntityTrailerEntry ¶
PackEntityTrailerEntry maps one object hash to an entity stable identifier.
type PackEntry ¶
type PackEntry struct {
Type PackObjectType
OriginalType PackObjectType
Size uint64
Data []byte
Offset uint64
BaseDistance uint64 // populated for OFS_DELTA entries
BaseRef Hash // populated for REF_DELTA entries
}
PackEntry represents one object entry in a pack stream.
func ResolvePackEntries ¶
ResolvePackEntries resolves OFS_DELTA and REF_DELTA entries to full object contents. Returned entries preserve OriginalType while Type is set to the resolved concrete object type.
type PackFile ¶
type PackFile struct {
Header PackHeader
Entries []PackEntry
Checksum Hash
EntityTrailer *PackEntityTrailer
}
PackFile is the decoded content of a full pack stream.
func ReadPack ¶
ReadPack parses a full pack file byte slice, verifies trailer checksum, and returns decoded entries.
func ReadPackFromReader ¶
ReadPackFromReader reads a complete pack stream from r and delegates to ReadPack for decode and verification.
func ReadPackResolved ¶
ReadPackResolved parses and resolves delta entries to their materialized object contents.
type PackHeader ¶
PackHeader is the fixed-size Git pack header.
Bytes:
- 0..3: "PACK"
- 4..7: version (big-endian)
- 8..11: number of objects (big-endian)
func UnmarshalPackHeader ¶
func UnmarshalPackHeader(data []byte) (*PackHeader, error)
UnmarshalPackHeader parses a canonical Git pack header.
func (PackHeader) Marshal ¶
func (h PackHeader) Marshal() []byte
Marshal serializes the header to the canonical 12-byte pack header.
type PackIndex ¶
type PackIndex struct {
PackChecksum Hash
IndexChecksum Hash
// contains filtered or unexported fields
}
PackIndex is an in-memory representation of an idx v2 file.
func ReadPackIndex ¶
ReadPackIndex parses and validates an idx v2 file.
func ReadPackIndexFromReader ¶
ReadPackIndexFromReader parses an idx v2 stream.
func (*PackIndex) Entries ¶
func (idx *PackIndex) Entries() []PackIndexEntry
Entries returns a copy of all index entries in lexicographic hash order.
type PackIndexEntry ¶
PackIndexEntry is one row in a pack index file.
type PackObjectType ¶
type PackObjectType uint8
PackObjectType is the Git pack object type encoding used in object entry headers. Values match the canonical Git wire/storage format.
const ( PackCommit PackObjectType = 1 PackTree PackObjectType = 2 PackBlob PackObjectType = 3 PackTag PackObjectType = 4 PackOfsDelta PackObjectType = 6 PackRefDelta PackObjectType = 7 )
type PackWriter ¶
type PackWriter struct {
// contains filtered or unexported fields
}
PackWriter writes Git-compatible pack streams with zlib-compressed object entries. The trailer checksum is SHA-256 over all bytes preceding the trailer.
func NewPackWriter ¶
func NewPackWriter(out io.Writer, numObjects uint32) (*PackWriter, error)
NewPackWriter initializes a new writer and writes the fixed pack header.
func (*PackWriter) CurrentOffset ¶
func (p *PackWriter) CurrentOffset() uint64
CurrentOffset returns the current byte offset in the pack stream (from pack start), excluding the trailing checksum written by Finish().
func (*PackWriter) Finish ¶
func (p *PackWriter) Finish() (Hash, error)
Finish validates object count, writes the trailing pack checksum, and returns that checksum as a hex digest.
func (*PackWriter) FinishWithEntityTrailer ¶
func (p *PackWriter) FinishWithEntityTrailer(entries []PackEntityTrailerEntry) (Hash, error)
FinishWithEntityTrailer behaves like Finish and additionally appends the Graft-specific entity trailer after the standard pack checksum.
func (*PackWriter) WriteCompressedEntry ¶
func (p *PackWriter) WriteCompressedEntry(objType PackObjectType, rawSize uint64, compressed []byte) error
WriteCompressedEntry appends an already-compressed object entry. The caller is responsible for passing the uncompressed object size alongside the exact zlib-compressed payload bytes for that object.
func (*PackWriter) WriteEntry ¶
func (p *PackWriter) WriteEntry(objType PackObjectType, data []byte) error
WriteEntry appends one object entry to the pack stream.
func (*PackWriter) WriteOfsDelta ¶
func (p *PackWriter) WriteOfsDelta(baseOffset uint64, baseData, targetData []byte) error
WriteOfsDelta writes an OFS_DELTA entry using an insert-only delta stream.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a content-addressed object store with a 2-character fan-out directory layout: objects/ab/cdef0123...
func NewStore ¶
NewStore creates a Store rooted at the given directory. The objects/ subdirectory is created lazily on first write.
func (*Store) GC ¶
GC packs all loose objects that are not already indexed by an existing pack idx. After a successful pack+index write, packed loose objects are removed.
func (*Store) GCReachable ¶
GCReachable packs loose objects reachable from roots that are not already indexed by an existing pack idx. After a successful pack+index write, packed loose objects are removed.
func (*Store) InvalidatePackIndexCache ¶
func (s *Store) InvalidatePackIndexCache()
InvalidatePackIndexCache drops all cached pack indices, forcing a re-read on the next access. This is useful after GC or external pack modifications.
func (*Store) ReachableSet ¶
ReachableSet returns all object hashes reachable from roots by following object references. Missing roots are ignored.
func (*Store) Read ¶
func (s *Store) Read(h Hash) (ObjectType, []byte, error)
Read retrieves an object by hash, returning its type and raw content.
func (*Store) ReadCommit ¶
ReadCommit reads and deserializes a CommitObj.
func (*Store) ReadEntity ¶
ReadEntity reads and deserializes an EntityObj.
func (*Store) ReadEntityList ¶
func (s *Store) ReadEntityList(h Hash) (*EntityListObj, error)
ReadEntityList reads and deserializes an EntityListObj.
func (*Store) Verify ¶
func (s *Store) Verify() (*VerifySummary, error)
Verify checks object integrity across loose objects and pack/index entries.
func (*Store) Write ¶
func (s *Store) Write(objType ObjectType, data []byte) (Hash, error)
Write stores an object and returns its content hash. The on-disk format is zlib("type len\0content"). Writes are atomic: data is written to a temp file and then renamed into place.
func (*Store) WriteCommit ¶
WriteCommit serializes and stores a CommitObj.
func (*Store) WriteEntity ¶
WriteEntity serializes and stores an EntityObj.
func (*Store) WriteEntityList ¶
func (s *Store) WriteEntityList(el *EntityListObj) (Hash, error)
WriteEntityList serializes and stores an EntityListObj.
type TagObj ¶
TagObj preserves annotated tag payload while tracking the referenced object. Data stores the canonical tag bytes, where the "object" header points at the graft hash (not git hash) so graph traversal can stay in graft object space.
func UnmarshalTag ¶
UnmarshalTag parses a TagObj from its serialized form.
type TreeEntry ¶
type TreeEntry struct {
Name string
IsDir bool
Mode string
BlobHash Hash
EntityListHash Hash
SubtreeHash Hash
}
TreeEntry is one entry in a tree object.
type TreeObj ¶
type TreeObj struct {
Entries []TreeEntry // sorted by Name
}
TreeObj holds a sorted list of tree entries.
func UnmarshalTree ¶
UnmarshalTree parses a TreeObj from its serialized form.
type VerifySummary ¶
VerifySummary reports the outcome of Store.Verify.