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 ¶
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 ¶
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.