diff

package
v0.0.0-...-3afbc18 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2016 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ADD = "+   "
	DEL = "-   "
)

Variables

This section is empty.

Functions

func Diff

func Diff(v1, v2 types.Value, dChan chan<- Difference, stopChan chan struct{}, leftRight bool)

Diff traverses two graphs simultaneously looking for differences. It returns two channels: a DiffReceiveChan that the caller can use to iterate over the diffs in the graph and a StopSendChanel that a caller can use to signal the Diff function to stop processing. Diff returns the Differences in depth-first first order. A 'diff' is defined as one of the following conditions:

  • a Value is Added or Removed from a node in the graph
  • the type of a Value has changed in the graph
  • a primitive (i.e. Bool, Number, String, Ref or Blob) Value has changed

A Difference is not returned when a non-primitive value has been modified. For example, a struct field has been changed from one Value of type Employee to another. Those modifications are accounted for by the Differences described above at a lower point in the graph.

If leftRight is true then the left-right diff is used for ordered sequences - see Diff vs DiffLeftRight in Set and Map.

Note: the function sends messages on diffChan and checks whether stopChan has been closed to know if it needs to terminate diffing early. To function properly it needs to be executed concurrently with code that reads values from diffChan. The following is a typical invocation of Diff():

dChan := make(chan Difference)
sChan := make(chan struct{})
go func() {
    d.Diff(s3, s4, dChan, sChan, leftRight)
    close(dChan)
}()
for dif := range dChan {
    <some code>
}

func PrintDiff

func PrintDiff(w io.Writer, v1, v2 types.Value, leftRight bool) (err error)

PrintDiff writes a textual reprensentation of the diff from |v1| to |v2| to |w|. If |leftRight| is true then the left-right diff is used for ordered sequences - see Diff vs DiffLeftRight in Set and Map.

func Summary

func Summary(value1, value2 types.Value)

Summary prints a summary of the diff between two values to stdout.

Types

type Difference

type Difference struct {
	// Path to the Value that has changed
	Path types.Path
	// ChangeType indicates the type of diff: modified, added, deleted
	ChangeType types.DiffChangeType
	// OldValue is Value before the change, can be nil if Value was added
	OldValue types.Value
	// NewValue is Value after the change, can be nil if Value was removed
	NewValue types.Value
}

Difference represents a "diff" between two Noms graphs.

Jump to

Keyboard shortcuts

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