libgit

package
v0.0.0-...-f10651d Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: BSD-3-Clause, BSD-3-Clause Imports: 38 Imported by: 24

Documentation

Index

Constants

View Source
const (
	// AutogitRoot is the subdirectory name within a TLF where autogit
	// can be accessed.
	AutogitRoot = ".kbfs_autogit"
	// AutogitBranchPrefix is a prefix of a subdirectory name
	// containing one element of a git reference name.
	AutogitBranchPrefix = ".kbfs_autogit_branch_"
	// AutogitCommitPrefix is a prefix of a file name
	// containing the full commit hash.
	AutogitCommitPrefix = ".kbfs_autogit_commit_"
)
View Source
const (
	GitSuffixToIgnore = ".git"
)
View Source
const (
	// LFSSubdir is the prefix for the LFS directory under .kbfs_git
	LFSSubdir = "kbfs_lfs"
)

Variables

View Source
var CommitSentinelValue *object.Commit

CommitSentinelValue marks the end of a list of commits, where there are still commits that haven't been read. Use the zero-value `nil`.

View Source
var NullID = ID{}

NullID is an empty ID

View Source
var RepoNameRE = `(?:[a-zA-Z0-9][a-zA-Z0-9_\.-]*)`

RepoNameRE is the uncompiled regex for repo names.

Functions

func CleanOldDeletedRepos

func CleanOldDeletedRepos(
	ctx context.Context, config libkbfs.Config,
	tlfHandle *tlfhandle.Handle) (err error)

CleanOldDeletedRepos completely removes any "deleted" repos that have been deleted for longer than `minDeletedAgeForCleaning`. The caller is responsible for syncing any data to disk, if desired.

func CleanOldDeletedReposTimeLimited

func CleanOldDeletedReposTimeLimited(
	ctx context.Context, config libkbfs.Config,
	tlfHandle *tlfhandle.Handle) error

CleanOldDeletedReposTimeLimited is the same as `CleanOldDeletedRepos`, except it limits the time spent on cleaning, deleting as much data as possible within the given time limit (without returning an error).

func DeleteRepo

func DeleteRepo(
	ctx context.Context, config libkbfs.Config, tlfHandle *tlfhandle.Handle,
	repoName string) error

DeleteRepo "deletes" the given repo in the given TLF. Right now it simply moves the repo out of the way to a special directory, to allow any concurrent writers to finish their pushes without triggering conflict resolution. The caller is responsible for syncing the FS and flushing the journal, if desired. It expects the `config` object to be unique during the lifetime of this call.

func GCRepo

func GCRepo(
	ctx context.Context, config libkbfs.Config, tlfHandle *tlfhandle.Handle,
	repoName string, options GCOptions) (err error)

GCRepo runs garbage collection on the specified repo, if it exceeds any of the thresholds provided in `options`.

func Init

func Init(ctx context.Context, gitKBFSParams libkbfs.InitParams,
	kbCtx libkbfs.Context, keybaseServiceCn libkbfs.KeybaseServiceCn,
	defaultLogPath string, vlogLevel string) (
	context.Context, libkbfs.Config, error)

Init initializes a context and a libkbfs.Config for git operations. The config should be shutdown when it is done being used.

func LastGCTime

func LastGCTime(ctx context.Context, fs billy.Filesystem) (
	time.Time, error)

LastGCTime returns the last time the repo was successfully garbage-collected.

func NeedsGC

func NeedsGC(storage storage.Storer, options GCOptions) (
	doPackRefs bool, numLooseRefs int, doPruneLoose, doObjectRepack bool,
	numObjectPacks int, err error)

NeedsGC checks the given repo storage layer against the given options to see what kinds of GC are needed on the repo.

func NormalizeRepoName

func NormalizeRepoName(repoName string) string

NormalizeRepoName removes the .git suffix from repoName.

func Params

func Params(kbCtx libkbfs.Context,
	storageRoot string, paramsBase *libkbfs.InitParams) (
	params libkbfs.InitParams, tempDir string, err error)

Params returns a set of default parameters for git-related operations, along with a temp directory that should be cleaned after the git work is complete.

func RenameRepo

func RenameRepo(
	ctx context.Context, config libkbfs.Config, tlfHandle *tlfhandle.Handle,
	oldRepoName, newRepoName string) (err error)

RenameRepo renames the repo from an old name to a new name. It leaves a symlink behind so that old remotes will continue to work. The caller is responsible for syncing the FS and flushing the journal, if desired.

func StartAutogit

func StartAutogit(config libkbfs.Config, browserCacheSize int) func()

StartAutogit launches autogit, and returns a function that should be called on shutdown.

func UpdateRepoMD

func UpdateRepoMD(ctx context.Context, config libkbfs.Config,
	tlfHandle *tlfhandle.Handle, fs billy.Filesystem,
	pushType keybase1.GitPushType,
	oldRepoName string, refDataByName RefDataByName) error

UpdateRepoMD lets the Keybase service know that a repo's MD has been updated.

Types

type AutogitManager

type AutogitManager struct {
	// contains filtered or unexported fields
}

AutogitManager can clone and pull source git repos into a destination folder, potentially across different TLFs. New requests for an operation in a destination repo are blocked by any ongoing requests for the same folder, and multiple outstanding requests for the same destination folder get rolled up into one.

func NewAutogitManager

func NewAutogitManager(
	config libkbfs.Config, browserCacheSize int) *AutogitManager

NewAutogitManager constructs a new AutogitManager instance.

func (*AutogitManager) BatchChanges

func (am *AutogitManager) BatchChanges(
	ctx context.Context, _ []libkbfs.NodeChange,
	affectedNodeIDs []libkbfs.NodeID)

BatchChanges implements the libkbfs.Observer interface for AutogitManager.

func (*AutogitManager) GetBrowserForRepo

func (am *AutogitManager) GetBrowserForRepo(
	ctx context.Context, gitFS *libfs.FS, repoName string,
	branch plumbing.ReferenceName, subdir string) (*libfs.FS, *Browser, error)

GetBrowserForRepo returns the root FS for the specified repo and a `Browser` for the branch and subdir.

func (*AutogitManager) LocalChange

func (am *AutogitManager) LocalChange(
	ctx context.Context, node libkbfs.Node, wr libkbfs.WriteRange)

LocalChange implements the libkbfs.Observer interface for AutogitManager.

func (*AutogitManager) Shutdown

func (am *AutogitManager) Shutdown()

Shutdown shuts down this manager.

func (*AutogitManager) TlfHandleChange

func (am *AutogitManager) TlfHandleChange(
	ctx context.Context, newHandle *tlfhandle.Handle)

TlfHandleChange implements the libkbfs.Observer interface for AutogitManager.

type Browser

type Browser struct {
	// contains filtered or unexported fields
}

Browser presents the contents of a git repo as a read-only file system, using only the dotgit directory of the repo.

func NewBrowser

func NewBrowser(
	repoFS *libfs.FS, clock libkbfs.Clock,
	gitBranchName plumbing.ReferenceName,
	sharedCache sharedInBrowserCache) (*Browser, error)

NewBrowser makes a new Browser instance, browsing the given branch of the given repo. If `gitBranchName` is empty, "refs/heads/master" is used. If `gitBranchName` is not empty, but it doesn't begin with "refs/", then "refs/heads/" is prepended to it.

func (*Browser) Chroot

func (b *Browser) Chroot(p string) (newFS billy.Filesystem, err error)

Chroot implements the billy.Filesystem interface for Browser.

func (*Browser) Create

func (b *Browser) Create(_ string) (billy.File, error)

Create implements the billy.Filesystem interface for Browser.

func (*Browser) Join

func (b *Browser) Join(elem ...string) string

Join implements the billy.Filesystem interface for Browser.

func (*Browser) Lstat

func (b *Browser) Lstat(filename string) (fi os.FileInfo, err error)

Lstat implements the billy.Filesystem interface for Browser.

func (*Browser) MkdirAll

func (b *Browser) MkdirAll(_ string, _ os.FileMode) (err error)

MkdirAll implements the billy.Filesystem interface for Browser.

func (*Browser) Open

func (b *Browser) Open(filename string) (f billy.File, err error)

Open implements the billy.Filesystem interface for Browser.

func (*Browser) OpenFile

func (b *Browser) OpenFile(filename string, flag int, _ os.FileMode) (
	f billy.File, err error)

OpenFile implements the billy.Filesystem interface for Browser.

func (*Browser) ReadDir

func (b *Browser) ReadDir(p string) (fis []os.FileInfo, err error)

ReadDir implements the billy.Filesystem interface for Browser.

func (b *Browser) Readlink(link string) (target string, err error)

Readlink implements the billy.Filesystem interface for Browser.

func (*Browser) Remove

func (b *Browser) Remove(_ string) (err error)

Remove implements the billy.Filesystem interface for Browser.

func (*Browser) Rename

func (b *Browser) Rename(_, _ string) (err error)

Rename implements the billy.Filesystem interface for Browser.

func (*Browser) Root

func (b *Browser) Root() string

Root implements the billy.Filesystem interface for Browser.

func (*Browser) Stat

func (b *Browser) Stat(filename string) (fi os.FileInfo, err error)

Stat implements the billy.Filesystem interface for Browser.

func (b *Browser) Symlink(_, _ string) (err error)

Symlink implements the billy.Filesystem interface for Browser.

func (*Browser) TempFile

func (b *Browser) TempFile(_, _ string) (billy.File, error)

TempFile implements the billy.Filesystem interface for Browser.

type Config

type Config struct {
	ID         ID
	Name       string // the original user-supplied format of the name
	CreatorUID string
	Ctime      int64 // create time in unix nanoseconds, by creator's clock
}

Config is a KBFS git repo config file.

type GCOptions

type GCOptions struct {
	// The most loose refs we will tolerate; if there are more loose
	// refs, we should pack them.
	MaxLooseRefs int
	// The minimum number of potentially-expired loose objects we need
	// to start the pruning process.  If < 0, pruning will not be done.
	PruneMinLooseObjects int
	// Any unreachable objects older than this time are subject to
	// pruning.
	PruneExpireTime time.Time
	// The most object packs we will tolerate; if there are more
	// object packs, we should re-pack all the objects.  If < 0,
	// re-packing will not be done.
	MaxObjectPacks int
}

GCOptions describe options foe garbage collection.

type GitConfigWithoutRemotesStorer

type GitConfigWithoutRemotesStorer struct {
	*filesystem.Storage
	// contains filtered or unexported fields
}

GitConfigWithoutRemotesStorer strips remotes from the config before writing them to disk, to work around a gcfg bug (used by go-git when reading configs from disk) that causes a freakout when it sees backslashes in git file URLs.

func NewGitConfigWithoutRemotesStorer

func NewGitConfigWithoutRemotesStorer(fs *libfs.FS) (
	*GitConfigWithoutRemotesStorer, error)

NewGitConfigWithoutRemotesStorer creates a new git config implementation that strips remotes from the config before writing them to disk.

func (*GitConfigWithoutRemotesStorer) Config

Config implements the `storer.Storer` interface.

func (*GitConfigWithoutRemotesStorer) Init

func (cwrs *GitConfigWithoutRemotesStorer) Init() error

Init implements the `storer.Initializer` interface.

func (*GitConfigWithoutRemotesStorer) SetConfig

func (cwrs *GitConfigWithoutRemotesStorer) SetConfig(c *gogitcfg.Config) (
	err error)

SetConfig implements the `storer.Storer` interface.

type ID

type ID struct {
	// contains filtered or unexported fields
}

ID encapsulates a repo ID.

func CreateRepoAndID

func CreateRepoAndID(
	ctx context.Context, config libkbfs.Config, tlfHandle *tlfhandle.Handle,
	repoName string) (ID, error)

CreateRepoAndID returns a new stable repo ID for the provided repoName in the given TLF. If the repo has already been created, it returns a `RepoAlreadyExistsError`. If `repoName` already exists, but is a symlink to another renamed directory, the symlink will be removed in favor of the new repo. The caller is responsible for syncing the FS and flushing the journal, if desired. It expects the `config` object to be unique during the lifetime of this call.

func GetOrCreateRepoAndID

func GetOrCreateRepoAndID(
	ctx context.Context, config libkbfs.Config, tlfHandle *tlfhandle.Handle,
	repoName string, uniqID string) (*libfs.FS, ID, error)

GetOrCreateRepoAndID returns a filesystem object rooted at the specified repo, along with the stable repo ID. If the repo hasn't been created yet, it generates a new ID and creates the repo. The caller is responsible for syncing the FS and flushing the journal, if desired.

func GetRepoAndID

func GetRepoAndID(
	ctx context.Context, config libkbfs.Config, tlfHandle *tlfhandle.Handle,
	repoName string, uniqID string) (*libfs.FS, ID, error)

GetRepoAndID returns a filesystem object rooted at the specified repo, along with the stable repo ID, if it already exists.

func (ID) Bytes

func (id ID) Bytes() []byte

Bytes returns the bytes of the ID.

func (ID) MarshalBinary

func (id ID) MarshalBinary() (data []byte, err error)

MarshalBinary implements the encoding.BinaryMarshaler interface for ID.

func (ID) MarshalText

func (id ID) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for ID.

func (ID) String

func (id ID) String() string

String implements the Stringer interface for ID.

func (*ID) UnmarshalBinary

func (id *ID) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface for ID.

func (*ID) UnmarshalText

func (id *ID) UnmarshalText(buf []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for ID.

type InvalidIDError

type InvalidIDError struct {
	// contains filtered or unexported fields
}

InvalidIDError indicates that a repo ID string is not parseable or invalid.

func (InvalidIDError) Error

func (e InvalidIDError) Error() string

type OnDemandStorer

type OnDemandStorer struct {
	storage.Storer
	// contains filtered or unexported fields
}

OnDemandStorer is a wrapper around a storage.Storer that reads encoded objects from disk only when the data is needed, to avoid pulling too much data into memory.

func NewOnDemandStorer

func NewOnDemandStorer(s storage.Storer) (*OnDemandStorer, error)

NewOnDemandStorer constructs an on-demand storage layer on top of an existing `Storer`.

func (*OnDemandStorer) DeltaObject

func (ods *OnDemandStorer) DeltaObject(
	ot plumbing.ObjectType, hash plumbing.Hash) (
	plumbing.EncodedObject, error)

DeltaObject implements the storer.DeltaObjectStorer interface for OnDemandStorer.

func (*OnDemandStorer) EncodedObject

func (ods *OnDemandStorer) EncodedObject(
	ot plumbing.ObjectType, hash plumbing.Hash) (
	plumbing.EncodedObject, error)

EncodedObject implements the storage.Storer interface for OnDemandStorer.

type RPCHandler

type RPCHandler struct {
	// contains filtered or unexported fields
}

RPCHandler handles service->KBFS git RPC calls.

func NewRPCHandlerWithCtx

func NewRPCHandlerWithCtx(kbCtx libkbfs.Context, config libkbfs.Config,
	kbfsInitParams *libkbfs.InitParams) (*RPCHandler, func())

NewRPCHandlerWithCtx returns a new instance of a Git RPC handler.

func (*RPCHandler) CreateRepo

func (rh *RPCHandler) CreateRepo(
	ctx context.Context, arg keybase1.CreateRepoArg) (
	id keybase1.RepoID, err error)

CreateRepo implements keybase1.KBFSGitInterface for KeybaseServiceBase.

func (*RPCHandler) DeleteRepo

func (rh *RPCHandler) DeleteRepo(
	ctx context.Context, arg keybase1.DeleteRepoArg) (err error)

DeleteRepo implements keybase1.KBFSGitInterface for KeybaseServiceBase.

func (*RPCHandler) Gc

func (rh *RPCHandler) Gc(
	ctx context.Context, arg keybase1.GcArg) (err error)

Gc implements keybase1.KBFSGitInterface for KeybaseServiceBase.

func (*RPCHandler) RenameRepo

func (rh *RPCHandler) RenameRepo(ctx context.Context,
	folder keybase1.FolderHandle, oldName, newName string) (err error)

RenameRepo renames an existing git repository.

TODO: Hook this up to an RPC.

type RefData

type RefData struct {
	IsDelete bool
	Commits  []*object.Commit
}

RefData stores the data for a ref.

type RefDataByName

type RefDataByName map[plumbing.ReferenceName]*RefData

RefDataByName represents a map of reference names to data about that ref.

Jump to

Keyboard shortcuts

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