Documentation
¶
Index ¶
- Variables
- func ChapterPath(id int64) string
- func CoverPath() string
- func GoinkPath() string
- func OutlinePath(id int64) string
- func ParseVolumePath(path string) (int64, bool)
- func PlanPath(scope string) string
- func ReadFile(novelID int64, path string) (string, error)
- func RemoveFile(novelID int64, path string) error
- func ResolvePath(path string, novelID int64) (string, error)
- func SafePath(base, rel string) (string, error)
- func VolumePath(volumeID int64) string
- func WriteFile(novelID int64, path, content string) error
- func WriteFileAtPathIfUnchanged(fullPath, expected, content string) error
- func WriteFileIfUnchanged(novelID int64, path, expected, content string) error
- type ChapterPathRef
- type CommitInfo
- type FileDiff
- type FileEntry
- type Repo
- func (r *Repo) Commit(msg string) (string, error)
- func (r *Repo) CommitFileList(hash string) (*CommitInfo, []FileEntry, error)
- func (r *Repo) DiffContent(relPath, proposed string) (string, error)
- func (r *Repo) HasUncommitted() (bool, error)
- func (r *Repo) Log(relPath string, n int) ([]CommitInfo, error)
- func (r *Repo) LogDetailed(n int, afterHash string) ([]CommitInfo, error)
- func (r *Repo) RevertAbort() error
- func (r *Repo) RevertNoCommit(hashes []string) error
- func (r *Repo) SetGitConfig(gitName, gitEmail string) error
- func (r *Repo) ShowFile(hash, filePath string) (*FileDiff, error)
- func (r *Repo) StageAll() error
Constants ¶
This section is empty.
Variables ¶
var ErrFileChanged = errors.New("git: file changed since it was read")
var ErrPathEscape = errors.New("git: path escapes novel directory")
Functions ¶
func ParseVolumePath ¶ added in v1.6.0
ParseVolumePath 解析卷纲虚拟路径。卷 ID 必须是规范的正整数表示。
func RemoveFile ¶ added in v1.6.0
RemoveFile 删除小说仓库中的文件。文件不存在时视为已删除,便于清理可选的大纲文件。
func ResolvePath ¶
ResolvePath 将用户输入路径解析为真实文件系统路径。 ~/.goink/ 展开到用户目录;其他相对路径基于小说目录。
func VolumePath ¶ added in v1.6.0
VolumePath 返回卷纲文件相对路径(按卷 id)。
func WriteFileAtPathIfUnchanged ¶ added in v1.6.0
WriteFileAtPathIfUnchanged 供已验证绝对路径的调用方共用同一进程写锁。
func WriteFileIfUnchanged ¶ added in v1.6.0
WriteFileIfUnchanged 将比较与写入放在同一个进程锁内,避免应用内写入互相覆盖。
Types ¶
type ChapterPathRef ¶ added in v1.6.0
ChapterPathRef 是章节正文或章节大纲虚拟路径的解析结果。 VolumeID 仅来自两级容错路径,不参与物理文件定位;IsNew 表示 new.md 创建通道。
func ParseChapterLikePath ¶ added in v1.6.0
func ParseChapterLikePath(path string) (ChapterPathRef, bool)
ParseChapterLikePath 解析 rw_tools 支持的章节正文或大纲虚拟路径。 支持扁平主格式和带卷 ID 的容错别名;旧的纯数字章节号路径不被接受。
type CommitInfo ¶
type CommitInfo struct {
Hash string `json:"hash"`
ShortHash string `json:"shortHash"`
Message string `json:"message"`
Time time.Time `json:"time"`
AuthorName string `json:"authorName"`
AuthorEmail string `json:"authorEmail"`
FilesChanged int `json:"filesChanged"`
Insertions int `json:"insertions"`
Deletions int `json:"deletions"`
}
CommitInfo 是 git log 的单条记录。
type FileDiff ¶
type FileDiff struct {
Path string `json:"path"`
ChangeType string `json:"changeType"`
OriginalContent string `json:"original"`
ModifiedContent string `json:"modified"`
}
FileDiff 表示一次 commit 中单个文件的变更。
type FileEntry ¶
type FileEntry struct {
Path string `json:"path"`
ChangeType string `json:"changeType"` // "added" | "modified" | "deleted" | "renamed"
OldPath string `json:"oldPath"` // 仅 renamed 时有值,表示重命名前的路径
}
FileEntry 表示 commit 中一个变更文件的简要信息(不含内容)。
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
Repo 管理单部小说的 Git 仓库,提供文件读写和版本控制。
func New ¶
New 为指定小说打开已有仓库,不存在则 git init + 首次空 commit。 gitName 和 gitEmail 用于设置仓库级 git config。空字符串时使用默认值。 logger 为 nil 时使用 slog.Default()。
func (*Repo) CommitFileList ¶
func (r *Repo) CommitFileList(hash string) (*CommitInfo, []FileEntry, error)
CommitFileList 返回指定 commit 的详细信息和变更文件列表(不含文件内容)。
func (*Repo) DiffContent ¶
DiffContent 对比当前工作区文件与 proposed 内容,返回 unified diff。 文件不存在时以空内容为基准。用临时文件 + git diff --no-index 实现。
func (*Repo) HasUncommitted ¶
func (*Repo) LogDetailed ¶
func (r *Repo) LogDetailed(n int, afterHash string) ([]CommitInfo, error)
LogDetailed 返回带详细统计的提交历史,按时间降序(最新在前)。 afterHash 非空时,返回该 commit 之后的更早提交(基于 git log <afterHash> --skip=1)。
func (*Repo) RevertAbort ¶
RevertAbort 取消进行中的 revert,丢弃所有暂存的 revert 内容。
func (*Repo) RevertNoCommit ¶
RevertNoCommit 逆序 revert 所有 hash,仅暂存不提交。冲突时自动 abort。 调用方负责最终 commit(或 abort)。
func (*Repo) SetGitConfig ¶
SetGitConfig 在已有仓库上更新仓库级 user.name / user.email 配置。