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
- Variables
- func Diff(sides DiffSides) []view.DiffHunk
- type DiffSides
- type Differ
- type Git
- func (Git) ChangedFiles(cwd string) ([]view.FileChange, error)
- func (Git) DiffBase(path string) ([]byte, error)
- func (Git) Discard(cwd, path string) error
- func (Git) HeadID(path string) (string, error)
- func (Git) HeadName(path string) (string, error)
- func (Git) Ignore(cwd, path string) error
- func (Git) IndexText(cwd, path string) ([]byte, error)
- func (Git) Stage(cwd, path string) error
- func (Git) Unstage(cwd, path string) error
- type Provider
- type Session
- func (s *Session) ChangedFiles() ([]view.FileChange, error)
- func (s *Session) Close()
- func (s *Session) DiffBase(doc *view.Document) (string, bool)
- func (s *Session) DiffHunks(doc *view.Document) []view.DiffHunk
- func (s *Session) Discard(path string) error
- func (s *Session) DocumentChanged(doc *view.Document, _ view.DocumentChange)
- func (s *Session) DocumentClosed(doc *view.Document)
- func (s *Session) DocumentOpened(doc *view.Document)
- func (s *Session) DocumentSaved(doc *view.Document)
- func (s *Session) HeadName(doc *view.Document) (string, bool)
- func (s *Session) HeadText(path string) string
- func (s *Session) Ignore(path string) error
- func (s *Session) IndexText(path string) string
- func (s *Session) Refresh()
- func (s *Session) Stage(path string) error
- func (s *Session) StagedDiffHunks(path string) []view.DiffHunk
- func (s *Session) Unstage(path string) error
- func (s *Session) UnstagedDiffHunks(path string) []view.DiffHunk
- func (s *Session) Updates() <-chan struct{}
Constants ¶
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 ¶
var ( ErrGitCommand = errors.New("git command failed") ErrGitBadStatus = errors.New("unparsable git status output") )
Functions ¶
Types ¶
type DiffSides ¶ added in v0.2.0
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 ¶
NewDiffer starts a differ for the given base and document text. notify is invoked from the worker goroutine after every recompute
func (*Differ) Close ¶
func (d *Differ) Close()
Close stops the worker goroutine. The differ must not be used after
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 ¶
DiffBase returns the HEAD contents of path. No eol/ident smudge filtering is applied. A .gitattributes eol conversion may cause phantom diffs
func (Git) Discard ¶ added in v0.4.1
Discard restores the working-tree state of path from the index. An untracked file has no index state to restore, so it is deleted instead
func (Git) HeadName ¶
HeadName returns the current branch name, or a short commit hash when the head is detached
func (Git) Ignore ¶ added in v0.4.1
Ignore appends path to the repository's root .gitignore, anchored so it names that one file rather than every file sharing its name
func (Git) IndexText ¶ added in v0.4.1
IndexText returns the staged blob for path, erroring when the file has no entry in the index
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)
// IndexText returns the staged contents of path
IndexText(cwd, path string) ([]byte, error)
// Stage adds the working-tree state of path to the staging area of the
// repository containing cwd
Stage(cwd, path string) error
// Unstage drops path from that staging area, leaving the working tree
Unstage(cwd, path string) error
// Discard restores the working-tree state of path from the staging
// area, deleting the file when it is untracked
Discard(cwd, path string) error
// Ignore adds path to the ignore list of its repository
Ignore(cwd, path string) 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 ¶
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) DiffHunks ¶
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) Discard ¶ added in v0.4.1
Discard restores the working-tree state of path from the staging area, deleting the file when version control does not track it
func (*Session) DocumentChanged ¶
func (s *Session) DocumentChanged(doc *view.Document, _ view.DocumentChange)
DocumentChanged feeds the new document text to the differ
func (*Session) DocumentClosed ¶
DocumentClosed stops and forgets the document's differ
func (*Session) DocumentOpened ¶
DocumentOpened fetches the diff base in the background and starts a differ once it arrives
func (*Session) DocumentSaved ¶
DocumentSaved refreshes the diff base. The head may have moved since the document was opened
func (*Session) HeadText ¶ added in v0.4.1
HeadText returns the head text of an arbitrary workspace file. It shells out to the provider, so it is intended for on-demand use such as picker previews
func (*Session) Ignore ¶ added in v0.4.1
Ignore adds path to the ignore list of the repository holding it
func (*Session) IndexText ¶ added in v0.4.1
IndexText returns the staged text of an arbitrary workspace file, falling back to its head text when the file has no entry in the index
func (*Session) Refresh ¶
func (s *Session) Refresh()
Refresh reloads open document diff bases when their repository head moves
func (*Session) Stage ¶ added in v0.4.1
Stage adds the working-tree state of path to the staging area
func (*Session) StagedDiffHunks ¶ added in v0.4.1
StagedDiffHunks computes hunks between the head and the staged contents of an arbitrary workspace file. It shells out to the provider, so it is intended for on-demand use such as picker previews
func (*Session) Unstage ¶ added in v0.4.1
Unstage drops path from the staging area, leaving the working tree
func (*Session) UnstagedDiffHunks ¶ added in v0.4.1
UnstagedDiffHunks computes hunks between the staged and the on-disk contents of an arbitrary workspace file. It shells out to the provider