RepoManager#

class mobu.services.repo.RepoManager(logger, *, testing=False)#

Bases: object

A reference-counting caching repo cloner.

Only the first call to clone for a given repo url and ref will clone the repo. Subsequent calls will return the location and hash of the already-cloned repo.

A call to invalidate will make it so that the next call to clone will re-clone the repo to a different path.

A call to clone also increases a reference counter for the url + ref + hash combo of the cloned repo. A call to invalidate for that combo decreases the counter. Invalidate will only delete the files from the cloned repo if the reference count drops to 0.

Parameters:

Methods Summary

clone(url, ref, username)

Clone a git repo or return cached info by url + ref.

close()

Delete all cloned repos and containing directory.

invalidate(url, ref, repo_hash, username)

Invalidate a git repo in the cache by url + ref.

Methods Documentation

async clone(url, ref, username)#

Clone a git repo or return cached info by url + ref.

Increase the reference count for the url + ref + hash combo.

Parameters:
  • url (str) – The URL of the repo to clone

  • ref (str) – The git ref to checkout after the repo is cloned

  • username (str) – The user trying to clone the repo

Return type:

ClonedRepoInfo

close()#

Delete all cloned repos and containing directory.

Return type:

None

async invalidate(url, ref, repo_hash, username)#

Invalidate a git repo in the cache by url + ref.

Decrease the url + ref + hash reference count. If it drops to zero, delete the files from that clone.

Parameters:
  • url (str) – The URL of the repo to clone

  • ref (str) – The git ref to checkout after the repo is cloned

  • hash – The hash of the cloned repo to remove

  • username (str) – The user trying to remove the repo

  • repo_hash (str)

Return type:

None