Documentation
¶
Overview ¶
Package workspace checks repositories out where their users need them.
A workspace is an ordinary clone whose objects live in its repository's pool, through `objects/info/alternates`: it takes little disk and seconds to make. Its `origin` is the repository's real address, so whoever runs git in it sees what a clone shows, but it never reaches the network itself: the pool is synced, and the workspace then fetches from the pool.
A workspace is built next to where it goes and renamed into place when it is complete, so a crash leaves at most a temporary directory that the next start removes. What is at the destination is never replaced unless gitd made it.
Index ¶
- Constants
- type Limits
- type Publishing
- type PullRequestOpener
- type Recorder
- type Report
- type Result
- type Settings
- type Workspaces
- func (workspaces *Workspaces) Adopt(ctx context.Context, request *gitdv1.AdoptRequest, report Report) (int64, error)
- func (workspaces *Workspaces) BuildTemplate(ctx context.Context, key template.Key, building, final string) error
- func (workspaces *Workspaces) Changes(ctx context.Context, request *gitdv1.ChangesRequest) (*gitdv1.ChangesResponse, error)
- func (workspaces *Workspaces) Checkout(ctx context.Context, request *gitdv1.CheckoutRequest, report Report) (Result, error)
- func (workspaces *Workspaces) Compare(ctx context.Context, request *gitdv1.CompareRequest) (*gitdv1.CompareResponse, error)
- func (workspaces *Workspaces) Conflicts(ctx context.Context, request *gitdv1.ConflictsRequest) (*gitdv1.ConflictsResponse, error)
- func (workspaces *Workspaces) Describe(ctx context.Context, request *gitdv1.DescribeRequest) (*gitdv1.DescribeResponse, error)
- func (workspaces *Workspaces) Diff(ctx context.Context, request *gitdv1.DiffRequest) (*gitdv1.DiffResponse, error)
- func (workspaces *Workspaces) ForgetTemplate(ctx context.Context, key template.Key, dir string) error
- func (workspaces *Workspaces) LFS(path string) []string
- func (workspaces *Workspaces) List(ctx context.Context) (*gitdv1.ListResponse, error)
- func (workspaces *Workspaces) ListWarm(request *gitdv1.ListWarmRequest) (*gitdv1.ListWarmResponse, error)
- func (workspaces *Workspaces) Prepare(ctx context.Context, request *gitdv1.PrepareRequest, report Report) (Result, error)
- func (workspaces *Workspaces) Publish(ctx context.Context, request *gitdv1.PublishRequest) (answer *gitdv1.PublishResponse, err error)
- func (workspaces *Workspaces) PublishPushed(ctx context.Context, request *gitdv1.PublishRequest, repository repo.Repo, ...) (answer *gitdv1.PublishResponse, err error)
- func (workspaces *Workspaces) RecordOwners(ctx context.Context)
- func (workspaces *Workspaces) Remove(ctx context.Context, request *gitdv1.RemoveRequest) error
- func (workspaces *Workspaces) Seal(ctx context.Context, request *gitdv1.SealRequest) (*gitdv1.WarmLayer, error)
- func (workspaces *Workspaces) SyncSubmodules(ctx context.Context, request *gitdv1.SyncSubmodulesRequest, report Report) (*gitdv1.SyncSubmodulesResult, error)
- func (workspaces *Workspaces) Update(ctx context.Context, request *gitdv1.UpdateRequest, report Report) (Result, error)
- func (workspaces *Workspaces) UseEvents(bus *events.Bus)
- func (workspaces *Workspaces) UseLimits(limits Limits)
- func (workspaces *Workspaces) UsePublishing(rules Publishing)
- func (workspaces *Workspaces) UseTemplates(templates *template.Store, maker strategy.Maker)
- func (workspaces *Workspaces) WatchLayers(ctx context.Context)
- func (workspaces *Workspaces) WithinDisk() error
Constants ¶
const PoolInside = "../" + poolMount
PoolInside is the alternates line of a workspace that carries its pool inside itself.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limits ¶
Limits hold one tenant's part of gitd to its share: at most Workspaces workspaces, and no new one, nor a new sandbox, once Used — the disk its pools and templates take, measured each maintenance round — reaches Disk. Zero is no limit.
type Publishing ¶
type Publishing struct {
Settings Settings
PullRequests PullRequestOpener
Recorder Recorder
}
Publishing is the rules a publish follows: Settings, when set, say per repository the branch prefix, the paths a publish may not change or delete and how many files it may change, and how pull requests are opened; PullRequests, when set, opens them; Recorder, when set, keeps every publish, done or refused.
type PullRequestOpener ¶
type PullRequestOpener interface {
Open(ctx context.Context, request pullrequests.Request) (*gitdv1.OpenedPullRequest, error)
Edit(ctx context.Context, request pullrequests.Request, number int64) error
}
PullRequestOpener opens the pull request of a published branch, and edits one.
type Recorder ¶
type Recorder interface {
Record(entry *gitdv1.AuditEntry) error
}
Recorder keeps a record of a publish: the audit log.
type Result ¶
type Result struct {
Commit string
Branch string
Pending []*gitdv1.PendingSubmodule
Strategy gitdv1.Strategy
Layers *gitdv1.Layers
// LFS are the patterns sent to git LFS, whose files are pointers in the workspace.
LFS []string
// PoolObjects is the pool's objects directory, for a workspace carrying its pool.
PoolObjects string
}
Result is where a workspace ended up, and the submodules that could not come along.
func (Result) Proto ¶
func (result Result) Proto() *gitdv1.WorkspaceResult
Proto is the result as the contract carries it.
type Settings ¶
type Settings interface {
For(repository repo.Repo) publishing.Effective
}
Settings say what publishing a repository must follow.
type Workspaces ¶
type Workspaces struct {
// contains filtered or unexported fields
}
Workspaces are the workspaces under the roots gitd may write in. Writes bounds how many operations run at once, and a git `.lock` older than staleLock is taken as left behind.
func New ¶
func New( roots []string, runner *git.Runner, pools *pool.Pools, locks *lock.Locks, writes *lock.Queue, staleLock time.Duration, ) *Workspaces
New returns the workspaces under roots. A root is kept with its symbolic links resolved, as every path asked for is compared once its own are.
func (*Workspaces) Adopt ¶
func (workspaces *Workspaces) Adopt(ctx context.Context, request *gitdv1.AdoptRequest, report Report) (int64, error)
Adopt takes in a clone gitd did not make: it links it to its repository's pool, seeding the pool from the clone when there is none, and repacks it so that it stops holding what the pool holds. What comes back is the disk the clone gave up.
Nothing is removed before `fsck` has checked that the clone reads whole through the pool; if it does not, the link is undone and the clone is left as it was. Its checked out submodules are taken in the same way, each to its own pool.
func (*Workspaces) BuildTemplate ¶
func (workspaces *Workspaces) BuildTemplate(ctx context.Context, key template.Key, building, final string) error
BuildTemplate checks a template out at building, as a workspace is made: borrowing from the pool, detached at the key's commit, with its submodules when the key asks. Its pool must hold the commit already. It is tuned for the copies made from it — whose inodes and change times differ from what its index recorded — to compare only sizes and modification times, so that their first `git status` reads nothing. It is noted on its pools as final, where it will live.
func (*Workspaces) Changes ¶
func (workspaces *Workspaces) Changes(ctx context.Context, request *gitdv1.ChangesRequest) (*gitdv1.ChangesResponse, error)
Changes says what was changed in a workspace since gitd last put it on a commit, committed or not, with the lines of each file.
On an overlay workspace the files the agent touched are those of its own layer, and those that differ between its template and that commit: only they are compared, and no git runs in the workspace. Otherwise git lists them in the workspace, after the same checks of its .git as every other call that runs git there.
func (*Workspaces) Checkout ¶
func (workspaces *Workspaces) Checkout( ctx context.Context, request *gitdv1.CheckoutRequest, report Report, ) (Result, error)
Checkout moves a workspace to a commit, as a rollback does. The pool is only synced when the commit is not in it already, which it is for anything the workspace was at.
func (*Workspaces) Compare ¶
func (workspaces *Workspaces) Compare(ctx context.Context, request *gitdv1.CompareRequest) (*gitdv1.CompareResponse, error)
Compare says how two works of one repository differ, file by file from the first to the second, with their lines and, when asked, their diff.
Only what may differ is compared: what each workspace changed since gitd put it on its commit, and what differs between the two commits. No tree is walked whole, and on overlay workspaces no git runs in a workspace.
func (*Workspaces) Conflicts ¶
func (workspaces *Workspaces) Conflicts(ctx context.Context, request *gitdv1.ConflictsRequest) (*gitdv1.ConflictsResponse, error)
Conflicts says which pairs of several works do not merge cleanly, and on which files. A workspace stands for what it committed: gitd brings that into the pool as publishing does, after the same checks of its .git, and forgets it after. Every merge is read with git merge-tree in the pool, without a working tree and running none of the repository's code.
func (*Workspaces) Describe ¶
func (workspaces *Workspaces) Describe( ctx context.Context, request *gitdv1.DescribeRequest, ) (*gitdv1.DescribeResponse, error)
Describe says what a workspace is on disk, without the network: its repository, its commit and branch, whether something was changed on disk, and its submodules.
func (*Workspaces) Diff ¶
func (workspaces *Workspaces) Diff(ctx context.Context, request *gitdv1.DiffRequest) (*gitdv1.DiffResponse, error)
Diff writes the unified diff of a workspace's changes — of the files asked for, or all — as git writes it, from the copies Changes compares, cut short at a size.
func (*Workspaces) ForgetTemplate ¶
func (workspaces *Workspaces) ForgetTemplate(ctx context.Context, key template.Key, dir string) error
ForgetTemplate takes the template at dir off the pools it borrows from: its repository's and its submodules'.
func (*Workspaces) LFS ¶
func (workspaces *Workspaces) LFS(path string) []string
LFS are the patterns the workspace's .gitattributes sends to git LFS, in the order it names them; none when it names none or cannot be read. The file is read through an os.Root of the workspace, so a link there cannot make gitd read a file outside it.
func (*Workspaces) List ¶ added in v0.15.0
func (workspaces *Workspaces) List(ctx context.Context) (*gitdv1.ListResponse, error)
List is every workspace gitd made that is still on disk, each with what Describe says of it and the branches published from it. A workspace that cannot be described right now, as one gitd refuses to run git in, is listed by its path alone.
func (*Workspaces) ListWarm ¶
func (workspaces *Workspaces) ListWarm(request *gitdv1.ListWarmRequest) (*gitdv1.ListWarmResponse, error)
ListWarm are the warm layers of the repository at url.
func (*Workspaces) Prepare ¶
func (workspaces *Workspaces) Prepare( ctx context.Context, request *gitdv1.PrepareRequest, report Report, ) (Result, error)
Prepare makes a workspace of a repository at a path, at a branch, a commit, or the repository's default branch. A workspace gitd already made there for the same repository is moved to the revision instead.
func (*Workspaces) Publish ¶
func (workspaces *Workspaces) Publish( ctx context.Context, request *gitdv1.PublishRequest, ) (answer *gitdv1.PublishResponse, err error)
Publish pushes what was committed in a workspace to a new branch of its repository, or, asked to update, moves the branch an earlier publish made forward.
Everything is staged in the pools first, and nothing is pushed when the workspace's own repository brings nothing new: a submodule commit nobody pointed the superproject at is not a change anybody can review. Then the submodules go, each to a branch of the same name in its own repository — its commit has to be there before the superproject's points at it — and the superproject last. A submodule that cannot be published stops it all, saying which.
An update that brings nothing beyond what gitd published to the branch pushes nothing and goes on to the pull requests, so one that failed after the push is opened by publishing again.
The branch must start with the prefix publishing is limited to, if there is one; what each repository brings must pass the rules its publishing settings set, checked in its pool before anything is pushed; and every publish, done or refused, is recorded.
func (*Workspaces) PublishPushed ¶
func (workspaces *Workspaces) PublishPushed( ctx context.Context, request *gitdv1.PublishRequest, repository repo.Repo, source string, ) (answer *gitdv1.PublishResponse, err error)
PublishPushed publishes a branch a sandbox pushed to its sandbox repository, at source, through the endpoint: under the same name, with the same branch prefix, rules, pull request and audit log as publishing a workspace. A sandbox repository has no submodules of gitd's and no configuration a sandbox wrote — smart HTTP writes neither — so nothing of it needs the checks a workspace's .git does.
func (*Workspaces) RecordOwners ¶
func (workspaces *Workspaces) RecordOwners(ctx context.Context)
RecordOwners writes, once, the list of own workspaces of every pool made before gitd kept one: each workspace that borrows from a pool and names its repository is taken as one of its own. It runs at start, before any call can change a workspace's configuration.
func (*Workspaces) Remove ¶
func (workspaces *Workspaces) Remove(ctx context.Context, request *gitdv1.RemoveRequest) error
Remove deletes a workspace gitd made. Its pool stays.
func (*Workspaces) Seal ¶
func (workspaces *Workspaces) Seal(ctx context.Context, request *gitdv1.SealRequest) (*gitdv1.WarmLayer, error)
Seal makes an overlay workspace's own layer a warm layer of its repository: what installing its dependencies wrote, for later workspaces at its template's commit to stand on. The layer is moved, not copied, without the workspace's .git; the workspace is then gone, as after Remove.
func (*Workspaces) SyncSubmodules ¶
func (workspaces *Workspaces) SyncSubmodules( ctx context.Context, request *gitdv1.SyncSubmodulesRequest, report Report, ) (*gitdv1.SyncSubmodulesResult, error)
SyncSubmodules checks out every submodule a workspace declares, or the one of a URL.
func (*Workspaces) Update ¶
func (workspaces *Workspaces) Update( ctx context.Context, request *gitdv1.UpdateRequest, report Report, ) (Result, error)
Update brings a workspace to the tip of a branch: the one asked for, or the one it follows. With merge, it merges that branch into the one the workspace is on instead.
func (*Workspaces) UseEvents ¶
func (workspaces *Workspaces) UseEvents(bus *events.Bus)
UseEvents has workspaces tell what happens to them.
func (*Workspaces) UseLimits ¶
func (workspaces *Workspaces) UseLimits(limits Limits)
UseLimits holds new workspaces to limits.
func (*Workspaces) UsePublishing ¶
func (workspaces *Workspaces) UsePublishing(rules Publishing)
UsePublishing has publishes follow rules.
func (*Workspaces) UseTemplates ¶
func (workspaces *Workspaces) UseTemplates(templates *template.Store, maker strategy.Maker)
UseTemplates has new workspaces made from templates by maker, which Detect picked; a nil maker keeps writing every file. Templates are built by the workspaces themselves, so this comes after New.
func (*Workspaces) WatchLayers ¶
func (workspaces *Workspaces) WatchLayers(ctx context.Context)
WatchLayers tells the watchers of an overlay workspace when something in its agent's layer changed, until ctx ends. The layers are looked at every couple of seconds, and only while someone watches: what an agent writes goes to its layer, which is small, so a look is a walk of what it changed, never of the tree. A workspace written whole has no layer to look at: its watchers hear of what gitd does to it, not of what its agent does.
func (*Workspaces) WithinDisk ¶
func (workspaces *Workspaces) WithinDisk() error
WithinDisk says why nothing new may be made for lack of disk, or nothing when it may.
Source Files
¶
- adopt.go
- adopt_submodules.go
- borrow.go
- bring_in.go
- changes.go
- changes_compare.go
- changes_git.go
- changes_layer.go
- changes_lines.go
- checkout.go
- compare.go
- compare_sides.go
- config_guard.go
- config_keys.go
- conflicts.go
- create.go
- describe.go
- diff.go
- from_template.go
- gitdir_guard.go
- gitmodules.go
- hold.go
- lfs.go
- limits.go
- link.go
- list.go
- merge.go
- mount.go
- own_branch.go
- owners.go
- paths.go
- platform_settings.go
- pool_inside.go
- pool_inside_linux.go
- prepare.go
- provenance.go
- publish.go
- publish_policy.go
- publish_pull_request.go
- publish_rules.go
- publish_sandbox.go
- publish_submodules.go
- seal.go
- settle.go
- states.go
- submodules.go
- template.go
- update.go
- warm.go
- watch.go
- whiteout_unix.go
- workspace.go
- write_inside.go