engine

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 18 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 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

func IsGenerated(data []byte) bool

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 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
}

MergeResult is the outcome of MergeTrees.

func MergeTrees

func MergeTrees(ctx context.Context, s blob.Store, base, ours, theirs hash.Hash, labels merge.Labels) (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.

func MergeTreesKeepConflicts

func MergeTreesKeepConflicts(ctx context.Context, s blob.Store, base, ours, theirs hash.Hash, labels merge.Labels) (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.

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"
)

Jump to

Keyboard shortcuts

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