github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/api/models/synchronization/conflict.go (about) 1 package synchronization 2 3 import ( 4 "github.com/mutagen-io/mutagen/pkg/synchronization/core" 5 ) 6 7 // Conflict represents a filesystem change conflict. 8 type Conflict struct { 9 // Root is the root path for the conflict, relative to the synchronization 10 // root. 11 Root string `json:"root"` 12 // AlphaChanges are the relevant changes on alpha. 13 AlphaChanges []Change `json:"alphaChanges"` 14 // BetaChanges are the relevant changes on beta. 15 BetaChanges []Change `json:"betaChanges"` 16 } 17 18 // loadFromInternal sets a conflict to match an internal Protocol Buffers 19 // representation. The conflict must be valid. 20 func (c *Conflict) loadFromInternal(conflict *core.Conflict) { 21 // Propagate the conflict root. 22 c.Root = conflict.Root 23 24 // Propagate alpha changes. 25 c.AlphaChanges = make([]Change, len(conflict.AlphaChanges)) 26 for i := 0; i < len(conflict.AlphaChanges); i++ { 27 c.AlphaChanges[i].loadFromInternal(conflict.AlphaChanges[i]) 28 } 29 30 // Propagate beta changes. 31 c.BetaChanges = make([]Change, len(conflict.BetaChanges)) 32 for i := 0; i < len(conflict.BetaChanges); i++ { 33 c.BetaChanges[i].loadFromInternal(conflict.BetaChanges[i]) 34 } 35 } 36 37 // exportConflicts is a convenience function that calls 38 // Conflict.loadFromInternal for a slice of conflicts. 39 func exportConflicts(conflicts []*core.Conflict) []Conflict { 40 // If there are no conflicts, then just return a nil slice. 41 count := len(conflicts) 42 if count == 0 { 43 return nil 44 } 45 46 // Create the resulting slice. 47 results := make([]Conflict, count) 48 for i := 0; i < count; i++ { 49 results[i].loadFromInternal(conflicts[i]) 50 } 51 52 // Done. 53 return results 54 }