gitmap

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package gitmap turns a unified diff into a deterministic old->new line mapping.

Text matching can only guess where a span went, and it guesses badly when the same code appears more than once in a file. A diff knows exactly: if git says twelve lines were inserted above a span, the span moved down twelve lines. This package extracts that answer so resolution can use it before falling back to similarity scoring.

Diffs are expected to be generated with -U0. Zero context means every hunk is purely added and removed lines, so a line is either inside a changed region or cleanly outside one, with no context lines to disambiguate.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LineMap

type LineMap struct {
	// contains filtered or unexported fields
}

LineMap maps line numbers from the "old" side of a diff to the "new" side. The zero value maps every line to itself, which is the correct behaviour for an unchanged file.

func Parse

func Parse(diff string) *LineMap

Parse reads the hunk headers of a unified diff. Content lines are ignored; with -U0 the headers alone fully describe the mapping.

func (*LineMap) MapLine

func (m *LineMap) MapLine(old int) (int, bool)

MapLine returns where a 1-based old line number ended up. It reports false when the line fell inside a region the diff deleted, meaning the line no longer exists and no honest mapping is possible.

func (*LineMap) MapRange

func (m *LineMap) MapRange(startLine, endLine int) (int, int, bool)

MapRange maps both ends of a span. It reports false unless both ends survive and the span stays well-formed, so a partially deleted range is rejected rather than silently shrunk to something the note never described.

func (*LineMap) Unchanged

func (m *LineMap) Unchanged() bool

Unchanged reports whether the diff contained no changes at all.

Jump to

Keyboard shortcuts

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