object

package
v0.0.0-...-4ff9f1c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash

func Hash(obj Object) string

Hash computes the SHA-1 hash of an object.

func Read

func Read(gitDir string, hash string) ([]byte, error)

Read reads an object from the Git object store.

func ReadFull

func ReadFull(gitDir string, hash string) ([]byte, error)

ReadFull reads an object from the Git object store with its header.

func Write

func Write(gitDir string, obj Object) (string, error)

Write writes an object to the Git object store.

Types

type Blob

type Blob struct {
	Content []byte
}

Blob represents a Git blob object (file content).

func NewBlob

func NewBlob(content []byte) *Blob

NewBlob creates a new blob object.

func (*Blob) Serialize

func (b *Blob) Serialize() []byte

Serialize returns the blob content.

func (*Blob) Type

func (b *Blob) Type() Type

Type returns the object type.

type Commit

type Commit struct {
	Tree       string    // SHA-1 hash of the tree object
	Parent     string    // SHA-1 hash of the parent commit (empty for initial commit)
	Author     string    // Author name and email
	AuthorDate time.Time // Author timestamp
	Committer  string    // Committer name and email
	CommitDate time.Time // Commit timestamp
	Message    string    // Commit message
}

Commit represents a Git commit object.

func NewCommit

func NewCommit(tree, parent, author, committer, message string) *Commit

NewCommit creates a new commit object.

func (*Commit) Serialize

func (c *Commit) Serialize() []byte

Serialize returns the commit content in Git format.

func (*Commit) Type

func (c *Commit) Type() Type

Type returns the object type.

type Object

type Object interface {
	Type() Type
	Serialize() []byte
}

Object represents a Git object.

type Tree

type Tree struct {
	Entries []TreeEntry
}

Tree represents a Git tree object (directory listing).

func NewTree

func NewTree() *Tree

NewTree creates a new tree object.

func (*Tree) AddEntry

func (t *Tree) AddEntry(mode, name, hash string)

AddEntry adds an entry to the tree.

func (*Tree) Serialize

func (t *Tree) Serialize() []byte

Serialize returns the tree content in Git format.

func (*Tree) Type

func (t *Tree) Type() Type

Type returns the object type.

type TreeEntry

type TreeEntry struct {
	Mode string // File mode (e.g., "100644" for regular file)
	Name string // File or directory name
	Hash string // SHA-1 hash of the object
}

TreeEntry represents an entry in a Git tree object.

type Type

type Type string

Type represents a Git object type.

const (
	TypeBlob   Type = "blob"
	TypeTree   Type = "tree"
	TypeCommit Type = "commit"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL