Exemplo n.º 1
0
func diffSummaryStructs(ch chan<- diffSummaryProgress, v1, v2 types.Struct) {
	size1 := uint64(v1.Type().Desc.(types.StructDesc).Len())
	size2 := uint64(v2.Type().Desc.(types.StructDesc).Len())
	diffSummaryValueChanged(ch, size1, size2, func(changeChan chan<- types.ValueChanged, stopChan <-chan struct{}) {
		v2.Diff(v1, changeChan, stopChan)
	})
}
Exemplo n.º 2
0
func diffStructs(w io.Writer, p types.Path, v1, v2 types.Struct) {
	changeChan := make(chan types.ValueChanged)
	stopChan := make(chan struct{}, 1) // buffer size of 1, so this won't block if diff already finished

	defer stop(stopChan)
	go func() {
		v2.Diff(v1, changeChan, stopChan)
		close(changeChan)
	}()

	wroteHeader := false

	for change := range changeChan {
		fn := string(change.V.(types.String))
		switch change.ChangeType {
		case types.DiffChangeAdded:
			wroteHeader = writeHeader(w, wroteHeader, p)
			field(w, ADD, change.V, v2.Get(fn))
		case types.DiffChangeRemoved:
			wroteHeader = writeHeader(w, wroteHeader, p)
			field(w, DEL, change.V, v1.Get(fn))
		case types.DiffChangeModified:
			f1 := v1.Get(fn)
			f2 := v2.Get(fn)
			if shouldDescend(f1, f2) {
				diff(w, p.AddField(fn), types.String(fn), f1, f2)
			} else {
				wroteHeader = writeHeader(w, wroteHeader, p)
				field(w, DEL, change.V, f1)
				field(w, ADD, change.V, f2)
			}
		}
	}
	writeFooter(w, wroteHeader)
}
Exemplo n.º 3
0
func diffStructs(w io.Writer, p types.Path, v1, v2 types.Struct) error {
	return diffOrdered(w, p, field, func(cc chan<- types.ValueChanged, sc <-chan struct{}) {
		v2.Diff(v1, cc, sc)
	},
		func(k types.Value) types.Value { return k },
		func(k types.Value) types.Value { return v1.Get(string(k.(types.String))) },
		func(k types.Value) types.Value { return v2.Get(string(k.(types.String))) },
	)
}