pool

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 20 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 pool keeps one bare copy of each repository on this server, and is the only thing that reaches the network for it.

Every workspace of a repository borrows its objects from the pool through `objects/info/alternates`, so nothing may ever be deleted from a pool: a rollback to a commit that the host lost to a force push still needs it. That is why a pool is fetched without pruning and git's own gc is switched off in it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasOwners

func HasOwners(dir string) bool

HasOwners says whether the pool at dir keeps its list of own workspaces yet: a pool made before gitd kept one has none, until RecordOwners writes it.

func IsTemp

func IsTemp(name string) bool

IsTemp is whether a name is one Temp gave.

func LastUsed

func LastUsed(dir string) time.Time

LastUsed is when the pool at dir was last synced or borrowed from.

func RecordOwners

func RecordOwners(dir string, paths []string) error

RecordOwners writes the list of own workspaces of the pool at dir.

func Temp

func Temp(path string) string

Temp is a fresh temporary name next to path.

Everything gitd builds is built under such a name and moved into place when it is complete. Whatever still carries one after a crash is half built, and the next start removes it.

func Workspaces

func Workspaces(dir string) []string

Workspaces are the paths noted as borrowing from the pool at dir.

func WriteAtomic

func WriteAtomic(path string, data []byte) error

WriteAtomic writes a file so that it is either the old one or the new one, never half.

Types

type Paths

type Paths struct {
	Among   []string
	Except  []string
	Deleted bool
}

Paths is which paths Touched lists: those among Among, git's glob pathspecs (every path when empty), but none among Except, and only those deleted when Deleted.

type Pools

type Pools struct {
	Dir string
	// contains filtered or unexported fields
}

Pools are the pools under Dir. Fetches bounds how many reach the network at once, a git `.lock` older than staleLock is taken as left behind, and a pool synced moments ago is not synced again.

func New

func New(
	dir string,
	runner *git.Runner,
	keys *credentials.Keys,
	locks *lock.Locks,
	fetches *lock.Queue,
	staleLock time.Duration,
) *Pools

New returns the pools under dir.

func (*Pools) Address

func (pools *Pools) Address(repository repo.Repo) string

Address is where a repository is read over HTTPS, on its host's port.

func (*Pools) All

func (pools *Pools) All() []string

All are the directories of every pool, found on disk: `<host>/<path>.git`, however many groups the path has. Nothing below a pool is looked into, nor anything half built, and symbolic links are not followed: a pool is a directory under the pools directory.

func (*Pools) Base

func (pools *Pools) Base(repository repo.Repo, path string) (string, bool)

Base is the commit gitd last put the workspace at path on, if it noted one.

func (*Pools) Blob

func (pools *Pools) Blob(ctx context.Context, repository repo.Repo, object string) (string, error)

Blob is the content of an object of a repository.

func (*Pools) Bring

func (pools *Pools) Bring(ctx context.Context, repository repo.Repo, source string) (string, func(), error)

Bring fetches the commit a git directory on this disk is on into the pool, under a ref of its own, and answers it with what forgets the ref again: for reading a workspace's committed work in the pool, as Conflicts does, without staging it for a publish.

func (*Pools) ChangedBetween

func (pools *Pools) ChangedBetween(ctx context.Context, repository repo.Repo, from, to string) ([]string, error)

ChangedBetween lists the paths that differ between two commits of a repository.

func (*Pools) DefaultBranch

func (pools *Pools) DefaultBranch(ctx context.Context, repository repo.Repo) string

DefaultBranch is the branch the pool's HEAD points at, as the repository named it when the pool was created.

func (*Pools) Disown

func (pools *Pools) Disown(ctx context.Context, repository repo.Repo, path string) error

Disown notes that the workspace at path is no longer one of the repository's own.

func (*Pools) Forget

func (pools *Pools) Forget(ctx context.Context, repository repo.Repo, path string) error

Forget notes that the workspace at path no longer borrows from the pool of a repository.

func (*Pools) ForgetBase

func (pools *Pools) ForgetBase(ctx context.Context, repository repo.Repo, path string) error

ForgetBase drops what was noted of the workspace at path.

func (*Pools) ForgetPublished added in v0.15.0

func (pools *Pools) ForgetPublished(ctx context.Context, repository repo.Repo, path string) error

ForgetPublished forgets what the workspace at path published, as it goes.

func (*Pools) Has

func (pools *Pools) Has(ctx context.Context, repository repo.Repo, revision string) (string, bool, error)

Has returns the commit a revision names in the pool of a repository, if it is there.

func (*Pools) Holds

func (pools *Pools) Holds(ctx context.Context, repository repo.Repo, branch string) (bool, error)

Holds says whether the branch gitd published holds what Stage staged for it, and that holds commits beyond the repository's branches: a publish bringing nothing new to a branch an earlier one made, whose pull requests may still be missing.

func (*Pools) Lends

func (pools *Pools) Lends(repository repo.Repo, path string) bool

Lends says whether the pool of a repository lists the workspace at path among those that borrow from it: what gitd wrote when it checked that repository out there.

func (*Pools) Lock

func (pools *Pools) Lock(ctx context.Context, repository repo.Repo) (func(), error)

Lock holds the pool of a repository for one write.

func (*Pools) MergeConflicts

func (pools *Pools) MergeConflicts(ctx context.Context, repository repo.Repo, first, second string) ([]string, error)

MergeConflicts says on which files merging two commits of a repository conflicts, none when they merge cleanly, as git merge-tree says without a working tree.

func (*Pools) NotePublished added in v0.15.0

func (pools *Pools) NotePublished(ctx context.Context, repository repo.Repo, path, branch string) error

NotePublished notes that the workspace at path published branch.

func (*Pools) ObjectFormat

func (pools *Pools) ObjectFormat(ctx context.Context, repository repo.Repo) (string, error)

ObjectFormat is the hash a repository names its objects with: sha1 or sha256.

func (*Pools) Own

func (pools *Pools) Own(ctx context.Context, repository repo.Repo, path string) error

Own notes that the workspace at path is one of the repository's own.

func (*Pools) Owned added in v0.15.0

func (pools *Pools) Owned() []string

Owned is every workspace the pools under Dir own that is still on disk, once each.

func (*Pools) OwnedCount

func (pools *Pools) OwnedCount() int

OwnedCount is how many workspaces the pools under Dir own that are still on disk.

func (*Pools) Owns

func (pools *Pools) Owns(repository repo.Repo, path string) bool

Owns says whether the workspace at path is one of the repository's own.

func (*Pools) Path

func (pools *Pools) Path(repository repo.Repo) string

Path is where the pool of a repository is, whether it exists or not.

func (*Pools) Probe

func (pools *Pools) Probe(ctx context.Context, request *gitdv1.ProbeRequest) *gitdv1.ProbeResponse

Probe asks a repository whether it can be read with the credential that opens it, or with nothing when none was given. The same answer lists its branches, so nobody has to type one from memory.

func (*Pools) Published added in v0.15.0

func (pools *Pools) Published(repository repo.Repo, path string) []string

Published is the branches the workspace at path published, as noted.

func (*Pools) Push

func (pools *Pools) Push(
	ctx context.Context, repository repo.Repo, branch string, given []credentials.Credential, forward bool,
) error

Push sends what Stage staged for branch to a new branch of the repository, and remembers it as published. Forward lets the branch exist already and moves it, only ever forward.

Only a token publishes: a deploy key is read only, and reading with nothing writes nothing. The push is never forced: a branch that already exists is refused rather than overwritten, and one moved forward keeps every commit it had.

func (*Pools) Seed

func (pools *Pools) Seed(ctx context.Context, repository repo.Repo, clone string, report progress.Report) error

Seed creates the pool of a repository from a clone already on this disk, without the network, when there is no pool yet: the branches the clone last saw on origin, and the commit it is on. A shallow clone seeds a shallow pool.

func (*Pools) SetBase

func (pools *Pools) SetBase(ctx context.Context, repository repo.Repo, path, commit string) error

SetBase notes the commit gitd put the workspace at path on.

func (*Pools) Shallow

func (pools *Pools) Shallow(repository repo.Repo) string

Shallow is the path of the file that says where the pool's history stops, or "" when it holds the whole of it. A workspace borrowing from a shallow pool needs the same file.

func (*Pools) Stage

func (pools *Pools) Stage(ctx context.Context, repository repo.Repo, source, branch string) (string, []string, error)

Stage brings the commit a git directory on this disk is on into the pool, ready to be pushed to branch, and returns it with the subjects of the commits it brings: those no branch of the repository has, nor any commit gitd fetched or already published for it. Publishing twice does not publish the same commits twice.

Pushing is done from the pool afterwards. The token is used there, where the configuration is gitd's, and never in the workspace, which others may write: an `http.proxy` or an `insteadOf` left there must not get to see where the token goes.

func (*Pools) StageRef

func (pools *Pools) StageRef(ctx context.Context, repository repo.Repo, source, ref, branch string) (string, []string, error)

StageRef is Stage of the commit ref names in the git directory source rather than the one it is on: a branch a sandbox pushed to its sandbox repository.

func (*Pools) Submodules

func (pools *Pools) Submodules(ctx context.Context, repository repo.Repo, commit string) ([]string, error)

Submodules are the paths a commit's .gitmodules names, read in the pool.

func (*Pools) Summarize

func (pools *Pools) Summarize(ctx context.Context, repository repo.Repo, branch string) (Summary, error)

Summarize is what the commits staged for branch bring beyond the repository's branches, those gitd published to that branch before included: what a pull request from it is about, the same before the push and after. Files and lines are counted commit by commit as Touched reads them: a merge counts only what it brings itself, a binary file no lines.

func (*Pools) Sync

func (pools *Pools) Sync(
	ctx context.Context, repository repo.Repo, given []credentials.Credential, want Want, report progress.Report,
) error

Sync brings what is wanted of a repository into its pool, creating the pool if it is not there.

It is read with the one credential that opens it, or with nothing: which credential that is was decided by whoever asked, so a refusal is the answer and not a reason to try another.

What was brought in moments ago is taken as current: an environment with ten submodules of one repository, or two environments created together, would otherwise ask the network the same question over and over.

func (*Pools) Touched

func (pools *Pools) Touched(ctx context.Context, repository repo.Repo, branch string, which Paths) ([]string, error)

Touched lists the paths the commits staged for branch change, as which says.

Each commit is read on its own, so a change undone by a later commit is still listed: that history would be pushed too. A rename is a deletion and an addition. A merge lists only what it brings itself, beyond merging its parents as git would: merging a branch people changed lists nothing, and a change hidden inside a merge is listed.

func (*Pools) TreeEntries

func (pools *Pools) TreeEntries(ctx context.Context, repository repo.Repo, commit string, paths []string) (map[string]TreeEntry, error)

TreeEntries are the files of a commit at or under the given paths, by path.

func (*Pools) Unstage

func (pools *Pools) Unstage(ctx context.Context, repository repo.Repo, branch string)

Unstage forgets what Stage staged for branch, once the publish is refused or fails: what it held is no one else's to see.

func (*Pools) Use

func (pools *Pools) Use(ctx context.Context, repository repo.Repo, path string) error

Use notes that the workspace at path borrows from the pool of a repository.

Each pool keeps the paths of the workspaces that borrow from it, and the time of that file is when the pool was last used. Both are what keeps a pool from being retired while something still needs it.

type Summary

type Summary struct {
	Subjects []string
	Files    int
	Added    int
	Removed  int
}

Summary is what a branch brings: the subjects of its commits, newest first, how many files they change and how many lines they add and remove.

type TreeEntry

type TreeEntry struct {
	Mode   string
	Object string
}

TreeEntry is a file of a commit: its mode and its object.

type Want

type Want struct {
	Full     bool
	Branches []string
	Commits  []string
	// Since, when set, brings the branches' history back to this time, as git's
	// --shallow-since reads it, instead of their tips only: what a merge needs to find the
	// commit two branches share, without the whole history.
	Since string
}

Want is what a sync must bring into a pool: the repository's whole history, or only some branch tips and some commits, each without the history behind it. A want with neither branches nor commits is the repository's default branch.

Only what is checked out, by default: a large repository as a submodule is its pinned commit, a few hundred megabytes, and not its history, which may be several gigabytes. A workspace that wants `git log` and `git blame` to go back as far as in a clone asks for the whole history.

func BranchSince added in v0.15.1

func BranchSince(branch, since string) Want

BranchSince is one branch with its history back to since.

func Everything

func Everything() Want

Everything is the whole history of every branch.

func OnlyBranch

func OnlyBranch(branch string) Want

OnlyBranch is the tip of one branch, or of the default one when branch is empty.

func OnlyCommit

func OnlyCommit(commit string) Want

OnlyCommit is one commit and what it points at.

Jump to

Keyboard shortcuts

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