Documentation
¶
Overview ¶
Package backend defines the read-only repository contract that the gitview server is written against. Implementations exist for local git directories (backend/local) and the GitHub REST API (backend/ghapi).
Index ¶
Constants ¶
const MaxBlobBytes = 10 << 20
MaxBlobBytes caps what backends load into memory for display.
const TooLargeLines = 3000
TooLargeLines is the per-file changed-line count beyond which hunks are dropped and the UI shows a folded "load diff" box, like github.com.
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrUnsupported = errors.New("unsupported") )
Sentinel errors. Backends wrap these with %w and detail.
Functions ¶
This section is empty.
Types ¶
type Blob ¶
type Blob struct {
Path string
Size int64
Content []byte
Binary bool
LFS *LFSPointer
Symlink bool // Content is the link target path, not file data
TooBig bool
}
Blob is file content plus the metadata the viewer needs.
type CommitDetail ¶
type DiffStatus ¶
type DiffStatus string
DiffStatus matches git --name-status letters.
const ( Added DiffStatus = "A" Modified DiffStatus = "M" Deleted DiffStatus = "D" Renamed DiffStatus = "R" Copied DiffStatus = "C" )
type FileDiff ¶
type FileDiff struct {
OldPath string
NewPath string
Status DiffStatus
Additions int
Deletions int
Binary bool
TooLarge bool
Hunks []Hunk
}
func ParsePatch ¶
ParsePatch parses git unified diff output (git diff-tree -p / the patch strings in GitHub's commit API) into FileDiffs. It is forgiving: unknown header lines are skipped, truncated input yields what was parsed.
type Info ¶
type Info struct {
Owner string
Name string
Description string
DefaultBranch string
CloneURL string
Mirror bool
}
Info is repository identity.
type LFSPointer ¶
type RateLimitError ¶
RateLimitError reports an exhausted quota on a metered backend. The server matches it with errors.As; it lives here so the server never has to import a concrete backend.
func (*RateLimitError) Error ¶
func (e *RateLimitError) Error() string
type Repo ¶
type Repo interface {
// Info returns identity and defaults. Called once at startup and cached.
Info(ctx context.Context) (Info, error)
// Refs returns all branches and tags with their tip SHAs.
Refs(ctx context.Context) (Refs, error)
// Resolve turns a ref name or SHA prefix into a full commit SHA.
Resolve(ctx context.Context, ref string) (string, error)
// Tree lists the entries of the directory at path ("" = root) at rev,
// sorted GitHub-style: dirs first, then files, case-insensitive.
Tree(ctx context.Context, rev, path string) ([]TreeEntry, error)
// Blob returns file content and metadata at rev:path.
Blob(ctx context.Context, rev, path string) (Blob, error)
// Commits lists up to n commits reachable from rev, newest first,
// optionally limited to those touching path ("" = all), skipping skip.
// more reports whether older commits exist beyond the window.
Commits(ctx context.Context, rev, path string, n, skip int) (commits []Commit, more bool, err error)
// Commit returns one commit with its full diff against its first
// parent, or against the empty tree for a root commit.
Commit(ctx context.Context, sha string) (CommitDetail, error)
// LastCommit returns the most recent commit touching path at rev.
LastCommit(ctx context.Context, rev, path string) (Commit, error)
// Blame attributes every line of rev:path to a commit.
Blame(ctx context.Context, rev, path string) ([]BlameHunk, error)
// Files returns every file path at rev (recursive, sorted).
Files(ctx context.Context, rev string) ([]string, error)
// Archive streams a zip or tar.gz of the tree at rev. format is
// "zip" or "tar.gz"; prefix is the top-level directory inside the
// archive.
Archive(ctx context.Context, rev, format, prefix string, w io.Writer) error
}
Repo is a read-only view of one repository. Implementations must be safe for concurrent use.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ghapi implements backend.Repo over the GitHub REST API v3 with a hand-rolled net/http client.
|
Package ghapi implements backend.Repo over the GitHub REST API v3 with a hand-rolled net/http client. |
|
Package hf implements backend.Repo over the Hugging Face Hub HTTP API with a hand-rolled net/http client, the same shape as the ghapi backend: bearer auth, conditional requests (ETag), Link-header pagination, and rate-limit errors.
|
Package hf implements backend.Repo over the Hugging Face Hub HTTP API with a hand-rolled net/http client, the same shape as the ghapi backend: bearer auth, conditional requests (ETag), Link-header pagination, and rate-limit errors. |
|
Package local implements backend.Repo for a repository on disk by driving the git command line.
|
Package local implements backend.Repo for a repository on disk by driving the git command line. |