parse

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package parse wraps go-gitdiff. We expose a minimal struct surface (`Diff` / `File` / `Hunk` / `Line`) so the renderer doesn't depend on the upstream type names — keeps the option to swap libraries later if go-gitdiff evolves in an uncomfortable direction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Diff

type Diff struct {
	Files []File
}

Diff is the top-level result of parsing a unified-diff stream.

func Parse

func Parse(r io.Reader) (*Diff, error)

Parse consumes a unified diff stream into the typed shape. The readSrc may be a bytes.Reader or any other io.Reader; we don't enforce a max-size cap here — caller decides.

func ParseBytes

func ParseBytes(b []byte) (*Diff, error)

ParseBytes is a convenience for the common case of having the patch as a single buffer.

type File

type File struct {
	OldPath  string
	NewPath  string
	OldMode  string
	NewMode  string
	IsBinary bool
	IsNew    bool
	IsDelete bool
	IsRename bool
	IsCopy   bool
	Hunks    []Hunk
	// Score is the rename/copy similarity (0–100) when IsRename or IsCopy.
	Score int
	// IsTooLarge marks files past the per-file render threshold; the
	// renderer emits a "too large" placeholder + expander link rather
	// than the full hunks.
	IsTooLarge bool
	// SizeBytes is the rough cost of this file's hunks (sum of line
	// content). Used to drive truncation decisions.
	SizeBytes int
}

File is one changed path. OldPath / NewPath differ on rename/copy; they're equal on a normal modify. IsBinary, IsRename, IsCopy, IsNew, IsDelete summarize the extended-header flags so renderers don't reach into the upstream types.

type Hunk

type Hunk struct {
	OldStart int
	OldLines int
	NewStart int
	NewLines int
	Section  string // text after the closing `@@` (function name etc.)
	Lines    []Line
}

Hunk is one `@@ -X,Y +A,B @@` block.

type Line

type Line struct {
	Kind      LineKind
	OldLineNo int    // 0 when the line is a pure addition
	NewLineNo int    // 0 when the line is a pure deletion
	Content   string // without the leading +/-/space marker, no trailing newline
}

Line is one rendered row in a hunk.

type LineKind

type LineKind int

LineKind is the per-line context indicator.

const (
	LineContext LineKind = iota
	LineAdd
	LineDelete
	LineNoNewline // "\ No newline at end of file"
)

Jump to

Keyboard shortcuts

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