merger

package
v0.0.0-...-0f3d56e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoResolveConflicts

func AutoResolveConflicts(conflicts map[string]MergeConflict, resolverName string) (map[string]MergeSolution, error)

AutoResolveConflicts resolves mergeConflicts using the resolver indicated by resolverName.

func PrepareDatabasesPostMerge

func PrepareDatabasesPostMerge(merged *model.Database) error

PrepareDatabasesPostMerge bundles function calls that check the integrity of the merged database and does some post-cleanup

func PrepareDatabasesPreMerge

func PrepareDatabasesPreMerge(left *model.Database, right *model.Database)

PrepareDatabasesPreMerge bundles function calls that are necessary for preparing the databases before merging.

func SolveConflictByChoosingLeft

func SolveConflictByChoosingLeft(conflicts map[string]MergeConflict) (map[string]MergeSolution, error)

SolveConflictByChoosingLeft solves a MergeConflict by always choosing the left side

func SolveConflictByChoosingNewest

func SolveConflictByChoosingNewest(conflicts map[string]MergeConflict) (map[string]MergeSolution, error)

SolveConflictByChoosingNewest solves a MergeConflict by always choosing the newest entry, which is detected by the `LastModified` field. It returns an error if the field does not exist

func SolveConflictByChoosingRight

func SolveConflictByChoosingRight(conflicts map[string]MergeConflict) (map[string]MergeSolution, error)

SolveConflictByChoosingRight solves a MergeConflict by always choosing the right side

func UpdateLRIDs

func UpdateLRIDs(left interface{}, right interface{}, IDName string, changes IDChanges)

UpdateLRIDs updates a given ID (named by IDName) on the left and right slices of *model.Model according to the given IDChanges.

Types

type IDChanges

type IDChanges struct {
	Left  map[int]int
	Right map[int]int
}

IDChanges represents the changed ids of two slices of a model type after a merge has happened, so dependent objects can be updated accordingly. So if the ID of an object of the left slice changed from id 5 to 20, it will be represented as: {5: 20}.

func MergeBookmarks

func MergeBookmarks(left []*model.Bookmark, right []*model.Bookmark, conflictSolution map[string]MergeSolution) ([]*model.Bookmark, IDChanges, error)

MergeBookmarks tries to merge the left and right slices of Bookmarks. If there is a collision, it returns an error asking for specification how it should handle it.

func MergeInputFields

func MergeInputFields(left []*model.InputField, right []*model.InputField, conflictSolution map[string]MergeSolution) ([]*model.InputField, IDChanges, error)

MergeInputFields tries to merge the left and right slice of InputField. If there is a collision, it returns an error asking for specification how it should handle it.

func MergeLocations

func MergeLocations(left []*model.Location, right []*model.Location) ([]*model.Location, IDChanges, error)

MergeLocations merges two slices of Location into one and returns the merged locations together with a IDChanges struct indicating if the ID of a location has changed.

func MergeNotes

func MergeNotes(left []*model.Note, right []*model.Note, conflictSolution map[string]MergeSolution) ([]*model.Note, IDChanges, error)

MergeNotes tries to merge the left and right slice of Note. If there is a collision, it returns an error asking for specification how it should handle it.

func MergeTagMaps

func MergeTagMaps(left []*model.TagMap, right []*model.TagMap, conflictSolution map[string]MergeSolution) ([]*model.TagMap, IDChanges, error)

MergeTagMaps merges a left and right slice of TagMap. It automatically removes redundant entries and also makes sure that the position-order stays similar.

func MergeTags

func MergeTags(left []*model.Tag, right []*model.Tag, conflictSolution map[string]MergeSolution) ([]*model.Tag, IDChanges, error)

MergeTags tries to merge the left and right slice of Tag. If there is a collision, it returns an error asking for specification how it should handle it.

func MergeUserMarkAndBlockRange

func MergeUserMarkAndBlockRange(leftUM []*model.UserMark, leftBR []*model.BlockRange,
	rightUM []*model.UserMark, rightBR []*model.BlockRange,
	conflictSolution map[string]MergeSolution) ([]*model.UserMark, []*model.BlockRange, IDChanges, error)

MergeUserMarkAndBlockRange joins UserMarks and BlockRanges from both sides and tries to merge them. Afterwards it will update the IDs of UserMark and BlockRange and returns them separately againg. If there is a collision, it will try to solve it using duplicate detection and - if that fails - returns an error asking for specification how it should handle it. MergeConflicts will be returned as a joined UserMarkBlockRange struct to make it easier representing conflicts. The returned IDChanges indicate if a UserMarkID has changed in the merge process.

type MergeConflict

type MergeConflict struct {
	Left  model.Model
	Right model.Model
}

MergeConflict represents two Models that collide because of the same UniqueKey or other similarities.

type MergeConflictError

type MergeConflictError struct {
	Err       string
	Conflicts map[string]MergeConflict
}

MergeConflictError indicates that a conflict happened while trying to merge two slices of Model. It contains the conflicts in order for the caller to solve them.

func (MergeConflictError) Error

func (e MergeConflictError) Error() string

type MergeConflictSolver

type MergeConflictSolver func(map[string]MergeConflict) (map[string]MergeSolution, error)

MergeConflictSolver describes a function that is able to handle mergeConflicts semi-automatic

type MergeSide

type MergeSide string

MergeSide indicates the side of a merge

const (
	// LeftSide is the left side of a merge
	LeftSide MergeSide = "leftSide"
	// RightSide is the right side of a merge
	RightSide MergeSide = "rightSide"
)

type MergeSolution

type MergeSolution struct {
	Side      MergeSide
	Solution  model.Model
	Discarded model.Model
}

MergeSolution indicates wheter a entry came from the left or right side of a to-be-merged model slice pair.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL