gitrepo

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: 10 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 gitrepo maps a repository name received from a git client to a bare repository on disk, decides who may read it, and bounds how many fetches run at once. SSH and smart HTTP both go through it, so they refuse the same names and apply the same rule.

Repositories live at <root>/<owner>/<name>.git. Until milestone 4 (push) they are created outside the forge with `git init --bare`. There is no ACL yet: an account reads its own repositories, and anyone reads one that holds the file git-daemon-export-ok (git's own "public" marker, honoured by git daemon and http-backend).

Index

Constants

View Source
const (
	DefaultTotalSessions   = 64
	DefaultSessionsPerKey  = 4
	DefaultRequestDuration = 15 * time.Minute
)

Defaults for the caps and the time one request may take.

View Source
const PublicMarker = "git-daemon-export-ok"

PublicMarker is the file whose presence in a repository makes it public.

Variables

View Source
var ErrBusy = errors.New("too many concurrent git sessions")

ErrBusy is returned when a concurrency cap is reached.

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

ErrNotFound is returned for a repository that does not exist and for one the caller may not read: the two are indistinguishable on purpose, so a name cannot be probed.

View Source
var ErrPath = errors.New("invalid repository path")

ErrPath is returned for a path that is not owner/name.

Functions

func WithTimeout

WithTimeout derives the context a request runs under.

Types

type Limiter

type Limiter struct {
	Total, PerKey int
	// contains filtered or unexported fields
}

Limiter caps concurrent sessions in total and per key (an account, or a remote host). A session over a cap is refused at once, not queued: waiting would let idle sessions hold everyone else out.

func (*Limiter) Acquire

func (l *Limiter) Acquire(key string) (release func(), err error)

Acquire takes a slot for key. The returned function gives it back and may be called more than once.

type Name

type Name struct{ Owner, Repo string }

Name identifies a repository.

func ParsePath

func ParsePath(p string) (Name, error)

ParsePath reads "owner/name", "owner/name.git" or either with one leading "/". Anything else is refused: no ".." and no other separator, no empty segment, no byte outside printable ASCII, and only the lowercase letters, digits, ".", "_" and "-" that logins and names are made of.

func (Name) String

func (n Name) String() string

type Service

type Service struct {
	// Root is the directory holding <owner>/<name>.git.
	Root string
	// Git is the git executable ("" for the one on PATH).
	Git string
	// Limits bound one protocol request (zero fields mean gitproto's defaults).
	Limits gitproto.Limits
	// PackThreads is passed to pack-objects (0: git's default).
	PackThreads int
	// Agent is advertised to clients ("" for gitproto's).
	Agent string
	// Collaborator, if set, tells whether login is a collaborator of n: a
	// collaborator reads a private repository like its owner does.
	Collaborator func(n Name, login string) bool
}

Service opens repositories under Root.

func (*Service) Dir

func (s *Service) Dir(n Name, login string) (string, error)

Dir returns the directory of the bare repository n if login may read it, with the rule of Open (the web pages and the protocols read the same repositories).

func (*Service) Open

func (s *Service) Open(n Name, login string) (*gitproto.Server, error)

Open returns the protocol server for n, for the account login ("" for an anonymous reader). A missing repository, one that is not a plain directory inside Root, and one login may not read all return ErrNotFound.

func (*Service) Validate

func (s *Service) Validate() error

Validate refuses a service that cannot work.

Jump to

Keyboard shortcuts

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