A vibe coded tangled fork which supports pijul.
1package vcs
2
3import (
4 "context"
5 "errors"
6 "io"
7
8 "tangled.org/core/knotserver/git"
9 "tangled.org/core/knotserver/pijul"
10)
11
12// ErrBinaryFile is returned by FileContentN when the file appears to be binary.
13// It matches both git.ErrBinaryFile and pijul.ErrBinaryFile.
14var ErrBinaryFile = errors.New("binary file")
15
16// IsBinaryFileError returns true if the error indicates a binary file,
17// matching against both the vcs, git, and pijul error types.
18func IsBinaryFileError(err error) bool {
19 return errors.Is(err, ErrBinaryFile) ||
20 errors.Is(err, git.ErrBinaryFile) ||
21 errors.Is(err, pijul.ErrBinaryFile)
22}
23
24// ReadRepo provides read-only access to a VCS repository, abstracting
25// over git and pijul.
26type ReadRepo interface {
27 // VCSType returns "git" or "pijul".
28 VCSType() string
29
30 // Path returns the on-disk path of the repository.
31 Path() string
32
33 // History returns history entries (commits/changes) with pagination.
34 History(offset, limit int) ([]HistoryEntry, error)
35
36 // TotalHistoryEntries returns the total count of commits/changes.
37 TotalHistoryEntries() (int, error)
38
39 // HistoryEntry returns a single commit/change by hash.
40 HistoryEntry(hash string) (*HistoryEntry, error)
41
42 // Branches returns branches/channels with optional pagination.
43 Branches(opts *PaginationOpts) ([]BranchInfo, error)
44
45 // DefaultBranch returns the name of the default branch/channel.
46 DefaultBranch() (string, error)
47
48 // FileTree returns the directory listing at the given path.
49 FileTree(ctx context.Context, path string) ([]TreeEntry, error)
50
51 // FileContentN reads up to cap bytes of a file, returning ErrBinaryFile
52 // if the file appears to be binary.
53 FileContentN(path string, cap int64) ([]byte, error)
54
55 // RawContent reads the full raw content of a file.
56 RawContent(path string) ([]byte, error)
57
58 // WriteTar writes a tar archive of the repository to w, prefixing
59 // all paths with prefix.
60 WriteTar(w io.Writer, prefix string) error
61
62 // Tags returns tags with optional pagination. Pijul repos return nil.
63 Tags(opts *PaginationOpts) ([]TagInfo, error)
64}
65
66// MutableRepo extends ReadRepo with write operations.
67type MutableRepo interface {
68 ReadRepo
69
70 // SetDefaultBranch sets the default branch/channel.
71 SetDefaultBranch(name string) error
72
73 // DeleteBranch deletes a branch/channel.
74 DeleteBranch(name string) error
75}