Documentation
¶
Overview ¶
Package diff compares and merges .012 workbooks cell by cell, for 012 diff and 012 merge-driver (see docs/files/git.md). Compare lists what changed between two workbooks: sheets added, removed, renamed or moved, each cell's input, value, format and note, notebook cells, regions, named ranges, macros and the other fields of sheets and workbooks. Merge combines two workbooks changed from a common one, and conflicts only where both changed the same part of the same cell or field.
Both read files as their JSON fields (raw.go), so nothing a file holds goes unseen, and use the engine only to compute formulas' values, which the file doesn't store. Nothing here runs a notebook cell or asks JEV: values come from what the formulas compute alone.
Index ¶
Constants ¶
const ( KindSheet = "sheet" // a sheet added, removed, renamed or moved KindCell = "cell" // a cell's input, value, format or note KindRegion = "region" // a notebook region or linked file KindTable = "table" // a table KindLayout = "layout" // another field of a sheet: widths, rules, charts KindName = "name" // a named range KindMacro = "macro" // a macro KindWorkbook = "workbook" // a field of the workbook: locale, arithmetic )
Kinds of Change.
const KindNotebook = "notebook"
KindNotebook is a Change to a notebook tab's cell: its source, or what its last run left.
Variables ¶
var Formats = []string{"text", "json", "nuon"}
Formats are what WriteChanges writes.
Functions ¶
func Dump ¶
Dump writes a workbook as lines of text, one for each cell and each field, each naming its sheet: what git diffs when 012 diff --textconv is a .012 file's textconv. A formula's line ends with its value, unless it changes on every recalculation (NOW, RAND and what reads them), which would show as a change each time.
Types ¶
type Book ¶
type Book struct {
// contains filtered or unexported fields
}
Book is a workbook read for comparing: its file's fields and the workbook they make.
type Change ¶
type Change struct {
Kind string
Sheet string // the sheet, by its name in the second workbook where it has one
Item string // the cell, region, name, macro or field that changed
// Field is what about it changed: for a cell input, value, format or
// note; for a sheet added, removed, renamed or moved; for a region,
// name or macro added, removed or its field's name; for a layout
// field, its key when it has keys (a column's width), else "".
Field string
Old, New nuon.Value
// contains filtered or unexported fields
}
Change is one difference. Old or New is null where the thing isn't on that side.
type Conflict ¶
type Conflict struct {
Where string // as a Change's: Q3!B7, sheet Q3, Q3 widths, name Sales
Field string // what about it: input, format, note, a field's key, or ""
// Base, Ours and Theirs are the three versions as text, "" where
// the thing isn't there; What says what happened instead, when the
// conflict is about a whole sheet.
Base, Ours, Theirs string
What string
}
Conflict is a part of a workbook both sides changed differently. The merge keeps ours; the report says what theirs had.
func Merge ¶
Merge combines ours and theirs, two workbook files changed from base, and returns the merged file as 012 saves it. Each cell's input, format and note, each field of a sheet or the workbook (a column's width, a region, a named range, a macro) and each sheet's name and presence merge on their own: a part changed on one side only takes that side's version, and a part both changed alike takes it too. A part both changed differently is a conflict: the merge keeps ours, and a cell's note says what theirs had (on top of its own note), so the conflicts can be found in the grid. Empty contents stand for a missing file.
Sheets are matched by name or, when renamed, by their cells (see matchSheets). Rows or columns inserted on one side shift the cells below or right of them, which a cell-by-cell merge can't tell from edits: merge such changes in 012 rather than here.