github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/libraries/doltcore/env/actions/resolve.go (about) 1 // Copyright 2019 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package actions 16 17 import ( 18 "context" 19 20 "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" 21 "github.com/dolthub/dolt/go/libraries/doltcore/env" 22 "github.com/dolthub/dolt/go/libraries/doltcore/merge" 23 "github.com/dolthub/dolt/go/libraries/doltcore/table/editor" 24 ) 25 26 type AutoResolveStats struct { 27 } 28 29 func AutoResolveAll(ctx context.Context, dEnv *env.DoltEnv, autoResolver merge.AutoResolver) error { 30 root, err := dEnv.WorkingRoot(ctx) 31 32 if err != nil { 33 return err 34 } 35 36 tbls, err := root.TablesInConflict(ctx) 37 38 if err != nil { 39 return err 40 } 41 42 return autoResolve(ctx, dEnv, root, autoResolver, tbls) 43 } 44 45 func AutoResolveTables(ctx context.Context, dEnv *env.DoltEnv, autoResolver merge.AutoResolver, tbls []string) error { 46 root, err := dEnv.WorkingRoot(ctx) 47 48 if err != nil { 49 return err 50 } 51 52 return autoResolve(ctx, dEnv, root, autoResolver, tbls) 53 } 54 55 func autoResolve(ctx context.Context, dEnv *env.DoltEnv, root *doltdb.RootValue, autoResolver merge.AutoResolver, tbls []string) error { 56 tableEditSession := editor.CreateTableEditSession(root, editor.TableEditSessionProps{}) 57 58 for _, tblName := range tbls { 59 tbl, ok, err := root.GetTable(ctx, tblName) 60 61 if err != nil { 62 return err 63 } 64 65 if !ok { 66 return doltdb.ErrTableNotFound 67 } 68 69 err = merge.ResolveTable(ctx, root.VRW(), tblName, tbl, autoResolver, tableEditSession) 70 71 if err != nil { 72 return err 73 } 74 } 75 76 newRoot, err := tableEditSession.Flush(ctx) 77 if err != nil { 78 return err 79 } 80 81 return dEnv.UpdateWorkingRoot(ctx, newRoot) 82 }