resources: Add proper edge compare method

Might as well do this cleanly in one place.
This commit is contained in:
James Shubin
2017-05-31 17:20:54 -04:00
parent 6e503cc79b
commit 14c2fd1edd
3 changed files with 19 additions and 3 deletions

View File

@@ -495,7 +495,7 @@ func (obj *Main) Run() error {
edgeCmpFn := func(e1, e2 pgraph.Edge) (bool, error) {
edge1 := e1.(*resources.Edge) // panic if wrong
edge2 := e2.(*resources.Edge) // panic if wrong
return edge1.Name == edge2.Name && edge1.Notify == edge2.Notify, nil // simple cmp
return edge1.Compare(edge2), nil
}
// on success, this updates the receiver graph...
if err := oldGraph.GraphSync(newGraph, vertexCmpFn, vertexAddFn, vertexRemoveFn, edgeCmpFn); err != nil {

View File

@@ -146,6 +146,7 @@ func (ag *baseGrouper) vertexMerge(v1, v2 pgraph.Vertex) (v pgraph.Vertex, err e
}
func (ag *baseGrouper) edgeMerge(e1, e2 pgraph.Edge) pgraph.Edge {
// FIXME: should we merge the edge.Notify or edge.refresh values?
return e1 // noop
}

View File

@@ -30,6 +30,21 @@ func (obj *Edge) String() string {
return obj.Name
}
// Compare returns true if two edges are equivalent. Otherwise it returns false.
func (obj *Edge) Compare(edge *Edge) bool {
if obj.Name != edge.Name {
return false
}
if obj.Notify != edge.Notify {
return false
}
// FIXME: should we compare this as well?
//if obj.refresh != edge.refresh {
// return false
//}
return true
}
// Refresh returns the pending refresh status of this edge.
func (obj *Edge) Refresh() bool {
return obj.refresh