Documentation
¶
Overview ¶
Package worktree lists the SQL files of a working directory and reports what git says about them.
It knows nothing about tview and nothing about databases: it answers "which files are here" and "which of them changed", and the caller decides what to do with the answers.
git is optional. A directory that is not a repository, or a machine with no git installed, still yields its .sql files — only the branch and the per-file markers go missing. That is the same bargain the schema cache and the query history make: a missing convenience must not cost the session.
Index ¶
Constants ¶
const MaxFileSize = 4 << 20
MaxFileSize is the largest file that will be loaded into the editor.
A mysqldump is routinely hundreds of megabytes, and handing one to a text widget does not produce a slow interface — it produces one that never draws again. Refusing is the only outcome that leaves the user something working.
Variables ¶
var ( // ErrOutsideWorktree refuses a path that resolves beyond the attached // directory. The interface hands back whatever path it was given, and a // stale or crafted one must not reach a file the user never attached. ErrOutsideWorktree = errors.New("path is outside the worktree") // ErrTooLarge refuses a file that would wedge the editor. ErrTooLarge = errors.New("file is too large to open") )
Functions ¶
This section is empty.
Types ¶
type File ¶
type File struct {
// Rel is relative to the attached directory, which is what the user
// chose and therefore what they should be shown.
Rel string
Abs string
Status Status
}
File is one SQL file of the worktree.
type Snapshot ¶
type Snapshot struct {
// Branch is the checked-out branch, or the short commit id when HEAD is
// detached. Empty when git had nothing to say.
Branch string
Detached bool
Dirty bool
// Remote is the origin URL, empty when there is no origin. It is read here
// rather than asked for because the project a session wants to browse is
// nearly always the one the checkout came from.
Remote string
Files []File
// Truncated reports that the listing hit its cap, so the user is told
// rather than left believing they saw everything.
Truncated bool
}
Snapshot is one reading of the worktree: what is in it, and where git says the work stands.
It is a value rather than state on Worktree so that a rescan cannot leave the file list and the branch describing different moments.
type Stamp ¶
Stamp identifies the version of a file that was read.
It is compared, never interpreted, so a comparable struct is the whole of what it needs to be.
type Status ¶
type Status rune
Status is what git says about one file, reduced to a single character.
git reports two: one for the index and one for the working tree. The pane showing these has room for one, so the index status wins — a file staged as new and then edited again is still a file that does not exist on the branch yet, which is the more useful thing to know.
const ( // StatusNone means git had nothing to say: the file is committed and // unchanged. It is the zero value so a file map needs no initialisation. StatusNone Status = 0 StatusModified Status = 'M' StatusAdded Status = 'A' StatusDeleted Status = 'D' StatusRenamed Status = 'R' StatusUntracked Status = '?' StatusConflict Status = 'U' )
type Worktree ¶
type Worktree struct {
// Root is absolute, with symlinks resolved, so containment checks compare
// like with like.
Root string
// contains filtered or unexported fields
}
Worktree is an attached directory.
func Open ¶
Open attaches a directory, resolving and checking it before anything else depends on it.
git is not consulted here — that happens on Scan, so attaching stays instant even on a repository large enough that a status takes a moment.
func (*Worktree) Name ¶
Name is the worktree's last path element, which is what identifies it on a status bar too narrow for the whole path.
func (*Worktree) Stat ¶
Stat reports the stamp of a file without reading it, which is how a save notices the file changed since it was opened.