diff

package
v1.94.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package diff parses unified diff text to build line mappings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Line

type Line struct {
	Type    LineType
	OldLine int // 0 if added
	NewLine int // 0 if removed
}

Line represents a single line in a diff hunk.

func Parse

func Parse(diffText string) []Line

Parse parses a unified diff fragment (the "diff" field from GitLab API) and returns a list of Line entries.

type LineType

type LineType int

LineType describes what happened to a line.

const (
	Unchanged LineType = iota
	Added
	Removed
)

func FindNewLine

func FindNewLine(lines []Line, target int) (int, LineType, error)

FindNewLine looks up a new-side line number in the parsed lines and returns the corresponding old line number and the line type. Returns an error if the line is not found in the diff.

func FindOldLine

func FindOldLine(lines []Line, target int) (int, LineType, error)

FindOldLine looks up an old-side line number in the parsed lines and returns the corresponding new line number and the line type.

Jump to

Keyboard shortcuts

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