land

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package land rebases a linear range of commits onto the tip of a ref by applying its tree changes, with a file-level conflict check. It is pure over a read-only object source: it stores nothing and holds no lock.

Index

Constants

View Source
const (
	// MaxCommits is the longest range that one land takes.
	MaxCommits = 1000
	// MaxLoggedPaths is the most paths that a log row keeps. A land that changes more is logged as overflow.
	MaxLoggedPaths = 1000
	// MaxRewriteBytes is the most new object data that one land may write.
	MaxRewriteBytes = 32 << 20
	// MaxConflictPaths is the most paths that a conflict names.
	MaxConflictPaths = 1000
)

Variables

View Source
var ErrTooLarge = errors.New("land: change is too large")

ErrTooLarge is a land that needs more than the limits allow.

View Source
var MaxChangedPaths = 100000

MaxChangedPaths is the most distinct leaves that one land may change.

View Source
var MaxObjectBytes = gitpack.MaxObjectBytes

MaxObjectBytes is the largest object that a land may make.

Functions

This section is empty.

Types

type Batch

type Batch struct {
	// contains filtered or unexported fields
}

Batch lands changes one after the other on a running tip, and holds the objects that it makes until the caller stores them. A later land of the batch sees the earlier ones. A Batch is for one goroutine.

func NewBatch

func NewBatch(src Source, grow func(retained int64) error, tip gitpack.SHA, hist History) *Batch

NewBatch starts a batch on tip. grow is told how many bytes the batch holds before each read, and may refuse. hist answers the stored lands since a base.

func (*Batch) Bytes

func (b *Batch) Bytes() int

Bytes is the size of the objects that the lands made.

func (*Batch) Land

func (b *Batch) Land(ctx context.Context, base, head gitpack.SHA, when time.Time) (Landed, error)

Land lands base..head on the running tip. A head that descends from the tip moves the ref to head as it is. Any other range is rebuilt on the tip with the commit time when. It returns a *ConflictError when a path of the range also changed since base, and Invalid or ErrTooLarge when the range cannot land. A failed land leaves no trace.

func (*Batch) Objects

func (b *Batch) Objects() []gitpack.Object

Objects returns the objects that the lands made, in the order made.

func (*Batch) Tip

func (b *Batch) Tip() gitpack.SHA

Tip is the tip after the lands so far.

type Change

type Change struct {
	Path     string
	Old, New *Entry
}

Change is a leaf that differs between two trees. Old is nil for an addition and New is nil for a removal. A rename is a removal and an addition. A directory that becomes a file is the removal of each leaf under it and the addition of the file.

type Commit

type Commit struct {
	Tree      gitpack.SHA
	Parents   []gitpack.SHA
	Author    string
	Committer string

	Message []byte
	// contains filtered or unexported fields
}

Commit is a parsed commit object.

func ParseCommit

func ParseCommit(data []byte) (Commit, error)

ParseCommit reads the headers and the message of a commit object.

func (Commit) Rebuild

func (c Commit) Rebuild(parent, tree gitpack.SHA, when time.Time) ([]byte, error)

Rebuild returns the bytes of c on top of parent with tree. The author, the message and every header except a signature stay. The committer keeps its name and address, with when as the time in UTC.

type ConflictError

type ConflictError struct{ Paths []string }

ConflictError is a change that touches a path that also changed since its base.

func (*ConflictError) Error

func (e *ConflictError) Error() string

type Entry

type Entry struct {
	Name string
	Mode uint32
	SHA  gitpack.SHA
}

Entry is one entry of a tree. A directory has the mode 040000. Any other entry, a submodule too, is a leaf.

type History

type History func(ctx context.Context, base gitpack.SHA, emit func(path string)) (ok bool, err error)

History emits every path that the stored lands changed from base up to the tip at the start of the batch. It reports ok false, and emits nothing, when the stored lands cannot answer. The caller then diffs trees.

type Invalid

type Invalid string

Invalid is a change that cannot land, whatever the state of the ref. Its text names the reason.

func (Invalid) Error

func (e Invalid) Error() string

type Landed

type Landed struct {
	Old, New    gitpack.SHA
	FastForward bool
	Noop        bool
	Commits     []Mapped
	Paths       []string
	Overflow    bool
}

Landed is one land of a batch. Paths holds the changed leaves, and is nil with Overflow set when there are more than MaxLoggedPaths.

type Mapped

type Mapped struct{ Old, New gitpack.SHA }

Mapped is a commit of the range and the commit that replaced it.

type Source

type Source interface {
	Get(ctx context.Context, sha gitpack.SHA, before func(size int64) error) (gitpack.Type, []byte, error)
}

Source reads stored objects. before gets the size of an object before the source reads it.

Jump to

Keyboard shortcuts

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