patch

package
v1.0.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 6 Imported by: 0

Documentation

Overview

Package patch implements the frozen CEM 0.1 bounded unified-diff parser specified by interop/cem-0.1/ALGORITHMS.md.

Index

Constants

View Source
const (
	MaxPatchBytes = 8 << 20
	MaxLFRecords  = 262144
)

Frozen bounds.

Variables

This section is empty.

Functions

func SplitLF

func SplitLF(data []byte) ([][]byte, error)

SplitLF applies the frozen LF tokenizer: the record count is the LF count plus one exactly when the non-empty input does not end in LF; inputs above MaxLFRecords records are rejected before splitting. Records retain their LF.

Types

type BodyLine

type BodyLine struct {
	Prefix     byte
	Payload    []byte
	StripLFOld bool
	StripLFNew bool
}

BodyLine is one hunk body line. Payload excludes the prefix byte and retains its trailing LF; StripLFOld/StripLFNew record a following no-final-newline marker for the respective reconstructed side.

func (BodyLine) NewPayload

func (line BodyLine) NewPayload() []byte

NewPayload returns one body line's new-side reconstructed bytes.

func (BodyLine) OldPayload

func (line BodyLine) OldPayload() []byte

OldPayload returns one body line's old-side reconstructed bytes.

type Group

type Group struct {
	Kind    GroupKind
	OldPath *string
	NewPath *string
	Mode    string // bound tree mode for creates and deletes
	Hunks   []*Hunk
}

Group is one contiguous file group.

type GroupKind

type GroupKind int

GroupKind classifies one contiguous file group.

const (
	KindModify GroupKind = iota
	KindCreate
	KindDelete
	KindRename
)

type Hunk

type Hunk struct {
	OldPath       *string
	NewPath       *string
	DisplayPath   string
	OldRange      wire.Range
	NewRange      wire.Range
	Body          []BodyLine
	RawBody       []byte
	ContentSha256 string
	ID            string
}

Hunk is one parsed textual hunk.

type Patch

type Patch struct {
	Groups []*Group
	Hunks  []*Hunk // every hunk in patch order
}

Patch is a fully parsed CEM 0.1 conformant patch.

func Parse

func Parse(raw []byte) (*Patch, error)

Parse reads one bounded CEM 0.1 patch.

Jump to

Keyboard shortcuts

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