Documentation
¶
Overview ¶
Package diff 提供文件补丁解析与应用能力(从 opencode internal/diff 迁移)。
与 opencode 版本的差异:去掉 chroma / lipgloss / tui/theme 等终端渲染依赖, 只保留工具真正需要的部分——生成 unified diff、解析 patch 文本、构建并应用 commit。
Index ¶
- func ApplyCommit(commit Commit, writeFn func(string, string) error, removeFn func(string) error) error
- func GenerateDiff(beforeContent, afterContent, fileName string) (string, int, int)
- func IdentifyFilesAdded(text string) []string
- func IdentifyFilesNeeded(text string) []string
- func LoadFiles(paths []string, openFn func(string) (string, error)) (map[string]string, error)
- func OpenFile(p string) (string, error)
- func ProcessPatch(text string, openFn func(string) (string, error), ...) (string, error)
- func RemoveFile(p string) error
- func ValidatePatch(patchText string, files map[string]string) (bool, string, error)
- func WriteFile(p string, content string) error
- type ActionType
- type Chunk
- type Commit
- type DiffError
- type FileChange
- type Parser
- type Patch
- type PatchAction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyCommit ¶
func GenerateDiff ¶
GenerateDiff 生成 before → after 的 unified diff,并返回新增 / 删除行数。
fileName 仅用于 diff 头(a/<name> b/<name>);相对路径会去掉工作目录前缀。
func IdentifyFilesAdded ¶
func IdentifyFilesNeeded ¶
func ProcessPatch ¶
func RemoveFile ¶
func ValidatePatch ¶
Types ¶
type ActionType ¶
type ActionType string
const ( ActionAdd ActionType = "add" ActionDelete ActionType = "delete" ActionUpdate ActionType = "update" )
type FileChange ¶
type FileChange struct {
Type ActionType
OldContent *string
NewContent *string
MovePath *string
}
type Patch ¶
type Patch struct {
Actions map[string]PatchAction
}
type PatchAction ¶
type PatchAction struct {
Type ActionType
NewFile *string
Chunks []Chunk
MovePath *string
}
Click to show internal directories.
Click to hide internal directories.