compare

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBinaryContent = fmt.Errorf("file contains binary content")

ErrBinaryContent indicates that a file classified as text actually contains binary data and should not be diffed as text.

Functions

This section is empty.

Types

type BinaryDiff

type BinaryDiff struct {
	Symbols  []SymbolChange  `json:"symbols"`
	Sections []SectionChange `json:"sections"`
}

BinaryDiff contains symbol and section differences between two Mach-O binaries.

type DetailResult

type DetailResult struct {
	Kind   FileKind    `json:"kind"`
	Plist  *PlistDiff  `json:"plist,omitempty"`
	Binary *BinaryDiff `json:"binary,omitempty"`
	Text   *TextDiff   `json:"text,omitempty"`
	Dir    *DirSummary `json:"dir,omitempty"`
}

DetailResult holds an on-demand detail diff for a single node.

func Detail

func Detail(result *Result, node *Node) (*DetailResult, error)

Detail computes an on-demand detail diff for a specific node. It reads file content from the sources referenced in the result.

type DiffStatus

type DiffStatus int

DiffStatus represents the diff status of a node.

const (
	Unchanged DiffStatus = iota
	Added
	Removed
	Modified
)

func (DiffStatus) MarshalJSON

func (s DiffStatus) MarshalJSON() ([]byte, error)

func (DiffStatus) String

func (s DiffStatus) String() string

type DirSummary

type DirSummary struct {
	TotalFiles int   `json:"total_files"`
	Added      int   `json:"added"`
	Removed    int   `json:"removed"`
	Modified   int   `json:"modified"`
	Unchanged  int   `json:"unchanged"`
	SizeDelta  int64 `json:"size_delta"`
}

DirSummary holds aggregate statistics for a directory node.

type FileKind

type FileKind int

FileKind represents the detected type of a file.

const (
	KindUnknown FileKind = iota
	KindDirectory
	KindArchive
	KindMachO
	KindPlist
	KindDSYM
	KindText
	KindData // opaque binary data (code signatures, assets, etc.)
)

func (FileKind) MarshalJSON

func (k FileKind) MarshalJSON() ([]byte, error)

func (FileKind) String

func (k FileKind) String() string

type Line

type Line struct {
	Kind    string `json:"kind"` // "context", "added", "removed"
	Content string `json:"content"`
}

Line represents a single line in a diff hunk.

type Mode

type Mode = string

Mode represents a comparison mode.

const (
	ModeTree   Mode = "tree"
	ModeBinary Mode = "binary"
	ModePlist  Mode = "plist"
	ModeText   Mode = "text"
)

type Node

type Node struct {
	Name     string     `json:"name"`
	Path     string     `json:"path"`
	Status   DiffStatus `json:"status"`
	Kind     FileKind   `json:"kind"`
	IsDir    bool       `json:"is_dir"`
	SizeA    int64      `json:"size_a"`
	SizeB    int64      `json:"size_b"`
	Children []*Node    `json:"children,omitempty"`
}

Node represents a single entry in the diff tree.

func (*Node) SizeDelta

func (n *Node) SizeDelta() int64

SizeDelta returns the size difference between B and A.

type PlistChange

type PlistChange struct {
	KeyPath string     `json:"key_path"`
	Status  DiffStatus `json:"status"`
	ValueA  string     `json:"value_a,omitempty"`
	ValueB  string     `json:"value_b,omitempty"`
}

PlistChange represents a single key-path change in a plist diff.

type PlistDiff

type PlistDiff struct {
	Changes []PlistChange `json:"changes"`
}

PlistDiff contains key-level changes between two plists.

type Result

type Result struct {
	PathA   string  `json:"path_a"`
	PathB   string  `json:"path_b"`
	Mode    Mode    `json:"mode"`
	Root    *Node   `json:"root"`
	Summary Summary `json:"summary"`
}

Result is the top-level output of a comparison.

func Compare

func Compare(pathA, pathB, mode Mode) (*Result, error)

Compare runs the appropriate comparison for the given paths and mode. If mode is empty, it is auto-detected from the inputs.

type SectionChange

type SectionChange struct {
	Segment string `json:"segment"`
	Section string `json:"section"`
	SizeA   int64  `json:"size_a"`
	SizeB   int64  `json:"size_b"`
}

SectionChange represents a size change in a Mach-O section.

type Summary

type Summary struct {
	Added     int   `json:"added"`
	Removed   int   `json:"removed"`
	Modified  int   `json:"modified"`
	Unchanged int   `json:"unchanged"`
	SizeDelta int64 `json:"size_delta"`
}

Summary aggregates diff statistics.

func ComputeSummary

func ComputeSummary(root *Node) Summary

ComputeSummary walks the tree and computes aggregate statistics.

type SymbolChange

type SymbolChange struct {
	Name   string     `json:"name"`
	Status DiffStatus `json:"status"`
}

SymbolChange represents a symbol that was added or removed.

type TextDiff

type TextDiff struct {
	Hunks []TextHunk `json:"hunks"`
}

TextDiff contains a unified diff between two text files.

type TextHunk

type TextHunk struct {
	OldStart int    `json:"old_start"`
	OldCount int    `json:"old_count"`
	NewStart int    `json:"new_start"`
	NewCount int    `json:"new_count"`
	Lines    []Line `json:"lines"`
}

TextHunk represents a single hunk in a unified diff.

Jump to

Keyboard shortcuts

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