diff

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 15 Imported by: 0

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

View Source
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.

View Source
const KindNotebook = "notebook"

KindNotebook is a Change to a notebook tab's cell: its source, or what its last run left.

Variables

View Source
var Formats = []string{"text", "json", "nuon"}

Formats are what WriteChanges writes.

Functions

func Dump

func Dump(w io.Writer, b *Book) error

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.

func WriteChanges

func WriteChanges(w io.Writer, changes []Change, format string, color bool) error

WriteChanges writes changes in format: text, a line each (colored with color), or a table of records with the columns kind, sheet, item, field, old and new as JSON or NUON.

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.

func Read

func Read(data []byte) (*Book, error)

Read reads a workbook file's contents. Empty contents are a workbook without sheets, which is what git hands over for a file that doesn't exist on one side.

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.

func Compare

func Compare(a, b *Book) []Change

Compare lists what changed from a to b: sheets first, then each sheet's cells in row order, a notebook tab's cells, its regions and other fields, then the workbook's names, macros and settings.

func (Change) Where

func (c Change) Where() string

Where names the change's place as the text output does: Q3!B7, sheet Q3, Q3 region r1, Q3 table Sales, Q3 widths, name Sales.

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

func Merge(base, ours, theirs []byte) ([]byte, []Conflict, error)

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.

func (Conflict) String

func (c Conflict) String() string

String is the conflict as the merge report lists it.

Jump to

Keyboard shortcuts

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