gitdiff

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 9 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 gitdiff answers which lines of a checkout differ from a ref.

It exists for `kivgraph impact`, which maps changed lines onto the symbols of the graph. It runs git rather than reimplementing it, because the question "what changed since this ref" has rules -- renames, binary files, untracked files -- that git already knows, and it reads the answer in the one form that does not depend on them: the line ranges of the new side of each hunk.

Index

Constants

View Source
const WholeFile = int(^uint(0) >> 1)

WholeFile is the end of a range that covers a file whatever its length.

Variables

View Source
var ErrUnknownRef = errors.New("unknown ref")

ErrUnknownRef is returned when the ref names no commit.

Functions

func Root

func Root(ctx context.Context, directory string) (string, error)

Root answers the top of the checkout that contains directory.

Types

type Change

type Change struct {
	// Path is slash-separated and relative to the checkout root.
	Path string
	// Deleted says the file no longer exists: its lines are gone and there is
	// nothing in the working tree to map them onto.
	Deleted bool
	// Ranges are the lines that differ. A file that is new, or untracked, is one
	// range over every line.
	Ranges []Range
	// Untracked says git has never been told about the file. Whatever the
	// graph does not hold of those is not a change anyone made: a build
	// directory, a tool's own state.
	Untracked bool
}

Change is one file that differs from the ref.

type Diff

type Diff struct {
	// BaseCommit is the commit the ref names, spelled in full.
	BaseCommit string
	Changes    []Change
}

Diff is the answer for one ref.

func Compare

func Compare(ctx context.Context, root, ref string) (Diff, error)

Compare lists what differs between ref and the working tree of the checkout at root: tracked files as they are on disk, staged or not, and untracked files that are not ignored.

type Range

type Range struct {
	Start, End int
	Between    bool
}

Range is a run of lines of the working tree, 1-based and inclusive.

Between marks a change that removed lines and added none: it sits between Start and End -- two neighbouring lines of the new file -- and belongs to a symbol only when that symbol holds both of them. A deletion between two functions touches neither.

func (Range) Overlaps

func (changed Range) Overlaps(first, last int) bool

Overlaps reports whether the lines first..last of a symbol are touched by the range.

Jump to

Keyboard shortcuts

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