github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/libraries/doltcore/doltdb/conflict.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 doltdb
    16  
    17  import "github.com/dolthub/dolt/go/store/types"
    18  
    19  type Conflict struct {
    20  	Base       types.Value
    21  	Value      types.Value
    22  	MergeValue types.Value
    23  }
    24  
    25  func NewConflict(base, value, mergeValue types.Value) Conflict {
    26  	if base == nil {
    27  		base = types.NullValue
    28  	}
    29  	if value == nil {
    30  		value = types.NullValue
    31  	}
    32  	if mergeValue == nil {
    33  		mergeValue = types.NullValue
    34  	}
    35  	return Conflict{base, value, mergeValue}
    36  }
    37  
    38  func ConflictFromTuple(tpl types.Tuple) (Conflict, error) {
    39  	base, err := tpl.Get(0)
    40  
    41  	if err != nil {
    42  		return Conflict{}, err
    43  	}
    44  
    45  	val, err := tpl.Get(1)
    46  
    47  	if err != nil {
    48  		return Conflict{}, err
    49  	}
    50  
    51  	mv, err := tpl.Get(2)
    52  
    53  	if err != nil {
    54  		return Conflict{}, err
    55  	}
    56  	return Conflict{base, val, mv}, nil
    57  }
    58  
    59  func (c Conflict) ToNomsList(vrw types.ValueReadWriter) (types.Tuple, error) {
    60  	return types.NewTuple(vrw.Format(), c.Base, c.Value, c.MergeValue)
    61  }