tree

package
v0.1.171 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package tree provides representations, parsers, and serializers for tree objects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendPath added in v0.1.152

func AppendPath(dst []byte, path [][]byte) []byte

AppendPath appends path to dst as one slash-separated byte path.

func ClonePath added in v0.1.152

func ClonePath(path [][]byte) [][]byte

ClonePath returns one deep copy of path.

func HasPathPrefix added in v0.1.152

func HasPathPrefix(path, prefix [][]byte) bool

HasPathPrefix reports whether path begins with prefix as whole components.

func SplitPath added in v0.1.152

func SplitPath(path []byte) [][]byte

SplitPath splits one slash-separated tree path into components.

func TreeEntryNameCompare

func TreeEntryNameCompare(entryName []byte, entryMode FileMode, searchName []byte, searchIsTree bool) int

TreeEntryNameCompare compares names using Git tree ordering rules.

Types

type FileMode

type FileMode uint32

FileMode represents the mode of a file in a Git tree.

const (
	FileModeDir        FileMode = 0o40000
	FileModeRegular    FileMode = 0o100644
	FileModeExecutable FileMode = 0o100755
	FileModeSymlink    FileMode = 0o120000
	FileModeGitlink    FileMode = 0o160000
)

func (FileMode) HasSameType added in v0.1.157

func (mode FileMode) HasSameType(other FileMode) bool

HasSameType reports whether mode and other describe the same tree entry kind.

Regular files and executable files have the same type for diff-status purposes.

func (FileMode) IsBlobLike added in v0.1.152

func (mode FileMode) IsBlobLike() bool

IsBlobLike reports whether mode names one blob-like tree entry kind.

Blob-like entries store blob object IDs as their targets.

func (FileMode) IsRegularFile added in v0.1.157

func (mode FileMode) IsRegularFile() bool

IsRegularFile reports whether mode names one regular-file variant.

type Tree

type Tree struct {
	// Entries must be sorted by TreeEntryNameCompare.
	// Use the Tree methods to preserve ordering and copy semantics rather than
	// modifying the slice directly.
	Entries []TreeEntry
}

Tree represents a fully materialized Git tree object.

Labels: MT-Unsafe.

func Parse

func Parse(body []byte, algo objectid.Algorithm) (*Tree, error)

Parse decodes a tree object body into a fully materialized Tree.

func (*Tree) Entry

func (tree *Tree) Entry(name []byte) *TreeEntry

Entry looks up a tree entry by name.

The returned pointer refers to storage within tree.Entries and must not be retained across InsertEntry or RemoveEntry calls.

func (*Tree) InsertEntry

func (tree *Tree) InsertEntry(newEntry TreeEntry) error

InsertEntry inserts a tree entry while preserving Git ordering.

InsertEntry copies newEntry.Name.

func (*Tree) ObjectType

func (tree *Tree) ObjectType() objecttype.Type

ObjectType returns TypeTree.

func (*Tree) RemoveEntry

func (tree *Tree) RemoveEntry(name []byte) error

RemoveEntry removes a tree entry by name.

func (*Tree) SerializeWithHeader

func (tree *Tree) SerializeWithHeader() ([]byte, error)

SerializeWithHeader renders the raw object (header + body).

func (*Tree) SerializeWithoutHeader

func (tree *Tree) SerializeWithoutHeader() ([]byte, error)

SerializeWithoutHeader renders the raw tree body bytes.

type TreeEntry

type TreeEntry struct {
	Mode FileMode
	// Name is part of the tree ordering. Mutating it after insertion may break
	// Tree ordering and lookup behavior.
	Name []byte
	ID   objectid.ObjectID
}

TreeEntry represents a single entry in a tree.

Jump to

Keyboard shortcuts

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