vcs

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package vcs integrates version-control systems with the editor: diff bases for gutter hunks, changed-file listings, and head names. Git is the only provider today; the Provider interface keeps the API explicit and pluggable

Index

Constants

View Source
const (
	MaxDiffLines = 65536
	MaxDiffBytes = 16 << 20
)

MaxDiffLines and MaxDiffBytes bound the inputs Diff will process, so a pathological file cannot stall the diff worker. Larger documents simply render without diff gutter marks

Variables

View Source
var (
	ErrGitCommand   = errors.New("git command failed")
	ErrGitBadStatus = errors.New("unparsable git status output")
)

Functions

func Diff

func Diff(sides DiffSides) []view.DiffHunk

Diff returns the line-level hunks that turn Base into Doc, sorted ascending and non-overlapping. It returns nil when either side exceeds the size caps

Types

type DiffSides added in v0.2.0

type DiffSides struct {
	Base core.Rope
	Doc  core.Rope
}

DiffSides is the version-control base text and the working document text being compared against it

type Differ

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

Differ tracks the hunks between a version-control base text and a live document text, recomputing on a background goroutine. Updates are debounced so rapid keystrokes coalesce into one diff

func NewDiffer

func NewDiffer(sides DiffSides, notify func()) *Differ

NewDiffer starts a differ for the given base and document text. notify is invoked from the worker goroutine after every recompute

func (*Differ) Base

func (d *Differ) Base() core.Rope

Base returns the current diff base text

func (*Differ) Close

func (d *Differ) Close()

Close stops the worker goroutine. The differ must not be used after

func (*Differ) Hunks

func (d *Differ) Hunks() []view.DiffHunk

Hunks returns a snapshot of the current hunks

func (*Differ) SetBase

func (d *Differ) SetBase(base core.Rope)

SetBase schedules a recompute against a new diff base text

func (*Differ) SetDoc

func (d *Differ) SetDoc(doc core.Rope)

SetDoc schedules a recompute against a new document text

type Git

type Git struct{}

Git reads HEAD state through go-git in-process and reports working-tree status by shelling out to the git binary found on PATH

func (Git) ChangedFiles

func (Git) ChangedFiles(cwd string) ([]view.FileChange, error)

ChangedFiles reports the working-tree changes for the repository containing cwd, with absolute paths. It prefers the git binary (fast) and falls back to go-git's in-process status walk when git is not on PATH

func (Git) DiffBase

func (Git) DiffBase(path string) ([]byte, error)

DiffBase returns the HEAD contents of path. No eol/ident smudge filtering is applied; .gitattributes eol conversion may cause phantom diffs

func (Git) HeadID

func (Git) HeadID(path string) (string, error)

HeadID returns the full current HEAD revision

func (Git) HeadName

func (Git) HeadName(path string) (string, error)

HeadName returns the current branch name, or a short commit hash when the head is detached

type Provider

type Provider interface {
	// DiffBase returns the checked-in contents of path, the "base" text a
	// diff of the working copy is computed against
	DiffBase(path string) ([]byte, error)

	// HeadName returns a short display name for the current head, such as
	// a branch name
	HeadName(path string) (string, error)

	// HeadID returns the exact current head revision
	HeadID(path string) (string, error)

	// ChangedFiles lists workspace files that differ from the head
	ChangedFiles(cwd string) ([]view.FileChange, error)
}

Provider supplies diff bases and change information from one version-control system

type Session

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

Session owns a differ per open document and implements the editor's VersionControl seam over the version-control provider

func Attach

func Attach(e *view.Editor) *Session

Attach starts a version-control session for the editor, observing document lifecycle events and serving diff state

func (*Session) ChangedFiles

func (s *Session) ChangedFiles() ([]view.FileChange, error)

ChangedFiles lists workspace files that differ from the head

func (*Session) Close

func (s *Session) Close()

Close stops all differs

func (*Session) DiffBase

func (s *Session) DiffBase(doc *view.Document) (string, bool)

DiffBase returns the version-control base text for the document

func (*Session) DiffBaseForPath

func (s *Session) DiffBaseForPath(path string) string

DiffBaseForPath returns the checked-in base text of an arbitrary workspace file. It shells out to the provider, so it is intended for on-demand use such as picker diff previews

func (*Session) DiffHunks

func (s *Session) DiffHunks(doc *view.Document) []view.DiffHunk

DiffHunks returns the current hunks for the document, loading its diff base on first request for a buffer that was not open at startup

func (*Session) DiffHunksForPath

func (s *Session) DiffHunksForPath(path string) []view.DiffHunk

DiffHunksForPath computes hunks between the checked-in base and the on-disk contents of an arbitrary workspace file. It shells out to the provider and is intended for on-demand use such as picker previews

func (*Session) DocumentChanged

func (s *Session) DocumentChanged(doc *view.Document, _ view.DocumentChange)

DocumentChanged feeds the new document text to the differ

func (*Session) DocumentClosed

func (s *Session) DocumentClosed(doc *view.Document)

DocumentClosed stops and forgets the document's differ

func (*Session) DocumentOpened

func (s *Session) DocumentOpened(doc *view.Document)

DocumentOpened fetches the diff base in the background and starts a differ once it arrives

func (*Session) DocumentSaved

func (s *Session) DocumentSaved(doc *view.Document)

DocumentSaved refreshes the diff base; the head may have moved since the document was opened

func (*Session) HeadName

func (s *Session) HeadName(doc *view.Document) (string, bool)

HeadName returns the head display name for the document's repository

func (*Session) Refresh

func (s *Session) Refresh()

Refresh reloads open document diff bases when their repository head moves

func (*Session) Updates

func (s *Session) Updates() <-chan struct{}

Updates delivers a token whenever diff state changes

Jump to

Keyboard shortcuts

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