func main() { flag.Usage = func() { fmt.Fprintln(os.Stderr, "Shows the difference between two objects\n") fmt.Fprintln(os.Stderr, "Usage: noms diff <object1> <object2>\n") flag.PrintDefaults() fmt.Fprintf(os.Stderr, "\nSee \"Spelling Objects\" at https://github.com/attic-labs/noms/blob/master/doc/spelling.md for details on the object argument.\n\n") } flag.Parse() if *showHelp { flag.Usage() return } if len(flag.Args()) != 2 { util.CheckError(errors.New("expected exactly two arguments")) } db1, value1, err := spec.GetPath(flag.Arg(0)) util.CheckError(err) defer db1.Close() db2, value2, err := spec.GetPath(flag.Arg(1)) util.CheckError(err) defer db2.Close() waitChan := outputpager.PageOutput(!*outputpager.NoPager) diff.Diff(os.Stdout, value1, value2) fmt.Fprintf(os.Stdout, "\n") if waitChan != nil { os.Stdout.Close() <-waitChan } }
func writeDiffLines(node LogNode, db datas.Database, maxLines, lineno int, w io.Writer) (lineCnt int, err error) { mlw := &maxLineWriter{numLines: lineno, maxLines: maxLines, node: node, dest: w, needsPrefix: true} parents := node.commit.Get(datas.ParentsField).(types.Set) var parent types.Value = nil if parents.Len() > 0 { parent = parents.First() } if parent == nil { _, err = fmt.Fprint(mlw, "\n") return 1, err } parentCommit := parent.(types.Ref).TargetValue(db).(types.Struct) err = diff.Diff(mlw, parentCommit.Get(datas.ValueField), node.commit.Get(datas.ValueField)) if err != nil { mlw.forceWrite([]byte("...\n")) mlw.numLines++ err = nil } if !node.lastCommit { mlw.forceWrite([]byte("\n")) } return mlw.numLines, err }