diff

package
v0.24.2 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package diff is the parsed pr.diff that both location validation and the review interface read.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NextMarker

func NextMarker(lines []ViewLine, from int) int

NextMarker returns the index of the first marked line after from, wrapping to the start, or -1 when none is marked.

func PrevMarker

func PrevMarker(lines []ViewLine, from int) int

PrevMarker returns the index of the last marked line before from, wrapping to the end, or -1 when none is marked.

func WholeFile

func WholeFile(path string, content []byte) []byte

WholeFile writes content as one new-file diff section under the display path, in git's own form. Empty content gets the header with no hunk, as git shows for an empty new file.

Types

type Diff

type Diff struct {
	Files []*File

	// Outline is set only by add and edit, which load it when an input carries a heading anchor.
	Outline Outline
	// contains filtered or unexported fields
}

func Parse

func Parse(data []byte) (*Diff, error)

func (*Diff) File

func (d *Diff) File(path string) *File

File finds a file by its new name, or by its old name when the file was deleted.

func (*Diff) FileView

func (d *Diff) FileView(path string, right, left map[int][]string) ([]ViewLine, error)

FileView returns every hunk of the file, each preceded by a separator. right and left map line numbers on each side to the finding ids anchored there; a context line exists on both sides and collects from both.

func (*Diff) HunkFor

func (d *Diff) HunkFor(path, side string, line int) (*File, *Hunk, error)

HunkFor finds the file and the hunk holding line on side, refusing like Validate when there is none.

func (*Diff) HunkView

func (d *Diff) HunkView(path, side string, line, startLine, context int) ([]ViewLine, error)

HunkView returns the hunk holding line on side, trimmed to context lines before the first and after the last anchored line. Anchored lines are those numbered startLine through line on side; startLine is 0 for one line.

func (*Diff) ResolveHeading

func (d *Diff) ResolveHeading(path, text string) (startLine, line int, err error)

ResolveHeading turns a heading anchor into the range of the one hunk that changes the heading's section, as Validate accepts it: startLine is 0 for a single line. It reads d.Outline, never the clone.

func (*Diff) Validate

func (d *Diff) Validate(path, side string, line, startLine int) error

Validate checks a comment location against the stored diff; startLine is 0 when the location is a single line.

type File

type File struct {
	OldName  string
	NewName  string
	IsNew    bool
	IsDelete bool
	IsBinary bool
	Hunks    []*Hunk
	// contains filtered or unexported fields
}

func (*File) LineAt

func (f *File) LineAt(side string, n int) (*Hunk, *Line, bool)

LineAt finds the line numbered n on side RIGHT (new file) or LEFT (old file). Indexes are built on first use because a large diff has many files the caller never looks at.

type Hunk

type Hunk struct {
	OldStart int
	OldLines int
	NewStart int
	NewLines int
	Lines    []Line
}

type Kind

type Kind int
const (
	Context Kind = iota
	Add
	Delete
)

type Line

type Line struct {
	Kind   Kind
	OldNum int
	NewNum int
	Text   string
}

Line numbers are zero on the side where the line does not exist: OldNum for Add, NewNum for Delete.

type Outline

type Outline map[string][]markdown.Heading

Outline maps each Markdown file capture outlined to its headings at the head. A nil Outline is a run captured before heading anchors, which has no outline file; a run whose diff changes no Markdown file has an empty one.

type ViewLine

type ViewLine struct {
	Line
	Separator bool
	Anchored  bool
	Markers   []string
}

ViewLine is one row of a hunk or file view. A separator row carries only the hunk header in Text.

Jump to

Keyboard shortcuts

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