git-bug: github.com/MichaelMure/git-bug/cache Index | Files

package cache

import "github.com/MichaelMure/git-bug/cache"

Package cache contains a caching layer on top of the low-level bug and identity functions to provide efficient querying, filtering, sorting.

Index

Package Files

bug_cache.go bug_excerpt.go doc.go filter.go identity_cache.go identity_excerpt.go multi_repo_cache.go repo_cache.go repo_cache_bug.go repo_cache_common.go repo_cache_identity.go

Variables

var ErrNoMatchingOp = fmt.Errorf("no matching operation found")

type BugCache Uses

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

BugCache is a wrapper around a Bug. It provide multiple functions:

1. Provide a higher level API to use than the raw API from Bug. 2. Maintain an up to date Snapshot available.

func NewBugCache Uses

func NewBugCache(repoCache *RepoCache, b *bug.Bug) *BugCache

func (*BugCache) AddComment Uses

func (c *BugCache) AddComment(message string) (*bug.AddCommentOperation, error)

func (*BugCache) AddCommentRaw Uses

func (c *BugCache) AddCommentRaw(author *IdentityCache, unixTime int64, message string, files []repository.Hash, metadata map[string]string) (*bug.AddCommentOperation, error)

func (*BugCache) AddCommentWithFiles Uses

func (c *BugCache) AddCommentWithFiles(message string, files []repository.Hash) (*bug.AddCommentOperation, error)

func (*BugCache) ChangeLabels Uses

func (c *BugCache) ChangeLabels(added []string, removed []string) ([]bug.LabelChangeResult, *bug.LabelChangeOperation, error)

func (*BugCache) ChangeLabelsRaw Uses

func (c *BugCache) ChangeLabelsRaw(author *IdentityCache, unixTime int64, added []string, removed []string, metadata map[string]string) ([]bug.LabelChangeResult, *bug.LabelChangeOperation, error)

func (*BugCache) Close Uses

func (c *BugCache) Close() (*bug.SetStatusOperation, error)

func (*BugCache) CloseRaw Uses

func (c *BugCache) CloseRaw(author *IdentityCache, unixTime int64, metadata map[string]string) (*bug.SetStatusOperation, error)

func (*BugCache) Commit Uses

func (c *BugCache) Commit() error

func (*BugCache) CommitAsNeeded Uses

func (c *BugCache) CommitAsNeeded() error

func (*BugCache) EditComment Uses

func (c *BugCache) EditComment(target entity.Id, message string) (*bug.EditCommentOperation, error)

func (*BugCache) EditCommentRaw Uses

func (c *BugCache) EditCommentRaw(author *IdentityCache, unixTime int64, target entity.Id, message string, metadata map[string]string) (*bug.EditCommentOperation, error)

func (*BugCache) EditCreateComment Uses

func (c *BugCache) EditCreateComment(body string) (*bug.EditCommentOperation, error)

func (*BugCache) EditCreateCommentRaw Uses

func (c *BugCache) EditCreateCommentRaw(author *IdentityCache, unixTime int64, body string, metadata map[string]string) (*bug.EditCommentOperation, error)

func (*BugCache) ForceChangeLabels Uses

func (c *BugCache) ForceChangeLabels(added []string, removed []string) (*bug.LabelChangeOperation, error)

func (*BugCache) ForceChangeLabelsRaw Uses

func (c *BugCache) ForceChangeLabelsRaw(author *IdentityCache, unixTime int64, added []string, removed []string, metadata map[string]string) (*bug.LabelChangeOperation, error)

func (*BugCache) Id Uses

func (c *BugCache) Id() entity.Id

func (*BugCache) NeedCommit Uses

func (c *BugCache) NeedCommit() bool

func (*BugCache) Open Uses

func (c *BugCache) Open() (*bug.SetStatusOperation, error)

func (*BugCache) OpenRaw Uses

func (c *BugCache) OpenRaw(author *IdentityCache, unixTime int64, metadata map[string]string) (*bug.SetStatusOperation, error)

func (*BugCache) ResolveOperationWithMetadata Uses

func (c *BugCache) ResolveOperationWithMetadata(key string, value string) (entity.Id, error)

ResolveOperationWithMetadata will find an operation that has the matching metadata

func (*BugCache) SetMetadata Uses

func (c *BugCache) SetMetadata(target entity.Id, newMetadata map[string]string) (*bug.SetMetadataOperation, error)

func (*BugCache) SetMetadataRaw Uses

func (c *BugCache) SetMetadataRaw(author *IdentityCache, unixTime int64, target entity.Id, newMetadata map[string]string) (*bug.SetMetadataOperation, error)

func (*BugCache) SetTitle Uses

func (c *BugCache) SetTitle(title string) (*bug.SetTitleOperation, error)

func (*BugCache) SetTitleRaw Uses

func (c *BugCache) SetTitleRaw(author *IdentityCache, unixTime int64, title string, metadata map[string]string) (*bug.SetTitleOperation, error)

func (*BugCache) Snapshot Uses

func (c *BugCache) Snapshot() *bug.Snapshot

type BugExcerpt Uses

type BugExcerpt struct {
    Id  entity.Id

    CreateLamportTime lamport.Time
    EditLamportTime   lamport.Time

    Status       bug.Status
    Labels       []bug.Label
    Title        string
    LenComments  int
    Actors       []entity.Id
    Participants []entity.Id

    // If author is identity.Bare, LegacyAuthor is set
    // If author is identity.Identity, AuthorId is set and data is deported
    // in a IdentityExcerpt
    LegacyAuthor LegacyAuthorExcerpt
    AuthorId     entity.Id

    CreateMetadata map[string]string
    // contains filtered or unexported fields
}

BugExcerpt hold a subset of the bug values to be able to sort and filter bugs efficiently without having to read and compile each raw bugs.

func NewBugExcerpt Uses

func NewBugExcerpt(b bug.Interface, snap *bug.Snapshot) *BugExcerpt

func (*BugExcerpt) CreateTime Uses

func (b *BugExcerpt) CreateTime() time.Time

func (*BugExcerpt) EditTime Uses

func (b *BugExcerpt) EditTime() time.Time

type BugsByCreationTime Uses

type BugsByCreationTime []*BugExcerpt

func (BugsByCreationTime) Len Uses

func (b BugsByCreationTime) Len() int

func (BugsByCreationTime) Less Uses

func (b BugsByCreationTime) Less(i, j int) bool

func (BugsByCreationTime) Swap Uses

func (b BugsByCreationTime) Swap(i, j int)

type BugsByEditTime Uses

type BugsByEditTime []*BugExcerpt

func (BugsByEditTime) Len Uses

func (b BugsByEditTime) Len() int

func (BugsByEditTime) Less Uses

func (b BugsByEditTime) Less(i, j int) bool

func (BugsByEditTime) Swap Uses

func (b BugsByEditTime) Swap(i, j int)

type BugsById Uses

type BugsById []*BugExcerpt

func (BugsById) Len Uses

func (b BugsById) Len() int

func (BugsById) Less Uses

func (b BugsById) Less(i, j int) bool

func (BugsById) Swap Uses

func (b BugsById) Swap(i, j int)

type Filter Uses

type Filter func(excerpt *BugExcerpt, resolver resolver) bool

Filter is a predicate that match a subset of bugs

func ActorFilter Uses

func ActorFilter(query string) Filter

ActorFilter return a Filter that match a bug actor

func AuthorFilter Uses

func AuthorFilter(query string) Filter

AuthorFilter return a Filter that match a bug author

func LabelFilter Uses

func LabelFilter(label string) Filter

LabelFilter return a Filter that match a label

func NoLabelFilter Uses

func NoLabelFilter() Filter

NoLabelFilter return a Filter that match the absence of labels

func ParticipantFilter Uses

func ParticipantFilter(query string) Filter

ParticipantFilter return a Filter that match a bug participant

func StatusFilter Uses

func StatusFilter(status bug.Status) Filter

StatusFilter return a Filter that match a bug status

func TitleFilter Uses

func TitleFilter(query string) Filter

TitleFilter return a Filter that match if the title contains the given query

type IdentityById Uses

type IdentityById []*IdentityExcerpt

func (IdentityById) Len Uses

func (b IdentityById) Len() int

func (IdentityById) Less Uses

func (b IdentityById) Less(i, j int) bool

func (IdentityById) Swap Uses

func (b IdentityById) Swap(i, j int)

type IdentityCache Uses

type IdentityCache struct {
    *identity.Identity
    // contains filtered or unexported fields
}

IdentityCache is a wrapper around an Identity for caching.

func NewIdentityCache Uses

func NewIdentityCache(repoCache *RepoCache, id *identity.Identity) *IdentityCache

func (*IdentityCache) Commit Uses

func (i *IdentityCache) Commit() error

func (*IdentityCache) CommitAsNeeded Uses

func (i *IdentityCache) CommitAsNeeded() error

func (*IdentityCache) Mutate Uses

func (i *IdentityCache) Mutate(f func(identity.Mutator) identity.Mutator) error

type IdentityExcerpt Uses

type IdentityExcerpt struct {
    Id  entity.Id

    Name              string
    Login             string
    ImmutableMetadata map[string]string
}

IdentityExcerpt hold a subset of the identity values to be able to sort and filter identities efficiently without having to read and compile each raw identity.

func NewIdentityExcerpt Uses

func NewIdentityExcerpt(i *identity.Identity) *IdentityExcerpt

func (*IdentityExcerpt) DisplayName Uses

func (i *IdentityExcerpt) DisplayName() string

DisplayName return a non-empty string to display, representing the identity, based on the non-empty values.

func (*IdentityExcerpt) Match Uses

func (i *IdentityExcerpt) Match(query string) bool

Match matches a query with the identity name, login and ID prefixes

type LegacyAuthorExcerpt Uses

type LegacyAuthorExcerpt struct {
    Name  string
    Login string
}

identity.Bare data are directly embedded in the bug excerpt

func (LegacyAuthorExcerpt) DisplayName Uses

func (l LegacyAuthorExcerpt) DisplayName() string

type Matcher Uses

type Matcher struct {
    Status      []Filter
    Author      []Filter
    Actor       []Filter
    Participant []Filter
    Label       []Filter
    Title       []Filter
    NoFilters   []Filter
}

Matcher is a collection of Filter that implement a complex filter

func (*Matcher) Match Uses

func (f *Matcher) Match(excerpt *BugExcerpt, resolver resolver) bool

Match check if a bug match the set of filters

type MultiRepoCache Uses

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

MultiRepoCache is the root cache, holding multiple RepoCache.

func NewMultiRepoCache Uses

func NewMultiRepoCache() *MultiRepoCache

func (*MultiRepoCache) Close Uses

func (c *MultiRepoCache) Close() error

Close will do anything that is needed to close the cache properly

func (*MultiRepoCache) DefaultRepo Uses

func (c *MultiRepoCache) DefaultRepo() (*RepoCache, error)

DefaultRepo retrieve the default repository

func (*MultiRepoCache) RegisterDefaultRepository Uses

func (c *MultiRepoCache) RegisterDefaultRepository(repo repository.ClockedRepo) (*RepoCache, error)

RegisterDefaultRepository register a unnamed repository. Use this for mono-repo setup

func (*MultiRepoCache) RegisterRepository Uses

func (c *MultiRepoCache) RegisterRepository(ref string, repo repository.ClockedRepo) (*RepoCache, error)

RegisterRepository register a named repository. Use this for multi-repo setup

func (*MultiRepoCache) ResolveRepo Uses

func (c *MultiRepoCache) ResolveRepo(ref string) (*RepoCache, error)

ResolveRepo retrieve a repository with a reference

type RepoCache Uses

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

RepoCache is a cache for a Repository. This cache has multiple functions:

1. After being loaded, a Bug is kept in memory in the cache, allowing for fast

access later.

2. The cache maintain in memory and on disk a pre-digested excerpt for each bug,

allowing for fast querying the whole set of bugs without having to load
them individually.

3. The cache guarantee that a single instance of a Bug is loaded at once, avoiding

loss of data that we could have with multiple copies in the same process.

4. The same way, the cache maintain in memory a single copy of the loaded identities.

The cache also protect the on-disk data by locking the git repository for its own usage, by writing a lock file. Of course, normal git operations are not affected, only git-bug related one.

func NewNamedRepoCache Uses

func NewNamedRepoCache(r repository.ClockedRepo, name string) (*RepoCache, error)

func NewRepoCache Uses

func NewRepoCache(r repository.ClockedRepo) (*RepoCache, error)

func (*RepoCache) AllBugsIds Uses

func (c *RepoCache) AllBugsIds() []entity.Id

AllBugsIds return all known bug ids

func (*RepoCache) AllIdentityIds Uses

func (c *RepoCache) AllIdentityIds() []entity.Id

AllIdentityIds return all known identity ids

func (*RepoCache) Close Uses

func (c *RepoCache) Close() error

func (*RepoCache) Fetch Uses

func (c *RepoCache) Fetch(remote string) (string, error)

Fetch retrieve updates from a remote This does not change the local bugs or identities state

func (*RepoCache) GetCoreEditor Uses

func (c *RepoCache) GetCoreEditor() (string, error)

GetCoreEditor returns the name of the editor that the user has used to configure git.

func (*RepoCache) GetPath Uses

func (c *RepoCache) GetPath() string

GetPath returns the path to the repo.

func (*RepoCache) GetRemotes Uses

func (c *RepoCache) GetRemotes() (map[string]string, error)

GetRemotes returns the configured remotes repositories.

func (*RepoCache) GetUserEmail Uses

func (c *RepoCache) GetUserEmail() (string, error)

GetUserEmail returns the email address that the user has used to configure git.

func (*RepoCache) GetUserIdentity Uses

func (c *RepoCache) GetUserIdentity() (*IdentityCache, error)

func (*RepoCache) GetUserIdentityExcerpt Uses

func (c *RepoCache) GetUserIdentityExcerpt() (*IdentityExcerpt, error)

func (*RepoCache) GetUserName Uses

func (c *RepoCache) GetUserName() (string, error)

GetUserName returns the name the the user has used to configure git

func (*RepoCache) GlobalConfig Uses

func (c *RepoCache) GlobalConfig() repository.Config

GlobalConfig give access to the git global configuration

func (*RepoCache) IsUserIdentitySet Uses

func (c *RepoCache) IsUserIdentitySet() (bool, error)

func (*RepoCache) LocalConfig Uses

func (c *RepoCache) LocalConfig() repository.Config

LocalConfig give access to the repository scoped configuration

func (*RepoCache) MergeAll Uses

func (c *RepoCache) MergeAll(remote string) <-chan entity.MergeResult

MergeAll will merge all the available remote bug and identities

func (*RepoCache) Name Uses

func (c *RepoCache) Name() string

func (*RepoCache) NewBug Uses

func (c *RepoCache) NewBug(title string, message string) (*BugCache, *bug.CreateOperation, error)

NewBug create a new bug The new bug is written in the repository (commit)

func (*RepoCache) NewBugRaw Uses

func (c *RepoCache) NewBugRaw(author *IdentityCache, unixTime int64, title string, message string, files []repository.Hash, metadata map[string]string) (*BugCache, *bug.CreateOperation, error)

NewBugWithFilesMeta create a new bug with attached files for the message, as well as metadata for the Create operation. The new bug is written in the repository (commit)

func (*RepoCache) NewBugWithFiles Uses

func (c *RepoCache) NewBugWithFiles(title string, message string, files []repository.Hash) (*BugCache, *bug.CreateOperation, error)

NewBugWithFiles create a new bug with attached files for the message The new bug is written in the repository (commit)

func (*RepoCache) NewIdentity Uses

func (c *RepoCache) NewIdentity(name string, email string) (*IdentityCache, error)

NewIdentity create a new identity The new identity is written in the repository (commit)

func (*RepoCache) NewIdentityFromGitUser Uses

func (c *RepoCache) NewIdentityFromGitUser() (*IdentityCache, error)

func (*RepoCache) NewIdentityFromGitUserRaw Uses

func (c *RepoCache) NewIdentityFromGitUserRaw(metadata map[string]string) (*IdentityCache, error)

func (*RepoCache) NewIdentityFull Uses

func (c *RepoCache) NewIdentityFull(name string, email string, login string, avatarUrl string) (*IdentityCache, error)

NewIdentityFull create a new identity The new identity is written in the repository (commit)

func (*RepoCache) NewIdentityRaw Uses

func (c *RepoCache) NewIdentityRaw(name string, email string, login string, avatarUrl string, metadata map[string]string) (*IdentityCache, error)

func (*RepoCache) Pull Uses

func (c *RepoCache) Pull(remote string) error

Pull will do a Fetch + MergeAll This function will return an error if a merge fail

func (*RepoCache) Push Uses

func (c *RepoCache) Push(remote string) (string, error)

Push update a remote with the local changes

func (*RepoCache) QueryBugs Uses

func (c *RepoCache) QueryBugs(q *query.Query) []entity.Id

QueryBugs return the id of all Bug matching the given Query

func (*RepoCache) ReadData Uses

func (c *RepoCache) ReadData(hash repository.Hash) ([]byte, error)

ReadData will attempt to read arbitrary data from the given hash

func (*RepoCache) ResolveBug Uses

func (c *RepoCache) ResolveBug(id entity.Id) (*BugCache, error)

ResolveBug retrieve a bug matching the exact given id

func (*RepoCache) ResolveBugCreateMetadata Uses

func (c *RepoCache) ResolveBugCreateMetadata(key string, value string) (*BugCache, error)

ResolveBugCreateMetadata retrieve a bug that has the exact given metadata on its Create operation, that is, the first operation. It fails if multiple bugs match.

func (*RepoCache) ResolveBugExcerpt Uses

func (c *RepoCache) ResolveBugExcerpt(id entity.Id) (*BugExcerpt, error)

ResolveBugExcerpt retrieve a BugExcerpt matching the exact given id

func (*RepoCache) ResolveBugExcerptMatcher Uses

func (c *RepoCache) ResolveBugExcerptMatcher(f func(*BugExcerpt) bool) (*BugExcerpt, error)

func (*RepoCache) ResolveBugExcerptPrefix Uses

func (c *RepoCache) ResolveBugExcerptPrefix(prefix string) (*BugExcerpt, error)

ResolveBugExcerptPrefix retrieve a BugExcerpt matching an id prefix. It fails if multiple bugs match.

func (*RepoCache) ResolveBugMatcher Uses

func (c *RepoCache) ResolveBugMatcher(f func(*BugExcerpt) bool) (*BugCache, error)

func (*RepoCache) ResolveBugPrefix Uses

func (c *RepoCache) ResolveBugPrefix(prefix string) (*BugCache, error)

ResolveBugPrefix retrieve a bug matching an id prefix. It fails if multiple bugs match.

func (*RepoCache) ResolveIdentity Uses

func (c *RepoCache) ResolveIdentity(id entity.Id) (*IdentityCache, error)

ResolveIdentity retrieve an identity matching the exact given id

func (*RepoCache) ResolveIdentityExcerpt Uses

func (c *RepoCache) ResolveIdentityExcerpt(id entity.Id) (*IdentityExcerpt, error)

ResolveIdentityExcerpt retrieve a IdentityExcerpt matching the exact given id

func (*RepoCache) ResolveIdentityExcerptMatcher Uses

func (c *RepoCache) ResolveIdentityExcerptMatcher(f func(*IdentityExcerpt) bool) (*IdentityExcerpt, error)

func (*RepoCache) ResolveIdentityExcerptPrefix Uses

func (c *RepoCache) ResolveIdentityExcerptPrefix(prefix string) (*IdentityExcerpt, error)

ResolveIdentityExcerptPrefix retrieve a IdentityExcerpt matching an id prefix. It fails if multiple identities match.

func (*RepoCache) ResolveIdentityImmutableMetadata Uses

func (c *RepoCache) ResolveIdentityImmutableMetadata(key string, value string) (*IdentityCache, error)

ResolveIdentityImmutableMetadata retrieve an Identity that has the exact given metadata on one of it's version. If multiple version have the same key, the first defined take precedence.

func (*RepoCache) ResolveIdentityMatcher Uses

func (c *RepoCache) ResolveIdentityMatcher(f func(*IdentityExcerpt) bool) (*IdentityCache, error)

func (*RepoCache) ResolveIdentityPrefix Uses

func (c *RepoCache) ResolveIdentityPrefix(prefix string) (*IdentityCache, error)

ResolveIdentityPrefix retrieve an Identity matching an id prefix. It fails if multiple identities match.

func (*RepoCache) SetUserIdentity Uses

func (c *RepoCache) SetUserIdentity(i *IdentityCache) error

func (*RepoCache) StoreData Uses

func (c *RepoCache) StoreData(data []byte) (repository.Hash, error)

StoreData will store arbitrary data and return the corresponding hash

func (*RepoCache) ValidLabels Uses

func (c *RepoCache) ValidLabels() []bug.Label

ValidLabels list valid labels

Note: in the future, a proper label policy could be implemented where valid labels are defined in a configuration file. Until that, the default behavior is to return the list of labels already used.

Package cache imports 21 packages (graph) and is imported by 12 packages. Updated 2020-07-11. Refresh now. Tools for package owners.