Revert "Breaking the direct package dependency from dsess to merge"

This reverts commit 9c65e422cf.
This commit is contained in:
Jason Fulghum
2023-05-22 09:13:01 -07:00
parent 9064f45a5e
commit 100da53873
2 changed files with 16 additions and 77 deletions
@@ -15,7 +15,6 @@
package dsess
import (
"context"
"errors"
"fmt"
"strings"
@@ -28,6 +27,7 @@ import (
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
"github.com/dolthub/dolt/go/libraries/doltcore/env"
"github.com/dolthub/dolt/go/libraries/doltcore/merge"
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
"github.com/dolthub/dolt/go/libraries/doltcore/table/editor"
"github.com/dolthub/dolt/go/store/datas"
@@ -45,24 +45,6 @@ var ErrUnresolvedConstraintViolationsCommit = errors.New("Committing this transa
"Constraint violations from a merge can be resolved using the dolt_constraint_violations table before committing the transaction. " +
"To allow transactions to be committed with constraint violations from a merge or transaction sequencing set @@dolt_force_transaction_commit=1.")
// TransactionRootMerger is used when a Dolt transaction is committed and a working set root needs to be merged with
// a branch HEAD root. This interface decouples the "dsess" package from the "merge" package we need to use the
// merge logic here to create new Dolt commits, but the dsess package is at the bottom of our package dependency stack
// and can't depend on the merge package directly, since the merge package needs to use dsess directly.
type TransactionRootMerger interface {
// MergeRoots three-way merges |ourRoot|, |theirRoot|, and |ancRoot| when creating a new Dolt commit and returns
// the new, merged root. |theirRootIsh| is the hash of their working set or commit. It is used to key any artifacts
// generated by this merge. |ancRootIsh| is similar and is used to retrieve the base value for a conflict.
MergeRoots(ctx context.Context,
ourRoot, theirRoot, ancRoot *doltdb.RootValue,
theirs, ancestor doltdb.Rootish,
opts editor.Options) (*doltdb.RootValue, error)
}
// DefaultTransactionRootMerger holds a reference to the default TransactionRootMerger to use when committing Dolt
// transactions and merging working set roots with a branch HEAD root.
var DefaultTransactionRootMerger TransactionRootMerger
// TODO: remove this
func TransactionsDisabled(ctx *sql.Context) bool {
enabled, err := ctx.GetSessionVariable(ctx, TransactionsDisabledSysVar)
@@ -212,17 +194,19 @@ func doltCommit(ctx *sql.Context,
// updates). The merged root value becomes our new Staged root value which
// is the value which we are trying to commit.
start := time.Now()
result, err := DefaultTransactionRootMerger.MergeRoots(ctx,
result, err := merge.MergeRoots(
ctx,
pending.Roots.Staged,
curRootVal,
pending.Roots.Head,
curHead,
tx.startState,
tx.mergeEditOpts)
tx.mergeEditOpts,
merge.MergeOpts{})
if err != nil {
return nil, nil, err
}
pending.Roots.Staged = result
pending.Roots.Staged = result.Root
// We also need to update the working set to reflect the new staged root value
workingSet = workingSet.WithStagedRoot(pending.Roots.Staged)
@@ -418,31 +402,35 @@ func (tx *DoltTransaction) mergeRoots(
) (*doltdb.WorkingSet, error) {
if !rootsEqual(existingWorkingSet.WorkingRoot(), workingSet.WorkingRoot()) {
result, err := DefaultTransactionRootMerger.MergeRoots(ctx,
result, err := merge.MergeRoots(
ctx,
existingWorkingSet.WorkingRoot(),
workingSet.WorkingRoot(),
tx.startState.WorkingRoot(),
workingSet,
tx.startState,
tx.mergeEditOpts)
tx.mergeEditOpts,
merge.MergeOpts{})
if err != nil {
return nil, err
}
workingSet = workingSet.WithWorkingRoot(result)
workingSet = workingSet.WithWorkingRoot(result.Root)
}
if !rootsEqual(existingWorkingSet.StagedRoot(), workingSet.StagedRoot()) {
result, err := DefaultTransactionRootMerger.MergeRoots(ctx,
result, err := merge.MergeRoots(
ctx,
existingWorkingSet.StagedRoot(),
workingSet.StagedRoot(),
tx.startState.StagedRoot(),
workingSet,
tx.startState,
tx.mergeEditOpts)
tx.mergeEditOpts,
merge.MergeOpts{})
if err != nil {
return nil, err
}
workingSet = workingSet.WithStagedRoot(result)
workingSet = workingSet.WithStagedRoot(result.Root)
}
return workingSet, nil
-49
View File
@@ -1,49 +0,0 @@
// Copyright 2023 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package sqle
import (
"context"
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
"github.com/dolthub/dolt/go/libraries/doltcore/merge"
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
"github.com/dolthub/dolt/go/libraries/doltcore/table/editor"
)
func init() {
// The transaction logic in the dsess package needs to use the merge code when committing, to merge
// staged changes into the current HEAD when creating a new commit. Since the merge package also
// needs the dsess package, we break the package import cycle by setting this interface in dsess
// with a default implementation here that uses the merge package.
dsess.DefaultTransactionRootMerger = &defaultTransactionRootMerger{}
}
type defaultTransactionRootMerger struct{}
var _ dsess.TransactionRootMerger = defaultTransactionRootMerger{}
// MergeRoots implements the dsess.TransactionRootMerger interface.
func (d defaultTransactionRootMerger) MergeRoots(ctx context.Context,
ourRoot, theirRoot, ancRoot *doltdb.RootValue,
theirs, ancestor doltdb.Rootish,
opts editor.Options) (*doltdb.RootValue, error) {
result, err := merge.MergeRoots(ctx, ourRoot, theirRoot, ancRoot, theirs, ancestor, opts, merge.MergeOpts{})
if err != nil {
return nil, err
}
return result.Root, nil
}