patch

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2025 License: Apache-2.0 Imports: 21 Imported by: 1

Documentation

Index

Constants

View Source
const Name = "system/patch"

Name of the system/patch action service.

Variables

View Source
var ErrNoChange = errors.New("no change between old and new")

Functions

This section is empty.

Types

type Action

type Action string
const (
	Delete Action = "delete"
	Move   Action = "move"
	Update Action = "update"
	Add    Action = "add"
)

type AddFile added in v0.1.19

type AddFile struct {
	Path     string
	Contents string
}

AddFile operation (*** Add File: path).

type ApplyInput

type ApplyInput struct {
	// The service applies the patch relative to the current working directory of the Fluxor runtime.
	Patch string `json:"patch" description:"Patch text to apply (either unified-diff format or simplified patch format)"`
	// Directory is the base directory for resolving relative paths in the patch.
	// If not provided, paths are resolved relative to the current working directory.
	Directory string `json:"directory" description:"Base directory for resolving relative paths in the patch"`
}

ApplyInput is the payload for Service.apply

type ApplyOutput

type ApplyOutput struct {
	Stats  DiffStats `json:"stats,omitempty"`
	Status string    `json:"status,omitempty"`
	Error  string    `json:"error,omitempty"`
}

ApplyOutput summarises the changes applied.

type DeleteFile added in v0.1.19

type DeleteFile struct{ Path string }

DeleteFile operation (*** Delete File: path).

type DiffInput

type DiffInput struct {
	OldContent   string `json:"old" description:"Original file content"`
	NewContent   string `json:"new" description:"Updated file content"`
	Path         string `json:"path,omitempty" description:"Display path for diff headers"`
	ContextLines int    `json:"contextLines,omitempty" description:"Number of context lines to include in diff (default 3)"`
}

DiffInput is the payload for Service.diff

type DiffOutput

type DiffOutput DiffResult

DiffOutput is identical to DiffResult, re-exported for JSON tags.

type DiffResult

type DiffResult struct {
	Patch string
	Stats DiffStats
}

type DiffStats

type DiffStats struct {
	Added   int // number of lines starting with '+' (excluding +++)
	Removed int // number of lines starting with '-' (excluding ---)
}

DiffStats captures basic statistics about a unified-diff output.

func GenerateDiff

func GenerateDiff(oldContent, newContent []byte, filePath string, contextLines int) (string, DiffStats, error)

GenerateDiff produces a GNU unified diff between old and new file contents. It returns the diff string along with insertion/deletion statistics. If the two inputs are identical, an empty diff string is returned.

type EmptyInput

type EmptyInput struct{}

EmptyInput/Output used by commit/rollback methods.

type EmptyOutput

type EmptyOutput struct{}

type Hunk added in v0.1.19

type Hunk interface {
	// contains filtered or unexported methods
}

Hunk represents any high-level patch operation.

func Parse added in v0.1.19

func Parse(patchText string) ([]Hunk, error)

Parse parses patchText and returns a slice of hunks.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service exposes filesystem patching capabilities as a Fluxor action service. It is stateless – every method call operates with its own ephemeral Session.

func New

func New() *Service

New creates the patch service instance.

func (*Service) Method

func (s *Service) Method(name string) (types.Executable, error)

Method maps method names to executable handlers.

func (*Service) Methods

func (s *Service) Methods() types.Signatures

Methods returns service method catalogue.

func (*Service) Name

func (s *Service) Name() string

Name returns service identifier.

type Session

type Session struct {
	ID string
	// contains filtered or unexported fields
}

func NewSession

func NewSession() (*Session, error)

func (*Session) Add

func (s *Session) Add(ctx context.Context, path string, data []byte) error

func (*Session) ApplyPatch

func (s *Session) ApplyPatch(ctx context.Context, patchText string, directory ...string) error

func (*Session) Commit

func (s *Session) Commit(ctx ...context.Context) error

func (*Session) Delete

func (s *Session) Delete(ctx context.Context, path string) error

func (*Session) Move

func (s *Session) Move(ctx context.Context, src, dst string) error

func (*Session) Rollback

func (s *Session) Rollback(ctx ...context.Context) error

func (*Session) Update

func (s *Session) Update(ctx context.Context, path string, newData []byte) error

type UpdateChunk added in v0.1.19

type UpdateChunk struct {
	ChangeContext string   // optional text after @@
	OldLines      []string // '-' and ' ' lines (without prefix)
	NewLines      []string // '+' and ' ' lines (without prefix)
	IsEOF         bool     // true when *** End of File terminator is present
}

UpdateChunk represents a contiguous diff chunk inside an UpdateFile hunk.

type UpdateFile added in v0.1.19

type UpdateFile struct {
	Path     string
	MovePath string
	Chunks   []UpdateChunk
}

UpdateFile operation (*** Update File: path).

Jump to

Keyboard shortcuts

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