patch

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 3 Imported by: ? 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 patch implements a two-stage fault-tolerant search/replace patch engine for the MCP file tool.

Index

Constants

This section is empty.

Variables

View Source
var ErrAmbiguousMatch = errors.New("ambiguous patch block matched multiple locations")

ErrAmbiguousMatch indicates that a search block matched multiple locations.

View Source
var ErrInvalidFormat = errors.New("invalid patch format")

ErrInvalidFormat indicates a malformed search/replace patch payload.

View Source
var ErrNoMatch = errors.New("patch block did not match file content")

ErrNoMatch indicates that a search block was not found in the target content.

Functions

This section is empty.

Types

type Block

type Block struct {
	Search  string
	Replace string
}

Block represents a single <<<< ... ==== ... >>>> replacement operation.

func Parse

func Parse(raw string) ([]Block, error)

Parse extracts one or more search/replace blocks from raw patch text. Each block is delimited by lines starting with "<<<<", "====", and ">>>>".

type Result

type Result struct {
	Content string
	// Blocks is the number of blocks applied.
	Blocks int
	// Fuzzy is the number of blocks that matched only after ignoring leading
	// and trailing whitespace on each line; callers should surface this so the
	// edit can be reviewed.
	Fuzzy int
}

Result reports the outcome of Apply.

func Apply

func Apply(content, rawPatch string) (Result, error)

Apply parses raw patch blocks and applies them sequentially to content. Uniform CRLF files keep CRLF; files with mixed line endings are patched byte-for-byte without normalization so untouched lines keep their endings.

Jump to

Keyboard shortcuts

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