gitdiff

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: GPL-3.0 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 gitdiff parses the patch output of

git log -p -U0 --no-renames --format=%x00%H%x00%ct%x00%aN%x00%P

into per-commit, per-file hunks. Unlike internal/parser, which only sees numstat line counts, this keeps the text of every added and deleted line, for analyses that need to know *which* lines changed (e.g. rework).

Index

Constants

View Source
const Format = "%x00%H%x00%ct%x00%aN%x00%P"

Format is the --format string Parse expects. Each field is prefixed with a NUL byte, which git never emits at the start of a diff line (a file whose content contains NUL is treated as binary), so a header line can never be confused with patch content.

Variables

This section is empty.

Functions

func Parse

func Parse(r io.Reader) iter.Seq2[Commit, error]

Parse streams commits from r. Iteration stops at the first error, which is yielded with a zero Commit.

Types

type Commit

type Commit struct {
	Rev     string
	Time    time.Time // committer date
	Author  string
	Parents []string
	Files   []FileDiff
}

Commit is one commit's patch.

type FileDiff

type FileDiff struct {
	Path    string
	Removed bool // the file was deleted
	Binary  bool // git reported "Binary files ... differ"; Hunks is empty
	Hunks   []Hunk
}

FileDiff is the change to one path within a commit.

type Hunk

type Hunk struct {
	OldStart int
	NewStart int
	Deleted  []string
	Added    []string
}

Hunk is one zero-context (-U0) hunk. OldStart/NewStart follow git's unified-diff convention: when a side has no lines, its start is the line *after which* the change applies (0 for the top of the file).

Jump to

Keyboard shortcuts

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