Documentation
¶
Overview ¶
Package engine holds the operations that combine snapshots: three-way merges of trees and the rebase step used when landing changes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsGenerated ¶ added in v0.2.0
IsGenerated reports whether a file says it was generated: one of its first lines is "// Code generated ... DO NOT EDIT.". A conflict in such a file is fixed by regenerating it, not by editing conflict markers.
Types ¶
type Conflict ¶
type Conflict struct {
Path string
Kind ConflictKind
Base object.File // zero if the file did not exist in base
Ours object.File // zero if ours deleted it
Theirs object.File // zero if theirs deleted it
// Markers is the file with diff3-style conflict markers, for content
// and add/add conflicts on text files.
Markers []byte
Detail string
}
Conflict is one path that needs a decision.
type ConflictKind ¶
type ConflictKind string
ConflictKind names why a path could not be merged.
const ( ConflictContent ConflictKind = "content" // both sides edited the same lines ConflictAddAdd ConflictKind = "add/add" // both sides created the file differently ConflictModifyDelete ConflictKind = "modify/delete" // ours edited, theirs deleted ConflictDeleteModify ConflictKind = "delete/modify" // ours deleted, theirs edited ConflictMode ConflictKind = "mode" // both sides changed the mode differently ConflictBinary ConflictKind = "binary" // both sides changed a binary file ConflictPath ConflictKind = "path" // a file and a directory collide )
type GeneratedFile ¶ added in v0.3.0
type GeneratedFile struct {
Path string
// Command regenerates it, from a [[generated]] rule in vx.toml; empty
// when the rule has none or the file was recognised by its
// "Code generated ... DO NOT EDIT." line.
Command string
}
GeneratedFile is a generated file both sides changed, kept from ours.
type MergeOption ¶ added in v0.3.0
type MergeOption func(*mergeConfig)
MergeOption changes how MergeTrees treats some paths.
func WithGenerated ¶ added in v0.3.0
func WithGenerated(f func(path string) (command string, ok bool)) MergeOption
WithGenerated says which paths are generated (vx.toml [[generated]] rules, see rules.Rules.GeneratedMatcher). Files that say "Code generated ... DO NOT EDIT." are generated with or without this option.
type MergeResult ¶
type MergeResult struct {
// Tree is the merged root tree. It is Zero when there are conflicts.
Tree hash.Hash
// Conflicts lists paths that could not be merged.
Conflicts []Conflict
// AutoMerged lists paths both sides changed that merged line by line.
AutoMerged []string
// KeptBoth lists the paths in AutoMerged where both sides inserted
// different lines at the same place and the merge kept both (the side
// passed as theirs first). Worth a look: the order may matter.
KeptBoth []string
// Generated lists generated files both sides changed. They are never
// text-merged: the result has ours (the side being landed, synced,
// shipped or replayed), and the file has to be regenerated.
Generated []GeneratedFile
}
MergeResult is the outcome of MergeTrees.
func MergeTrees ¶
func MergeTrees(ctx context.Context, s blob.Store, base, ours, theirs hash.Hash, labels merge.Labels, opts ...MergeOption) (MergeResult, error)
MergeTrees merges ours and theirs, which both descend from base. Paths changed on one side take that side. Paths changed on both sides are merged line by line when possible. With conflicts, the result has no tree.
Generated files (see WithGenerated) changed on both sides are not merged: ours wins and the path is listed in Generated.
func MergeTreesKeepConflicts ¶
func MergeTreesKeepConflicts(ctx context.Context, s blob.Store, base, ours, theirs hash.Hash, labels merge.Labels, opts ...MergeOption) (MergeResult, error)
MergeTreesKeepConflicts is MergeTrees for a working copy: it always returns a tree. Text conflicts are written into the file with conflict markers; other conflicts keep our side. The caller shows the conflicts and the person or agent resolves them in place.
func (MergeResult) Clean ¶
func (r MergeResult) Clean() bool
Clean reports whether the merge has no conflicts.
type Warning ¶ added in v0.2.0
type Warning struct {
Path string // package directory for duplicates ("." for the root), file path for parse errors
Kind WarningKind //
Name string // duplicate: the name, "Recv.Name" for methods
Decl string // duplicate: func, method, type, var, const, or "declaration" when kinds differ
Files []string // duplicate: base names of the declaring files, sorted and unique
Detail string // human-readable summary
}
Warning is a semantic problem in a tree: the text merged, but the result will probably not build.
func CheckGo ¶ added in v0.2.0
func CheckGo(ctx context.Context, s blob.Store, root hash.Hash, changed []string) ([]Warning, error)
CheckGo looks for duplicate top-level declarations in the Go packages of root that contain one of the changed paths. Every .go file of such a directory is parsed, not only the changed ones, and packages are told apart by name, so package x and its external test package x_test in the same directory are checked separately. A duplicate is reported only when at least one of its declarations is in a changed file, so problems that predate the change are not repeated on every land.
Changed .go files that do not parse get a parse warning; other files that do not parse are skipped.
Limitations: build constraints (//go:build lines and _GOOS/_GOARCH file name suffixes) are evaluated for linux/amd64 with cgo and no custom tags. Files excluded on that platform are not checked, so a duplicate between two files for another platform, or one behind a custom tag, is missed. Only redeclarations are detected: an import name that collides with a package-level name, or a method that collides with a field, is not.
func GeneratedWarnings ¶ added in v0.3.0
func GeneratedWarnings(gs []GeneratedFile) []Warning
GeneratedWarnings turns generated files into warnings, sorted by path:
generated file gen/x.go: regenerate with `buf generate`
type WarningKind ¶ added in v0.2.0
type WarningKind string
WarningKind names a problem found in a merged tree that does not stop a land.
const ( // WarningDuplicate: one Go package declares the same top-level name twice, // typically because two changes each added it in a different file and the // text merged cleanly. WarningDuplicate WarningKind = "duplicate" // WarningParse: a changed Go file does not parse. WarningParse WarningKind = "parse" // WarningCheck: a check could not run; Detail says why. WarningCheck WarningKind = "check" )
const WarningGenerated WarningKind = "generated"
WarningGenerated: both sides changed a generated file; the merge kept ours and the file needs regenerating.