patch

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package patch parses and applies the bounded, model-facing patch grammar used by the coding application. It performs no filesystem I/O.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalid means a patch does not conform to the supported grammar.
	ErrInvalid = errors.New("coding patch: invalid patch")
	// ErrConflict means an update hunk does not identify one exact location.
	ErrConflict = errors.New("coding patch: context conflict")
	// ErrBinary means a patch or target contains non-text content.
	ErrBinary = errors.New("coding patch: binary content")
)

Functions

func Apply

func Apply(original []byte, hunks []Hunk) ([]byte, error)

Apply applies exact, ordered hunks to UTF-8 text in memory. It preserves a UTF-8 BOM, the existing line-ending style, and final-newline presence.

Types

type Change

type Change struct {
	Kind    Kind
	Path    string
	Content []byte
	Hunks   []Hunk
}

Change is one file operation in patch order.

type Document

type Document struct {
	Changes []Change
}

Document is one fully parsed patch.

func Parse

func Parse(value string, limits Limits) (Document, error)

Parse validates the complete patch before returning any operation.

type Hunk

type Hunk struct {
	Lines []Line
}

Hunk is one ordered exact-context update.

type Kind

type Kind uint8

Kind identifies one supported file operation.

const (
	Add Kind = iota + 1
	Update
	Delete
)

Supported file operation kinds.

type Limits

type Limits struct {
	Bytes int
	Files int
	// PlanPath, when non-empty, admits that exact absolute plan-file path as a
	// patch target in addition to workspace-relative paths.
	PlanPath string
}

Limits bounds parser input and file operations.

type Line

type Line struct {
	Operation byte
	Text      string
}

Line is one exact hunk line. Operation is space, plus, or minus.

Jump to

Keyboard shortcuts

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