gitdiff

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSagaPath

func IsSagaPath(path string) bool

func Key

func Key(atom Atom) string

func VerifyRepository

func VerifyRepository(ctx context.Context, repo, declared string) error

VerifyRepository confirms the checkout identity when its file path or origin provides enough information to do so.

Types

type Atom

type Atom struct {
	Key     string `json:"key"`
	URI     string `json:"uri"`
	Kind    string `json:"kind"`
	Path    string `json:"path,omitempty"`
	Side    string `json:"side,omitempty"`
	Line    int    `json:"line,omitempty"`
	Content string `json:"content"`
	Event   string `json:"event,omitempty"`
	OldPath string `json:"old_path,omitempty"`
	NewPath string `json:"new_path,omitempty"`
}

Atom is the smallest independently coverable unit of a comparison. Kind discriminates the shape: a "line" atom always carries path, side, line, and content; an "event" atom always carries event. Content is emitted even when the changed line is empty, so a consumer can read it unconditionally instead of having to distinguish a blank line from an absent field.

func Parse

func Parse(patch []byte) ([]Atom, error)

type Catalog added in v0.0.8

type Catalog struct {
	Repository string        `json:"repository"`
	Base       string        `json:"base"`
	Head       string        `json:"head"`
	BaseOID    string        `json:"base_oid"`
	HeadOID    string        `json:"head_oid"`
	HeadCommit string        `json:"head_commit"`
	Files      []FileSummary `json:"files"`
}

Catalog is the bounded source-comparison identity and changed-file list used by review navigation. It deliberately contains no patch bodies or per-line atoms: opening Code can therefore enumerate files without constructing the complete comparison first.

func ReadCatalog added in v0.0.8

func ReadCatalog(ctx context.Context, fromDir, repositoryURI, base, head string) (Catalog, error)

ReadCatalog resolves the exact same comparison identity as Read while asking Git only for NUL-delimited per-file statistics. Its memory use is therefore proportional to changed files rather than changed lines.

func ReadCatalogWithOptions added in v0.0.8

func ReadCatalogWithOptions(ctx context.Context, fromDir, repositoryURI, base, head string, options ReadOptions) (Catalog, error)

type ChangeSet

type ChangeSet struct {
	Repository  string `json:"repository"`
	Base        string `json:"base"`
	Head        string `json:"head"`
	BaseOID     string `json:"base_oid"`
	HeadOID     string `json:"head_oid"`
	Atoms       []Atom `json:"atoms"`
	SagaChanges []Atom `json:"saga_changes"`
	// DisplayLines contains bounded unchanged context alongside changed atoms.
	// It is renderer-only: coverage and persisted diff identity continue to use
	// Atoms exclusively.
	DisplayLines []DisplayLine `json:"-"`
}

func Read

func Read(ctx context.Context, fromDir, repositoryURI, base, head string) (ChangeSet, error)

func ReadFile added in v0.0.8

func ReadFile(ctx context.Context, fromDir string, catalog Catalog, file FileSummary) (ChangeSet, error)

ReadFile emits and parses only one catalog entry. The catalog supplies the already-hashed comparison identity, while both rename paths are passed to Git so the focused patch preserves the whole-comparison file identity.

func ReadWithOptions

func ReadWithOptions(ctx context.Context, fromDir, repositoryURI, base, head string, options ReadOptions) (ChangeSet, error)

type DisplayLine

type DisplayLine struct {
	Kind    string
	Path    string
	OldLine int
	NewLine int
	Content string
	AtomKey string
	Event   string
	OldPath string
	NewPath string
}

type FileSummary added in v0.0.8

type FileSummary struct {
	Path    string `json:"path"`
	OldPath string `json:"old_path,omitempty"`
	NewPath string `json:"new_path,omitempty"`
	Added   int    `json:"added"`
	Deleted int    `json:"deleted"`
	Binary  bool   `json:"binary,omitempty"`
}

FileSummary is the metadata Git can report without emitting a patch body. OldPath and NewPath preserve rename/copy identity; Path is the current path reviewers select (the new path when one exists).

type ReadOptions

type ReadOptions struct {
	AllowRepositoryMismatch bool
}

Jump to

Keyboard shortcuts

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