servegit

package
v0.0.0-...-2835e8c Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

package servegit provides a smart Git HTTP transfer protocol handler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// Dir is a function which takes a repository name and returns an absolute
	// path to the GIT_DIR for it.
	Dir func(context.Context, string) (string, error)

	// ErrorHook is called if we fail to run the git command. The main use of
	// this is to inject logging. For example in src-cli we don't use
	// sourcegraph/log so this allows us to use stdlib log.
	//
	// Note: This is required to be set
	ErrorHook func(err error, stderr string)

	// CommandHook if non-nil will run with the git upload command before we
	// start the command.
	//
	// This allows the command to be modified before running. In practice
	// sourcegraph.com will add a flowrated writer for Stdout to treat our
	// internal networks more kindly.
	CommandHook func(*exec.Cmd)

	// Trace if non-nil is called at the start of serving a request. It will
	// call the returned function when done executing. If the executation
	// failed, it will pass in a non-nil error.
	Trace func(ctx context.Context, svc, repo, protocol string) func(error)

	// RootFS is a traversal safe API that ensures files outside of the
	// root cannot be opened.
	RootFS *os.Root
}

Handler is a smart Git HTTP transfer protocol as documented at https://www.git-scm.com/docs/http-protocol.

This allows users to clone any git repo. We only support the smart protocol. We aim to support modern git features such as protocol v2 to minimize traffic.

func (*Handler) ServeHTTP

func (s *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Repo

type Repo struct {
	Name      string
	URI       string
	ClonePath string
}

type Serve

type Serve struct {
	Addr   string
	Root   string
	RootFS *os.Root
	Info   *log.Logger
	Debug  *log.Logger
}

func (*Serve) Repos

func (s *Serve) Repos() ([]Repo, error)

Repos returns a slice of all the git repositories it finds.

func (*Serve) Start

func (s *Serve) Start() error

Jump to

Keyboard shortcuts

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