compare

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: Apache-2.0 Imports: 31 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

func IsGitRepo added in v0.6.0

func IsGitRepo() bool

IsGitRepo returns true if the current working directory is inside a git repository.

func ResolveGitRef added in v0.6.0

func ResolveGitRef(ref string) (string, error)

ResolveGitRef validates and resolves a git ref to its full SHA.

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"`
	Image  *ImageDiff  `json:"image,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
	KindImage // image files (png, jpg, gif, etc.)
	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 GitCommitInfo added in v0.6.0

type GitCommitInfo struct {
	SHA     string `json:"sha"`
	Subject string `json:"subject"`
	Body    string `json:"body,omitempty"`
	Author  string `json:"author"`
	Date    string `json:"date"`
	Ref     string `json:"ref"` // original ref (branch name, tag, HEAD, etc.)
	Remote  string `json:"remote,omitempty"`
}

GitCommitInfo holds metadata for a single git commit.

func (*GitCommitInfo) CommitURL added in v0.6.0

func (c *GitCommitInfo) CommitURL() string

CommitURL returns the web URL for viewing a commit, or empty if unavailable.

func (*GitCommitInfo) PRNumber added in v0.6.0

func (c *GitCommitInfo) PRNumber() string

PRNumber extracts a pull request number from the commit subject if it follows the squash-merge "(#1234)" convention used by GitHub.

func (*GitCommitInfo) PRURL added in v0.6.0

func (c *GitCommitInfo) PRURL() string

PRURL returns the web URL for viewing the pull request, or empty if unavailable.

type GitMeta added in v0.6.0

type GitMeta struct {
	CommitA *GitCommitInfo `json:"commit_a,omitempty"`
	CommitB *GitCommitInfo `json:"commit_b,omitempty"`
}

GitMeta holds git-specific metadata for the comparison.

func BuildGitMeta added in v0.6.0

func BuildGitMeta(refA, refB string) *GitMeta

BuildGitMeta constructs GitMeta for two refs.

type ImageDiff added in v0.5.0

type ImageDiff struct {
	WidthA  int `json:"width_a"`
	HeightA int `json:"height_a"`
	WidthB  int `json:"width_b"`
	HeightB int `json:"height_b"`

	FormatA string `json:"format_a"`
	FormatB string `json:"format_b"`

	ColorModelA string `json:"color_model_a"`
	ColorModelB string `json:"color_model_b"`

	// Pixel diff stats (only populated when dimensions match).
	PixelsChanged int     `json:"pixels_changed"`
	PixelsTotal   int     `json:"pixels_total"`
	ChangePercent float64 `json:"change_percent"`

	// Bounding box of changed region.
	ChangeBounds image.Rectangle `json:"change_bounds"`

	// Decoded images for TUI rendering (not serialized).
	ImageA image.Image `json:"-"`
	ImageB image.Image `json:"-"`
	// DiffMask highlights changed pixels (nil when dimensions differ).
	DiffMask image.Image `json:"-"`
}

ImageDiff holds the result of comparing two images.

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"
	ModeImage  Mode = "image"
	ModeGit    Mode = "git"
)

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"`
	Git     *GitMeta `json:"git,omitempty"`
}

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.

func CompareGitWorkTree added in v0.6.0

func CompareGitWorkTree() (*Result, error)

CompareGitWorkTree builds a diff tree of uncommitted changes against HEAD.

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