Documentation
¶
Index ¶
- Variables
- type CommitMeta
- type Conflict
- type PageMeta
- type RepoSummary
- type Store
- func (s *Store) ChangedSince(repoID, since string) ([]string, string, error)
- func (s *Store) Exists(repoID string) bool
- func (s *Store) HeadSHA(repoID string) (string, error)
- func (s *Store) HeadSHAForPath(repoID, filePath string) (string, error)
- func (s *Store) Init(repoID string) error
- func (s *Store) ListPages(repoID string) ([]PageMeta, error)
- func (s *Store) ListRepos() ([]string, error)
- func (s *Store) ListReposWithMeta() ([]RepoSummary, error)
- func (s *Store) Log(repoID string, limit int) ([]CommitMeta, error)
- func (s *Store) LogPath(repoID, filePath string, limit int) ([]CommitMeta, error)
- func (s *Store) Read(repoID, filePath string) ([]byte, string, error)
- func (s *Store) ReadAtSha(repoID, filePath, sha string) ([]byte, error)
- func (s *Store) ResolveParentSHAForPath(repoID, filePath, sha string) (string, error)
- func (s *Store) Write(repoID, filePath string, content []byte, ...) (string, *Conflict, error)
Constants ¶
This section is empty.
Variables ¶
var ErrConflict = errors.New("gitstore: parent_sha conflict")
ErrConflict is returned when a Write's parent_sha does not match the current sha of the last commit that touched the file.
var ErrPathNotAtSHA = errors.New("gitstore: path not present at sha")
ErrPathNotAtSHA is returned by ReadAtSha when the sha exists but the path does not exist in that commit's tree.
var ErrRepoNotFound = errors.New("gitstore: repo not initialized")
ErrRepoNotFound is returned for operations on an uninitialized repo.
var ErrUnknownSHA = errors.New("gitstore: unknown sha")
ErrUnknownSHA is returned by ReadAtSha when the given sha doesn't resolve.
var ErrUnsafePath = errors.New("gitstore: unsafe file path")
ErrUnsafePath is returned when a caller-supplied file path could escape the repo working tree or be parsed by git as an option (path traversal / git argument injection). Every public method that forwards a file path to git or the filesystem validates it with validatePagePath first.
Functions ¶
This section is empty.
Types ¶
type CommitMeta ¶
type CommitMeta struct {
SHA string `json:"sha"`
Author string `json:"author"`
Email string `json:"email"`
Time time.Time `json:"time"`
Message string `json:"message"`
}
CommitMeta describes a single commit returned by Log.
type Conflict ¶
type Conflict struct {
Path string `json:"path"`
CurrentSHA string `json:"current_sha"`
CurrentContent []byte `json:"current_content"`
ExpectedParentSHA string `json:"expected_parent_sha"`
AncestorContent []byte `json:"ancestor_content,omitempty"`
}
Conflict describes a non-fast-forward write attempt. AncestorContent is populated by callers (see handler.Push) when they can resolve the ExpectedParentSHA — the differ needs all three versions (yours, theirs, ancestor) for a useful merge brief.
type PageMeta ¶
type PageMeta struct {
Path string `json:"path"`
SHA string `json:"sha"`
Author string `json:"author"`
Email string `json:"email"`
Time time.Time `json:"time"`
Message string `json:"message"`
}
PageMeta describes a tracked file's last-touch metadata in a repo.
type RepoSummary ¶
type RepoSummary struct {
ID string `json:"id"`
PageCount int `json:"page_count"`
LastCommit *CommitMeta `json:"last_commit,omitempty"`
}
RepoSummary is the JSON shape returned for the repo list.
type Store ¶
type Store struct {
Root string
}
Store wraps a directory holding one git working repo per repo_id.
func (*Store) ChangedSince ¶
ChangedSince returns file paths changed since the given sha (or all files at HEAD when since is empty), plus the current HEAD sha.
func (*Store) HeadSHAForPath ¶
HeadSHAForPath returns the sha of the most recent commit that touched filePath, or "" if the file has no history in the repo.
func (*Store) ListPages ¶
ListPages returns metadata for every tracked file in a repo. One git process walks all commits newest → oldest; for each file the first time it appears is its last-touch commit.
func (*Store) ListReposWithMeta ¶
func (s *Store) ListReposWithMeta() ([]RepoSummary, error)
ListReposWithMeta returns repo summaries (page count + last commit).
func (*Store) Log ¶
func (s *Store) Log(repoID string, limit int) ([]CommitMeta, error)
Log returns up to limit recent commits across the whole repo.
func (*Store) LogPath ¶
func (s *Store) LogPath(repoID, filePath string, limit int) ([]CommitMeta, error)
LogPath returns up to limit commits that touched filePath.
func (*Store) Read ¶
Read returns the file content at HEAD and the sha of the last commit that touched the file. Returns os.ErrNotExist if the file doesn't exist.
func (*Store) ReadAtSha ¶
ReadAtSha returns the contents of filePath at the given commit sha. Returns ErrUnknownSHA if the sha doesn't resolve, or ErrPathNotAtSHA if the commit exists but doesn't contain the file.
func (*Store) ResolveParentSHAForPath ¶
ResolveParentSHAForPath returns the parent commit sha that touched filePath before `sha`. Returns "" with no error when there is no such parent (i.e. `sha` introduced the file). Returns ErrUnknownSHA if `sha` itself doesn't resolve.
func (*Store) Write ¶
func (s *Store) Write(repoID, filePath string, content []byte, authorName, authorEmail, message, parentSHA string) (string, *Conflict, error)
Write writes a file, commits it, and returns the new HEAD sha. If parentSHA is non-empty, it must match the latest commit sha that touched filePath; otherwise returns ErrConflict with a *Conflict describing the current state.