gitstore

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
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.

View Source
var ErrRepoNotFound = errors.New("gitstore: repo not initialized")

ErrRepoNotFound is returned for operations on an uninitialized repo.

View Source
var ErrUnknownSHA = errors.New("gitstore: unknown sha")

ErrUnknownSHA is returned by ReadAtSha when the given sha doesn't resolve.

View Source
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 Open

func Open(root string) (*Store, error)

Open returns a Store rooted at the given directory, creating it if missing.

func (*Store) ChangedSince

func (s *Store) ChangedSince(repoID, since string) ([]string, string, error)

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) Exists

func (s *Store) Exists(repoID string) bool

Exists reports whether a repo has been initialized.

func (*Store) HeadSHA

func (s *Store) HeadSHA(repoID string) (string, error)

HeadSHA returns the current HEAD sha, or empty if the repo has no commits.

func (*Store) HeadSHAForPath

func (s *Store) HeadSHAForPath(repoID, filePath string) (string, error)

HeadSHAForPath returns the sha of the most recent commit that touched filePath, or "" if the file has no history in the repo.

func (*Store) Init

func (s *Store) Init(repoID string) error

Init creates a new repo for repoID (idempotent).

func (*Store) ListPages

func (s *Store) ListPages(repoID string) ([]PageMeta, error)

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) ListRepos

func (s *Store) ListRepos() ([]string, error)

ListRepos returns every initialized repo ID under the store root, sorted.

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

func (s *Store) Read(repoID, filePath string) ([]byte, string, error)

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

func (s *Store) ReadAtSha(repoID, filePath, sha string) ([]byte, error)

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

func (s *Store) ResolveParentSHAForPath(repoID, filePath, sha string) (string, error)

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.

Jump to

Keyboard shortcuts

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