mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-04 19:41:26 -05:00
65edbaabe3
The Dataset.Commit() code pathway still enforces fast-forward-only behavior, but a new SetHead() method allows the HEAD of a Dataset to be forced to any other Commit. noms sync detects the case where the source Commit is not a descendent of the provided sink Dataset's HEAD and uses the new API to force the sink to the desired new Commit, printing out the now-abandoned old HEAD. Fixes #2240
52 lines
1.7 KiB
Go
52 lines
1.7 KiB
Go
// Copyright 2016 Attic Labs, Inc. All rights reserved.
|
|
// Licensed under the Apache License, version 2.0:
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
package datas
|
|
|
|
import (
|
|
"github.com/attic-labs/noms/go/chunks"
|
|
"github.com/attic-labs/noms/go/d"
|
|
"github.com/attic-labs/noms/go/types"
|
|
)
|
|
|
|
// Database provides versioned storage for noms values. Each Database instance represents one moment in history. Heads() returns the Commit from each active fork at that moment. The Commit() method returns a new Database, representing a new moment in history.
|
|
type LocalDatabase struct {
|
|
databaseCommon
|
|
cs chunks.ChunkStore
|
|
}
|
|
|
|
func newLocalDatabase(cs chunks.ChunkStore) *LocalDatabase {
|
|
bs := types.NewBatchStoreAdaptor(cs)
|
|
return &LocalDatabase{
|
|
newDatabaseCommon(newCachingChunkHaver(cs), types.NewValueStore(bs), bs),
|
|
cs,
|
|
}
|
|
}
|
|
|
|
func (lds *LocalDatabase) Commit(datasetID string, commit types.Struct) (Database, error) {
|
|
err := lds.doCommit(datasetID, commit)
|
|
return &LocalDatabase{newDatabaseCommon(lds.cch, lds.vs, lds.rt), lds.cs}, err
|
|
}
|
|
|
|
func (lds *LocalDatabase) Delete(datasetID string) (Database, error) {
|
|
err := lds.doDelete(datasetID)
|
|
return &LocalDatabase{newDatabaseCommon(lds.cch, lds.vs, lds.rt), lds.cs}, err
|
|
}
|
|
|
|
func (lds *LocalDatabase) SetHead(datasetID string, commit types.Struct) (Database, error) {
|
|
err := lds.doSetHead(datasetID, commit)
|
|
return &LocalDatabase{newDatabaseCommon(lds.cch, lds.vs, lds.rt), lds.cs}, err
|
|
}
|
|
|
|
func (lds *LocalDatabase) validatingBatchStore() (bs types.BatchStore) {
|
|
bs = lds.vs.BatchStore()
|
|
if !bs.IsValidating() {
|
|
bs = newLocalBatchStore(lds.cs)
|
|
lds.vs = types.NewValueStore(bs)
|
|
lds.rt = bs
|
|
}
|
|
d.Chk.True(bs.IsValidating())
|
|
return bs
|
|
}
|