gitread

package
v0.16.397 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 29 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const WriteMax = 4 << 20

WriteMax is the largest file the review writes.

Variables

View Source
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

func CommitChanges(q url.Values) (int, any)

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

func CommitFiles(root, message string, paths []string) (int, any)

CommitFiles commits the given changed files of the repository at root with a message, and answers the new commit.

func ContentHash

func ContentHash(text string) string

ContentHash is the hash a page sends as expect: sha256 of the text, hex.

func FileSides

func FileSides(q url.Values) (int, any)

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

func MadeCommits(root string, since float64) ([]string, error)

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

func ParseSessionStart(text string) *float64

ParseSessionStart is the first timestamp of a transcript (a string date or a number of milliseconds), nil for none.

func ReadSessionStart

func ReadSessionStart(transcript string, roots []string) (*float64, error)

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

func TranscriptRoots(home string) []string

TranscriptRoots are the folders a transcript may be read from (the agents' conversation folders under the home).

func WriteFile

func WriteFile(root, path, text, expect string) (int, any)

WriteFile writes text into the file at path of the repository at root, when the file is still what the page read.

Types

type BranchBody

type BranchBody struct {
	Branch *string `json:"branch"`
}

BranchBody is the branch route's answer.

type Changes

type Changes struct {
	Diff      string `json:"diff"`
	Truncated bool   `json:"truncated"`
}

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

type LogNotRepo struct {
	IsGitRepo bool       `json:"isGitRepo"`
	Commits   []LogEntry `json:"commits"`
}

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 New

func New(tm Tmux) *Service

func (*Service) Branch

func (s *Service) Branch(q url.Values) (int, any)

Branch answers /api/git/branch?tmuxSession=&force=.

func (*Service) CommitDiff

func (s *Service) CommitDiff(q url.Values) (int, any)

CommitDiff answers /api/layout/commit-diff?session=&hash=.

func (*Service) Diff

func (s *Service) Diff(q url.Values) (int, any)

Diff answers /api/layout/diff?session=&hashOnly=&fetch=; with fetch=true the remote is fetched first.

func (*Service) GitLog

func (s *Service) GitLog(q url.Values) (int, any)

GitLog answers /api/layout/git-log?session=&limit=&skip=.

func (*Service) Status

func (s *Service) Status(q url.Values) (int, any)

Status answers /api/git/status?tmuxSession=&force=.

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.

type Tmux

type Tmux interface {
	HasSession(name string) bool
	PanePID(name string) int
	PanePath(name string) string
}

Tmux is what the routes need of the runtime's tmux servers.

Jump to

Keyboard shortcuts

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