Help us shape the future of Go! Take the 2026 Go Developer Survey

source

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package source produces raw git-diff patch bytes for the parser. Three flavors:

  • FromCommit — commit-vs-parent (for the single-commit page)
  • FromRange — base..head two-dot (for compare-style diffs)
  • FromMergeBase — base...head three-dot (for PR / compare against the merge-base; matches GitHub's PR file-list behavior)

Each function returns the unified-diff bytes; the parser package consumes from there. Whitespace-ignoring requested via Options.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromCommit

func FromCommit(ctx context.Context, gitDir, sha string, opts Options) ([]byte, error)

FromCommit returns the diff between sha and its first parent. For a root commit (no parent) we diff against the empty tree by using `git diff-tree -p -r --root`.

func FromMergeBase

func FromMergeBase(ctx context.Context, gitDir, base, head string, opts Options) ([]byte, error)

FromMergeBase returns the three-dot diff base...head. Equivalent to `git diff $(git merge-base base head)..head`. Used by PR / compare pages — shows only what `head` adds over the common ancestor.

func FromRange

func FromRange(ctx context.Context, gitDir, base, head string, opts Options) ([]byte, error)

FromRange returns the two-dot diff base..head. Use for "show me every change between these two refs", regardless of merge graph.

Types

type Options

type Options struct {
	IgnoreWhitespace bool
	// FindRenames toggles -M (--find-renames). Default off matches
	// historical git behavior; the package's helpers turn it on for
	// the rendered surfaces because rename detection is what users
	// expect on a code-review page.
	FindRenames bool
}

Options tunes a diff source. IgnoreWhitespace passes -w to git so whitespace-only lines vanish from the patch (cleaner UX than parser- side filtering, and git's whitespace handling respects language quirks like indentation-sensitive Python).

Jump to

Keyboard shortcuts

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