Documentation
¶
Overview ¶
Package gitread answers the read-only git questions about a tab's working folder and a repository on this machine: branch, status, the working diff, a commit's diff and the commit log. It runs git with the same arguments, limits and timeouts as the runtime it replaces and reads the output the same way, so its answers match that runtime's.
Index ¶
- Constants
- Variables
- func CommitChanges(q url.Values) (int, any)
- func CommitFiles(root, message string, paths []string) (int, any)
- func ContentHash(text string) string
- func FileSides(q url.Values) (int, any)
- func MadeCommits(root string, since float64) ([]string, error)
- func ParseSessionStart(text string) *float64
- func ReadSessionStart(transcript string, roots []string) (*float64, error)
- func TranscriptRoots(home string) []string
- func WriteFile(root, path, text, expect string) (int, any)
- type BranchBody
- type Changes
- type Commit
- type CommitDiff
- type CommitMeta
- type CommitSummary
- type Diff
- type DiffHash
- type DiffNotRepo
- type HeadCommit
- type Log
- type LogEntry
- type LogNotRepo
- type RepoChanges
- type Service
- type SessionChangesBody
- type Status
- type StatusBody
- type Tmux
Constants ¶
const WriteMax = 4 << 20
WriteMax is the largest file the review writes.
Variables ¶
var ErrBadDate = errors.New("session start out of the range of a date")
ErrBadDate is a session start no Date can hold (the previous runtime threw, and its dispatcher answered 500).
Functions ¶
func CommitChanges ¶
CommitChanges answers GET /api/<changes>?root=&sha=: a commit's diff, checked to belong to the repository at root. A parameter given more than once counts as missing.
func CommitFiles ¶
CommitFiles commits the given changed files of the repository at root with a message, and answers the new commit.
func ContentHash ¶
ContentHash is the hash a page sends as expect: sha256 of the text, hex.
func FileSides ¶
FileSides is both versions of one file of the changes panel, for the review's diff, read when the file is opened: for a commit (`sha`) at its parent and at the commit, for uncommitted work at HEAD and in the working tree. `root` must be a repository's top folder; `path` is the file now and `oldPath` what it was (the same when absent, nothing when `added=1`); an empty `path` is a deleted file.
func MadeCommits ¶
MadeCommits are the commits the worktree at root made since `since` (ms) that are still on a branch or HEAD, newest first: from the HEAD reflog, or, without one, the commits of HEAD since then.
func ParseSessionStart ¶
ParseSessionStart is the first timestamp of a transcript (a string date or a number of milliseconds), nil for none.
func ReadSessionStart ¶
ReadSessionStart reads the start of a session from the head of its transcript; nil when it is not one of roots'. A transcript that opens but cannot be read is an error (the previous runtime threw).
func TranscriptRoots ¶
TranscriptRoots are the folders a transcript may be read from (the agents' conversation folders under the home).
Types ¶
type BranchBody ¶
type BranchBody struct {
Branch *string `json:"branch"`
}
BranchBody is the branch route's answer.
type Changes ¶
Changes is one commit's diff for the changes panel, cut at a file boundary when it is too long.
type Commit ¶
type Commit struct {
Hash string `json:"hash"`
ShortHash string `json:"shortHash"`
Author string `json:"author"`
Timestamp *float64 `json:"timestamp"`
Subject string `json:"subject"`
IsMerge bool `json:"isMerge"`
FilesChanged int `json:"filesChanged"`
Insertions int `json:"insertions"`
Deletions int `json:"deletions"`
}
Commit is one of the recent commits of a status.
type CommitDiff ¶
type CommitDiff struct {
Commit CommitMeta `json:"commit"`
Diff string `json:"diff"`
}
CommitDiff is a commit and its diff against its first parent.
type CommitMeta ¶
type CommitMeta struct {
Hash string `json:"hash"`
ShortHash string `json:"shortHash"`
Subject string `json:"subject"`
Body string `json:"body"`
Author string `json:"author"`
Email string `json:"email"`
Timestamp *float64 `json:"timestamp"`
Parents []string `json:"parents"`
}
CommitMeta describes one commit of the commit diff.
type CommitSummary ¶
type CommitSummary struct {
Sha string `json:"sha"`
Short string `json:"short"`
Subject string `json:"subject"`
Author string `json:"author"`
Date float64 `json:"date"`
Additions float64 `json:"additions"`
Deletions float64 `json:"deletions"`
Files int `json:"files"`
}
CommitSummary is one commit of the session.
type Diff ¶
type Diff struct {
IsGitRepo bool `json:"isGitRepo"`
Diff string `json:"diff"`
Hash string `json:"hash"`
Ahead int `json:"ahead"`
Behind int `json:"behind"`
Branch string `json:"branch"`
Upstream *string `json:"upstream"`
IsDetached bool `json:"isDetached"`
Stash int `json:"stash"`
HeadCommit *HeadCommit `json:"headCommit"`
RepoRoot string `json:"repoRoot"`
Fetched bool `json:"fetched"`
}
Diff is the working tree against HEAD, untracked files included, with what the panel shows around it.
type DiffHash ¶
type DiffHash struct {
IsGitRepo bool `json:"isGitRepo"`
Hash string `json:"hash"`
Ahead int `json:"ahead"`
Behind int `json:"behind"`
Fetched bool `json:"fetched"`
}
DiffHash is the cheap answer: only whether anything changed since the caller's hash.
type DiffNotRepo ¶
type DiffNotRepo struct {
IsGitRepo bool `json:"isGitRepo"`
Diff string `json:"diff"`
Hash string `json:"hash"`
}
DiffNotRepo is the answer for a folder outside any work tree.
type HeadCommit ¶
type HeadCommit struct {
Hash string `json:"hash"`
ShortHash string `json:"shortHash"`
Subject string `json:"subject"`
Author string `json:"author"`
Timestamp *float64 `json:"timestamp"`
}
HeadCommit is the commit HEAD points at.
type Log ¶
type Log struct {
IsGitRepo bool `json:"isGitRepo"`
Head string `json:"head"`
Branch string `json:"branch"`
UpstreamHash *string `json:"upstreamHash"`
Commits []LogEntry `json:"commits"`
}
Log is a page of the folder's history; head, branch and upstream only on the first page.
type LogEntry ¶
type LogEntry struct {
Hash string `json:"hash"`
ShortHash string `json:"shortHash"`
Parents []string `json:"parents"`
Author string `json:"author"`
Email string `json:"email"`
Timestamp *float64 `json:"timestamp"`
Subject string `json:"subject"`
IsMerge bool `json:"isMerge"`
}
LogEntry is one commit of the commit log.
type LogNotRepo ¶
LogNotRepo is the answer for a folder outside any work tree.
type RepoChanges ¶
type RepoChanges struct {
Root string `json:"root"`
Name string `json:"name"`
Branch *string `json:"branch"`
Diff string `json:"diff"`
Truncated bool `json:"truncated"`
Commits []CommitSummary `json:"commits"`
CommitsTruncated bool `json:"commitsTruncated"`
}
RepoChanges is one repository's changes.
func CollectChanges ¶
func CollectChanges(paths []string, since *float64) ([]*RepoChanges, error)
CollectChanges is the uncommitted diff and the session's commits of every repository the paths belong to (at most eight, in the order the paths name them), the repositories with changes first, then by name.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service answers the routes; it keeps the short-lived branch and status answers per folder.
func (*Service) CommitDiff ¶
CommitDiff answers /api/layout/commit-diff?session=&hash=.
func (*Service) Diff ¶
Diff answers /api/layout/diff?session=&hashOnly=&fetch=; with fetch=true the remote is fetched first.
type SessionChangesBody ¶
type SessionChangesBody struct {
Since *float64 `json:"since"`
Repos []*RepoChanges `json:"repos"`
}
SessionChangesBody is the answer.
type Status ¶
type Status struct {
Staged int `json:"staged"`
Modified int `json:"modified"`
Untracked int `json:"untracked"`
Ahead int `json:"ahead"`
Behind int `json:"behind"`
Stash int `json:"stash"`
Insertions int `json:"insertions"`
Deletions int `json:"deletions"`
RecentCommits []Commit `json:"recentCommits"`
}
Status is a working folder's state at a glance.
type StatusBody ¶
type StatusBody struct {
Status *Status `json:"status"`
}
StatusBody is the status route's answer.