perf(git): cache git rev-parse results within sessions
Multiple gt commands call git rev-parse --show-toplevel, adding ~50ms each invocation. Results rarely change within a session, and multiple agents calling git concurrently contend on .git/index.lock. Add cached RepoRoot() and RepoRootFrom() functions to the git package and update all callers to use them. This ensures a single git subprocess call per process for the common case of checking the current directory's repo root. Files updated: - internal/git/git.go: Add RepoRoot() and RepoRootFrom() - internal/cmd/prime.go: Use cached git.RepoRoot() - internal/cmd/molecule_status.go: Use cached git.RepoRoot() - internal/cmd/sling_helpers.go: Use cached git.RepoRoot() - internal/cmd/rig_quick_add.go: Use git.RepoRootFrom() for path arg - internal/version/stale.go: Use cached git.RepoRoot() Closes: bd-2zd.5
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
"os/exec"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
|
||||
"github.com/steveyegge/gastown/internal/git"
|
||||
)
|
||||
|
||||
// These variables are set at build time via ldflags in cmd package.
|
||||
@@ -133,9 +135,8 @@ func GetRepoRoot() (string, error) {
|
||||
}
|
||||
|
||||
// Check if current directory is in a gastown repo
|
||||
cmd := exec.Command("git", "rev-parse", "--show-toplevel")
|
||||
if output, err := cmd.Output(); err == nil {
|
||||
root := strings.TrimSpace(string(output))
|
||||
// Uses cached git.RepoRoot() to avoid repeated subprocess calls
|
||||
if root, err := git.RepoRoot(); err == nil {
|
||||
if hasGastownMarker(root) {
|
||||
return root, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user