Exemplo n.º 1
0
// Commit updates the commit that a dataset points at. The new Commit is constructed using v and the current Head.
// If the update cannot be performed, e.g., because of a conflict, Commit returns an 'ErrMergeNeeded' error and the current snapshot of the dataset so that the client can merge the changes and try again.
func (ds *Dataset) Commit(v types.Value) (Dataset, error) {
	p := datas.NewSetOfRefOfCommit()
	if head, ok := ds.MaybeHead(); ok {
		p = p.Insert(datas.NewRefOfCommit(head.Ref()))
	}
	return ds.CommitWithParents(v, p)
}
Exemplo n.º 2
0
func TestExplicitBranchUsingDatasets(t *testing.T) {
	assert := assert.New(t)
	id1 := "testdataset"
	id2 := "othertestdataset"
	cs := chunks.NewMemoryStore()

	ds1 := newDS(id1, cs)

	// ds1: |a|
	a := types.NewString("a")
	ds1, err := ds1.Commit(a)
	assert.NoError(err)
	assert.True(ds1.Head().Value().Equals(a))

	// ds1: |a|
	//        \ds2
	ds2 := newDS(id2, cs)
	ds2, err = ds2.Commit(ds1.Head().Value())
	assert.NoError(err)
	assert.True(ds2.Head().Value().Equals(a))

	// ds1: |a| <- |b|
	b := types.NewString("b")
	ds1, err = ds1.Commit(b)
	assert.NoError(err)
	assert.True(ds1.Head().Value().Equals(b))

	// ds1: |a|    <- |b|
	//        \ds2 <- |c|
	c := types.NewString("c")
	ds2, err = ds2.Commit(c)
	assert.NoError(err)
	assert.True(ds2.Head().Value().Equals(c))

	// ds1: |a|    <- |b| <--|d|
	//        \ds2 <- |c| <--/
	mergeParents := datas.NewSetOfRefOfCommit().Insert(datas.NewRefOfCommit(ds1.Head().Ref())).Insert(datas.NewRefOfCommit(ds2.Head().Ref()))
	d := types.NewString("d")
	ds2, err = ds2.CommitWithParents(d, mergeParents)
	assert.NoError(err)
	assert.True(ds2.Head().Value().Equals(d))

	ds1, err = ds1.CommitWithParents(d, mergeParents)
	assert.NoError(err)
	assert.True(ds1.Head().Value().Equals(d))
}