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
- Variables
- func Warm(ctx context.Context, src Source, base, head gitpack.SHA) error
- type Batch
- func (b *Batch) Bytes() int
- func (b *Batch) Land(ctx context.Context, base, head gitpack.SHA, when time.Time) (Landed, error)
- func (b *Batch) LandExpecting(ctx context.Context, base, head gitpack.SHA, when time.Time, ...) (Landed, error)
- func (b *Batch) Objects() []gitpack.Object
- func (b *Batch) Tip() gitpack.SHA
- func (b *Batch) TreeOf(ctx context.Context, sha gitpack.SHA) (gitpack.SHA, error)
- type Change
- type Commit
- type ConflictError
- type Entry
- type History
- type Invalid
- type Landed
- type Mapped
- type Options
- type Source
- type StaleError
Constants ¶
const ( // DefaultMaxObjectBytes is the largest object that a land may make. DefaultMaxObjectBytes = gitpack.MaxObjectBytes // DefaultMaxChangedPaths is the most distinct leaves that one land may change. DefaultMaxChangedPaths = 100000 )
The limits of a Batch whose Options leave them zero.
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 ¶
var ErrTooLarge = errors.New("land: change is too large")
ErrTooLarge is a land that needs more than the limits allow.
Functions ¶
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, opts Options) *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) Land ¶
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) LandExpecting ¶ added in v0.7.0
func (b *Batch) LandExpecting(ctx context.Context, base, head gitpack.SHA, when time.Time, expect *gitpack.SHA) (Landed, error)
LandExpecting is Land that also returns a *StaleError, and moves nothing, when expect is set and the tree of the commit that head becomes differs from it. The check follows the conflict check.
type Change ¶
Change is a leaf that differs between two trees. Old is nil for an addition and New is nil for a removal, and a change of the content or the mode of a leaf has both. 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 ¶
ParseCommit reads the headers and the message of a commit object.
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 ¶
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.
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 Options ¶ added in v0.21.0
type Options struct {
// MaxChangedPaths is the most distinct leaves that one land may change.
MaxChangedPaths int
// MaxObjectBytes is the largest object that a land may make.
MaxObjectBytes int
}
Options sets the limits of a Batch. A zero field takes its default.
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.
type StaleError ¶ added in v0.7.0
StaleError is a land whose tree is not the tree that the caller expected. Tree is the tree that the land would make.
func (*StaleError) Error ¶ added in v0.7.0
func (e *StaleError) Error() string