Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Move repo syncing into repo #940

Merged
merged 3 commits into from
Feb 27, 2018
Merged

Move repo syncing into repo #940

merged 3 commits into from
Feb 27, 2018

Conversation

squaremo
Copy link
Member

@squaremo squaremo commented Feb 13, 2018

To ease the transition into supporting zero git repos, and later supporting more than one repo, this PR moves the periodic git fetch loop into the git package.

The effect is to make a git repo a state machine; it starts uncloned, then is mirrored, and finally tested to see if it's writable. Treating it as a state machine has a couple of benefits:

  1. We will be better able to cope with intermediate states -- for example, to give results that don't need write access when we don't have write access. This will matter the more so when we're dealing with more than one repo.
  2. It decouples the git repo polling from the daemon's "main loop", so not as many things are rolled up in the one place.

This PR doesn't change how the daemon works, in the main -- it will still wait for the repo to be ready before proceeding. To support zero git repos, we can remove that gate and respond to each API method by checking whether there's a git repo ready or not, and acting accordingly.

Tasting notes:

  • there's still a need for the git mirror to tell the daemon that there are fresh commits; and for the daemon to tell the git mirror that it has pushed something upstream. These are accomplished with a non-blocking channel send in each direction.
  • there's also a synchronous *Repo.Refresh(...) for when the daemon needs to wait for the repo to be up to date before proceeding.
  • the Repo is a mirror, which means it doesn't have a working directory to look around in; the downside is you have to clone it every time you want to look at the files (a cache could be done in the daemon loop, if necessary). The upside (aside from some convenience in the git operations) is that there's no confusion over which things you can write to -- if you want to make a commit, you have to clone first.

@squaremo squaremo force-pushed the feature/repo-sync branch 3 times, most recently from b7eb805 to 55f6ae8 Compare February 16, 2018 15:25
@squaremo squaremo requested review from errordeveloper and stefanprodan and removed request for errordeveloper and stefanprodan February 16, 2018 15:26
@squaremo
Copy link
Member Author

Ops, accidental review requests. My apologues.

This rewrites the git package so that there are two distinct
abstractions: a self-syncing `Repo` and a working directory
`Checkout`.

`Repo` maintains a git mirror of an upstream git repository. It does
both the initial clone and regular fetches, notifying on a channel
when it's done so. The advantage of it being a mirror is that it will
keep track of all refs (including notes), so does not need to be told
to fetch particular branches.

Since the daemon often needs to push new commits, then wait for them
to be mirrored, there is also a synchronous method to fetch from
upstream.

Since it's just a mirror (i.e., has no working files), if the daemon
needs to look at files it must clone the repo. There's now a helper
method for this -- `*Daemon.WithClone` -- which makes sure things are
tidied up afterward.
In particular, figure out the old and new revisions up front, rather
than relying on HEAD and the tag to be in the right places, which is
safe now but may not survive code changes as well.
@squaremo squaremo changed the title [WIP] Move repo syncing into repo Move repo syncing into repo Feb 26, 2018
Being able to refer to the Config fields by two paths is unnecessary,
as is the mutex (which made some sense when the daemon was pulling
refs occasionally, but no longer).
Copy link
Contributor

@samb1729 samb1729 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LTMG

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants