mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-31 03:18:43 -06:00
Disambiguate the term "root".
datas.Root(Set) -> datas.Commit(Set) DataStore::Roots() -> DataStore::Heads()
This commit is contained in:
56
datas/commit_cache.go
Normal file
56
datas/commit_cache.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package datas
|
||||
|
||||
import (
|
||||
"github.com/attic-labs/noms/chunks"
|
||||
"github.com/attic-labs/noms/ref"
|
||||
"github.com/attic-labs/noms/types"
|
||||
)
|
||||
|
||||
// commitCache maintains an in-memory cache of all known commits.
|
||||
type commitCache struct {
|
||||
source chunks.ChunkSource
|
||||
refs map[ref.Ref]bool
|
||||
}
|
||||
|
||||
func (cache *commitCache) updateFromCommit(commit Commit) {
|
||||
if _, ok := cache.refs[commit.Ref()]; ok {
|
||||
return
|
||||
}
|
||||
|
||||
parents := commit.Parents()
|
||||
parents.Iter(func(commit types.Value) (stop bool) {
|
||||
cache.updateFromCommit(CommitFromVal(commit))
|
||||
return
|
||||
})
|
||||
cache.refs[commit.Ref()] = true
|
||||
}
|
||||
|
||||
func (cache *commitCache) Update(currentCommits CommitSet) {
|
||||
if currentCommits.Len() == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
commitsRef := currentCommits.Ref()
|
||||
if _, ok := cache.refs[commitsRef]; ok {
|
||||
return
|
||||
}
|
||||
|
||||
commitSet := CommitSet{types.MustReadValue(commitsRef, cache.source).(types.Set)}
|
||||
commitSet.Iter(func(commit Commit) (stop bool) {
|
||||
cache.updateFromCommit(commit)
|
||||
return
|
||||
})
|
||||
cache.refs[commitsRef] = true
|
||||
}
|
||||
|
||||
func (cache *commitCache) Contains(candidate ref.Ref) bool {
|
||||
_, ok := cache.refs[candidate]
|
||||
return ok
|
||||
}
|
||||
|
||||
func NewCommitCache(source chunks.ChunkSource) *commitCache {
|
||||
return &commitCache{
|
||||
source,
|
||||
make(map[ref.Ref]bool),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user