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 ¶
- func HasOwners(dir string) bool
- func IsTemp(name string) bool
- func LastUsed(dir string) time.Time
- func RecordOwners(dir string, paths []string) error
- func Temp(path string) string
- func Workspaces(dir string) []string
- func WriteAtomic(path string, data []byte) error
- type Paths
- type Pools
- func (pools *Pools) Address(repository repo.Repo) string
- func (pools *Pools) All() []string
- func (pools *Pools) Base(repository repo.Repo, path string) (string, bool)
- func (pools *Pools) Blob(ctx context.Context, repository repo.Repo, object string) (string, error)
- func (pools *Pools) Bring(ctx context.Context, repository repo.Repo, source string) (string, func(), error)
- func (pools *Pools) ChangedBetween(ctx context.Context, repository repo.Repo, from, to string) ([]string, error)
- func (pools *Pools) DefaultBranch(ctx context.Context, repository repo.Repo) string
- func (pools *Pools) Disown(ctx context.Context, repository repo.Repo, path string) error
- func (pools *Pools) Forget(ctx context.Context, repository repo.Repo, path string) error
- func (pools *Pools) ForgetBase(ctx context.Context, repository repo.Repo, path string) error
- func (pools *Pools) Has(ctx context.Context, repository repo.Repo, revision string) (string, bool, error)
- func (pools *Pools) Holds(ctx context.Context, repository repo.Repo, branch string) (bool, error)
- func (pools *Pools) Lends(repository repo.Repo, path string) bool
- func (pools *Pools) Lock(ctx context.Context, repository repo.Repo) (func(), error)
- func (pools *Pools) MergeConflicts(ctx context.Context, repository repo.Repo, first, second string) ([]string, error)
- func (pools *Pools) ObjectFormat(ctx context.Context, repository repo.Repo) (string, error)
- func (pools *Pools) Own(ctx context.Context, repository repo.Repo, path string) error
- func (pools *Pools) OwnedCount() int
- func (pools *Pools) Owns(repository repo.Repo, path string) bool
- func (pools *Pools) Path(repository repo.Repo) string
- func (pools *Pools) Probe(ctx context.Context, request *gitdv1.ProbeRequest) *gitdv1.ProbeResponse
- func (pools *Pools) Push(ctx context.Context, repository repo.Repo, branch string, ...) error
- func (pools *Pools) Seed(ctx context.Context, repository repo.Repo, clone string, ...) error
- func (pools *Pools) SetBase(ctx context.Context, repository repo.Repo, path, commit string) error
- func (pools *Pools) Shallow(repository repo.Repo) string
- func (pools *Pools) Stage(ctx context.Context, repository repo.Repo, source, branch string) (string, []string, error)
- func (pools *Pools) StageRef(ctx context.Context, repository repo.Repo, source, ref, branch string) (string, []string, error)
- func (pools *Pools) Submodules(ctx context.Context, repository repo.Repo, commit string) ([]string, error)
- func (pools *Pools) Summarize(ctx context.Context, repository repo.Repo, branch string) (Summary, error)
- func (pools *Pools) Sync(ctx context.Context, repository repo.Repo, given []credentials.Credential, ...) error
- func (pools *Pools) Touched(ctx context.Context, repository repo.Repo, branch string, which Paths) ([]string, error)
- func (pools *Pools) TreeEntries(ctx context.Context, repository repo.Repo, commit string, paths []string) (map[string]TreeEntry, error)
- func (pools *Pools) Unstage(ctx context.Context, repository repo.Repo, branch string)
- func (pools *Pools) Use(ctx context.Context, repository repo.Repo, path string) error
- type Summary
- type TreeEntry
- type Want
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasOwners ¶
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 RecordOwners ¶
RecordOwners writes the list of own workspaces of the pool at dir.
func Temp ¶
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 ¶
Workspaces are the paths noted as borrowing from the pool at dir.
func WriteAtomic ¶
WriteAtomic writes a file so that it is either the old one or the new one, never half.
Types ¶
type Paths ¶
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) All ¶
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) 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 ¶
DefaultBranch is the branch the pool's HEAD points at, as the repository named it when the pool was created.
func (*Pools) Disown ¶
Disown notes that the workspace at path is no longer one of the repository's own.
func (*Pools) Forget ¶
Forget notes that the workspace at path no longer borrows from the pool of a repository.
func (*Pools) ForgetBase ¶
ForgetBase drops what was noted of the workspace at path.
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 ¶
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 ¶
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) 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) ObjectFormat ¶
ObjectFormat is the hash a repository names its objects with: sha1 or sha256.
func (*Pools) OwnedCount ¶
OwnedCount is how many workspaces the pools under Dir own that are still on disk.
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) 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) Shallow ¶
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 ¶
Unstage forgets what Stage staged for branch, once the publish is refused or fails: what it held is no one else's to see.
type Summary ¶
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 Want ¶
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 OnlyBranch ¶
OnlyBranch is the tip of one branch, or of the default one when branch is empty.
func OnlyCommit ¶
OnlyCommit is one commit and what it points at.