Documentation
¶
Overview ¶
Package gitview reads a bare repository for the web pages: a commit's tree, a blob, the log, one commit's diff. It runs the git program, read-only, and keeps every answer bounded.
Rules it keeps, each with a test:
- a path from a URL is cleaned before git sees it: no empty, "." or ".." segment, no control character, no backslash, valid UTF-8, bounded in length and depth;
- a ref is a short name or an object id from a fixed alphabet, resolved to a commit id first; every later command takes that id, so no argument that comes from a user can start with "-";
- the output of a command is read through a limit and the process is killed when it is reached, and every command has a deadline;
- git runs with no user or system configuration and no terminal.
Index ¶
- Constants
- Variables
- func CleanPath(p string) (string, error)
- func IsText(b []byte) bool
- type Commit
- type Detail
- type Entry
- type Repo
- func (r *Repo) Blob(ctx context.Context, oid, p string, limit int) ([]byte, bool, error)
- func (r *Repo) BlobSize(ctx context.Context, oid, p string) (int64, error)
- func (r *Repo) Kind(ctx context.Context, oid, p string) (string, error)
- func (r *Repo) Log(ctx context.Context, oid string, skip int) (cs []Commit, more bool, err error)
- func (r *Repo) Resolve(ctx context.Context, ref string) (string, error)
- func (r *Repo) Show(ctx context.Context, oid string) (Detail, error)
- func (r *Repo) Tree(ctx context.Context, oid, p string) (es []Entry, truncated bool, err error)
Constants ¶
const ( MaxTreeEntries = 5000 MaxBlobView = 256 << 10 // a blob shown in a page MaxRaw = 4 << 20 // a blob served raw MaxDiff = 256 << 10 MaxMessage = 64 << 10 LogPage = 50 MaxSkip = 10000 MaxPathLen = 1024 MaxDepth = 64 DefaultTimeout = 10 * time.Second )
Bounds. A page never holds more than these, whatever the repository holds.
Variables ¶
var ErrBadPath = errors.New("gitview: invalid path or ref")
ErrBadPath is a path or ref the rules above refuse.
var ErrNotFound = errors.New("gitview: not found")
ErrNotFound is every answer of "no such ref, path or object".
Functions ¶
Types ¶
type Repo ¶
type Repo struct {
Dir string
// Git is the git executable ("" for the one on PATH).
Git string
// Timeout bounds one command (0: DefaultTimeout).
Timeout time.Duration
}
Repo is one bare repository.
func (*Repo) Log ¶
Log returns up to LogPage commits reachable from oid, skipping skip; more says there are older ones.
func (*Repo) Resolve ¶
Resolve turns a ref ("HEAD", a branch, a tag, or a full object id) into the id of a commit.