package vcs import ( "context" "errors" "io" "tangled.org/core/knotserver/git" "tangled.org/core/knotserver/pijul" ) // ErrBinaryFile is returned by FileContentN when the file appears to be binary. // It matches both git.ErrBinaryFile and pijul.ErrBinaryFile. var ErrBinaryFile = errors.New("binary file") // IsBinaryFileError returns true if the error indicates a binary file, // matching against both the vcs, git, and pijul error types. func IsBinaryFileError(err error) bool { return errors.Is(err, ErrBinaryFile) || errors.Is(err, git.ErrBinaryFile) || errors.Is(err, pijul.ErrBinaryFile) } // ReadRepo provides read-only access to a VCS repository, abstracting // over git and pijul. type ReadRepo interface { // VCSType returns "git" or "pijul". VCSType() string // Path returns the on-disk path of the repository. Path() string // History returns history entries (commits/changes) with pagination. History(offset, limit int) ([]HistoryEntry, error) // TotalHistoryEntries returns the total count of commits/changes. TotalHistoryEntries() (int, error) // HistoryEntry returns a single commit/change by hash. HistoryEntry(hash string) (*HistoryEntry, error) // Branches returns branches/channels with optional pagination. Branches(opts *PaginationOpts) ([]BranchInfo, error) // DefaultBranch returns the name of the default branch/channel. DefaultBranch() (string, error) // FileTree returns the directory listing at the given path. FileTree(ctx context.Context, path string) ([]TreeEntry, error) // FileContentN reads up to cap bytes of a file, returning ErrBinaryFile // if the file appears to be binary. FileContentN(path string, cap int64) ([]byte, error) // RawContent reads the full raw content of a file. RawContent(path string) ([]byte, error) // WriteTar writes a tar archive of the repository to w, prefixing // all paths with prefix. WriteTar(w io.Writer, prefix string) error // Tags returns tags with optional pagination. Pijul repos return nil. Tags(opts *PaginationOpts) ([]TagInfo, error) } // MutableRepo extends ReadRepo with write operations. type MutableRepo interface { ReadRepo // SetDefaultBranch sets the default branch/channel. SetDefaultBranch(name string) error // DeleteBranch deletes a branch/channel. DeleteBranch(name string) error }