gitview

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: BSD-3-Clause Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

View Source
var ErrBadPath = errors.New("gitview: invalid path or ref")

ErrBadPath is a path or ref the rules above refuse.

View Source
var ErrNotFound = errors.New("gitview: not found")

ErrNotFound is every answer of "no such ref, path or object".

Functions

func CleanPath

func CleanPath(p string) (string, error)

CleanPath checks a path inside a tree. "" is the root; one trailing "/" is dropped.

func IsText

func IsText(b []byte) bool

IsText applies git's own test for a binary file (a NUL in the first 8000 bytes) and refuses what is not UTF-8, which a page could not show faithfully.

Types

type Commit

type Commit struct {
	ID, Author, Subject string
	Time                time.Time
}

Commit is one line of the log.

type Detail

type Detail struct {
	Commit
	Parents       []string
	Message       string
	Diff          string
	DiffTruncated bool
}

Detail is one commit with its message and its diff against its first parent.

type Entry

type Entry struct {
	Mode, Type, ID, Name string
	Size                 int64 // -1 for a directory or a submodule
}

Entry is one line of a directory.

func (Entry) IsDir

func (e Entry) IsDir() bool

IsDir reports whether the entry is a directory.

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

func (r *Repo) Blob(ctx context.Context, oid, p string, limit int) ([]byte, bool, error)

Blob returns at most limit bytes of the blob at p.

func (*Repo) BlobSize

func (r *Repo) BlobSize(ctx context.Context, oid, p string) (int64, error)

BlobSize is the size of the blob at p.

func (*Repo) Kind

func (r *Repo) Kind(ctx context.Context, oid, p string) (string, error)

Kind is "tree" or "blob" for the object at p in the commit oid.

func (*Repo) Log

func (r *Repo) Log(ctx context.Context, oid string, skip int) (cs []Commit, more bool, err error)

Log returns up to LogPage commits reachable from oid, skipping skip; more says there are older ones.

func (*Repo) Resolve

func (r *Repo) Resolve(ctx context.Context, ref string) (string, error)

Resolve turns a ref ("HEAD", a branch, a tag, or a full object id) into the id of a commit.

func (*Repo) Show

func (r *Repo) Show(ctx context.Context, oid string) (Detail, error)

Show returns the commit oid with a bounded diff. A merge shows no diff.

func (*Repo) Tree

func (r *Repo) Tree(ctx context.Context, oid, p string) (es []Entry, truncated bool, err error)

Tree lists the directory at p, directories first, then by name. At most MaxTreeEntries are returned; truncated says there were more.

Jump to

Keyboard shortcuts

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