diff

package
v0.0.0-...-91bf553 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TabChar          = '→'
	SpaceChar        = '·'
	TrailingSpaceStr = "␣"
)

Variables

This section is empty.

Functions

func CompareDirectories

func CompareDirectories(leftDir, rightDir string) (string, error)

CompareDirectories generates a unified diff comparing two directories. Returns git-format diff text suitable for parsing by diff.Parse().

func ComputeHunkWordDiffs

func ComputeHunkWordDiffs(hunk *Hunk) map[int]WordDiffResult

func CountTrailingWhitespace

func CountTrailingWhitespace(content string) int

func GeneratePatch

func GeneratePatch(files []FileChange, selection SelectionState) string

func GeneratePatchForTag

func GeneratePatchForTag(files []FileChange, selection SelectionState) string

func GetLeadingWhitespace

func GetLeadingWhitespace(content string) string

GetLeadingWhitespace extracts the leading whitespace from a string

func GetSelectedHunksMap

func GetSelectedHunksMap(files []FileChange, selectionState interface {
	IsHunkSelected(filePath string, hunkIdx int) bool
}) map[string]map[int]bool

GetSelectedHunksMap is deprecated but kept for backward compatibility

func GetUnselectedFiles

func GetUnselectedFiles(files []FileChange, selection SelectionState) []string

GetUnselectedFiles returns paths of files with no selections. These files should be restored to their left state.

func HasTrailingWhitespace

func HasTrailingWhitespace(content string) bool

func IsWhitespaceOnlyChange

func IsWhitespaceOnlyChange(oldContent, newContent string) bool

IsWhitespaceOnlyChange returns true if the two strings differ only in whitespace

func RenderWhitespaceSimple

func RenderWhitespaceSimple(content string, tabWidth int) string

func SelectAll

func SelectAll(files []FileChange, selection interface {
	ToggleHunk(filePath string, hunkIdx int)
})

SelectAll selects all hunks in all files. Used when user wants to keep all changes (default behavior).

Types

type Applier

type Applier struct {
	LeftDir  string
	RightDir string
}

Applier handles writing user selections back to the right directory. For diff-editor mode, jj expects the right directory to contain only the changes the user wants to keep.

func NewApplier

func NewApplier(leftDir, rightDir string) *Applier

func (*Applier) ApplySelections

func (a *Applier) ApplySelections(files []FileChange, selection SelectionState) error

ApplySelections reconstructs files in rightDir based on user selections. - Selected hunks: keep the change (content from right) - Unselected hunks: revert the change (content from left)

type ChangeType

type ChangeType int
const (
	ChangeTypeModified ChangeType = iota
	ChangeTypeAdded
	ChangeTypeDeleted
	ChangeTypeRenamed
)

func (ChangeType) String

func (ct ChangeType) String() string

type DiffSource

type DiffSource interface {
	GetDiff() (string, error)
	GetSourceLabel() string
	SupportsRevisions() bool
}

DiffSource abstracts the source of diff data. This enables the same UI to work with both jj revisions and directory comparisons.

type DirectorySource

type DirectorySource struct {
	LeftPath  string
	RightPath string
}

DirectorySource generates diffs by comparing two directories. Used for diff-editor mode where jj passes $left and $right directories.

func NewDirectorySource

func NewDirectorySource(leftPath, rightPath string) *DirectorySource

func (*DirectorySource) GetDiff

func (s *DirectorySource) GetDiff() (string, error)

func (*DirectorySource) GetSourceLabel

func (s *DirectorySource) GetSourceLabel() string

func (*DirectorySource) SupportsRevisions

func (s *DirectorySource) SupportsRevisions() bool

type FileChange

type FileChange struct {
	Path       string
	ChangeType ChangeType
	Hunks      []Hunk
}

func Parse

func Parse(diffText string) []FileChange

func (*FileChange) AddedLines

func (fc *FileChange) AddedLines() int

func (*FileChange) DeletedLines

func (fc *FileChange) DeletedLines() int

func (*FileChange) TotalLines

func (fc *FileChange) TotalLines() int

type Hunk

type Hunk struct {
	Header   string
	OldStart int
	OldLines int
	NewStart int
	NewLines int
	Lines    []Line
}

type IntraLineSpan

type IntraLineSpan struct {
	Start int
	End   int
	Type  SpanType
	Text  string
}

type Line

type Line struct {
	Type       LineType
	Content    string
	OldLineNum int
	NewLineNum int
}

func ProcessHunkHideWhitespace

func ProcessHunkHideWhitespace(lines []Line) []Line

ProcessHunkHideWhitespace transforms a hunk to hide whitespace-only changes Returns a new set of lines with whitespace changes handled

type LinePair

type LinePair struct {
	OldLineIdx int
	NewLineIdx int
	OldLine    *Line
	NewLine    *Line
}

func FindLinePairs

func FindLinePairs(hunk *Hunk) []LinePair

type LineType

type LineType int
const (
	LineContext LineType = iota
	LineAddition
	LineDeletion
)

func (LineType) String

func (lt LineType) String() string

type RevisionSource

type RevisionSource struct {
	Client   *jj.Client
	Revision string
}

RevisionSource generates diffs from jj revisions.

func NewRevisionSource

func NewRevisionSource(client *jj.Client, revision string) *RevisionSource

func (*RevisionSource) GetDiff

func (s *RevisionSource) GetDiff() (string, error)

func (*RevisionSource) GetSourceLabel

func (s *RevisionSource) GetSourceLabel() string

func (*RevisionSource) SupportsRevisions

func (s *RevisionSource) SupportsRevisions() bool

type SelectionState

type SelectionState interface {
	IsHunkSelected(filePath string, hunkIdx int) bool
	HasPartialSelection(filePath string, hunkIdx int) bool
	IsLineSelected(filePath string, hunkIdx, lineIdx int) bool
}

SelectionState interface for accessing selection state

type SpanType

type SpanType int
const (
	SpanEqual SpanType = iota
	SpanAdded
	SpanDeleted
)

type WhitespaceRenderer

type WhitespaceRenderer struct {
	// contains filtered or unexported fields
}

func NewWhitespaceRenderer

func NewWhitespaceRenderer(tabWidth int, trailingHighlight lipgloss.Style) *WhitespaceRenderer

func (*WhitespaceRenderer) Render

func (r *WhitespaceRenderer) Render(content string) string

type WordDiffResult

type WordDiffResult struct {
	OldSpans []IntraLineSpan
	NewSpans []IntraLineSpan
}

func ComputeWordDiff

func ComputeWordDiff(oldLine, newLine string) WordDiffResult

Jump to

Keyboard shortcuts

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