Repository navigation
refactor(vcs): isolate repository operations behind providers - #1912
Qiyuanqiii wants to merge 1 commit into
Conversation
|
This PR is split out from #1738, so we'll wait it for the time being. |
|
🔍 OpenCodeReview found 2 issue(s) in this PR.
|
| if base == "" { | ||
| return DiffSet{}, fmt.Errorf("cannot find merge-base between %s and %s", p.from, p.to) | ||
| } |
There was a problem hiding this comment.
When ModeDirect is used with an empty from, this error message says "cannot find merge-base" which is misleading — ModeDirect does not compute a merge-base. While the current sole caller (vcs/git/review.go) guards against an empty base before constructing a ModeDirect provider, this is a public constructor (NewDirectProvider) and the error should accurately describe the failure for both modes.
Suggestion:
| if base == "" { | |
| return DiffSet{}, fmt.Errorf("cannot find merge-base between %s and %s", p.from, p.to) | |
| } | |
| if base == "" { | |
| if p.mode == ModeDirect { | |
| return DiffSet{}, fmt.Errorf("direct comparison base is empty (from=%s, to=%s)", p.from, p.to) | |
| } | |
| return DiffSet{}, fmt.Errorf("cannot find merge-base between %s and %s", p.from, p.to) | |
| } |
| func (r *Repository) CurrentBranch(ctx context.Context) (string, error) { | ||
| runner := r.Runner | ||
| if runner == nil { | ||
| runner = gitcmd.New(1) | ||
| } | ||
| out, err := runner.Output(ctx, r.RepoDir, "rev-parse", "--abbrev-ref", "HEAD") | ||
| return strings.TrimSpace(string(out)), err | ||
| } |
There was a problem hiding this comment.
When r.Runner is nil, this creates a new gitcmd.Runner (with its own semaphore channel) on every call instead of reusing the shared defaultRunner via r.commandRunner(). Every other method in this package uses commandRunner() for the nil-fallback path. This both allocates unnecessarily per call and bypasses the shared concurrency limit, potentially allowing unbounded subprocess creation if CurrentBranch is called concurrently.
Suggestion:
| func (r *Repository) CurrentBranch(ctx context.Context) (string, error) { | |
| runner := r.Runner | |
| if runner == nil { | |
| runner = gitcmd.New(1) | |
| } | |
| out, err := runner.Output(ctx, r.RepoDir, "rev-parse", "--abbrev-ref", "HEAD") | |
| return strings.TrimSpace(string(out)), err | |
| } | |
| func (r *Repository) CurrentBranch(ctx context.Context) (string, error) { | |
| out, err := r.commandRunner().Output(ctx, r.RepoDir, "rev-parse", "--abbrev-ref", "HEAD") | |
| return strings.TrimSpace(string(out)), err | |
| } |
Behavior
Review, scan and code tools currently use Git-specific runners and revision rules directly. This change puts repository operations behind
internal/vcscontracts and supplies the built-in Git adapter, preserving the existing CLI modes and Git-backed review behavior.This is an independent PR against
main, adapted from the earlier fork's VCS implementation as part of the #1738 split. It does not depend on local rule plugins or the MCP HTTPS change (#1910).Boundaries
flowchart LR consumers["Review / scan / rules / code tools"] --> contracts["internal/vcs contracts"] contracts --> adapter["internal/vcs/git adapter"] adapter --> existing["Git runner and diff engine"]Review order
internal/vcs/vcs.goanddocs/vcs-provider-boundary.md.internal/vcs/git: resolved comparisons, bounded file access, listing and search.internal/agent/repository.goand CLI preparation: shared comparison and identity.Validation
Windows, Go 1.26.10:
make license-addandmake checkpassed.make testpassed for VCS, Git runner, tools, diff, rules, scan, agent and CLI packages.make coveragepassed: 91.1% overall.AI assistance and contributor review
OpenAI Codex (GPT-6), a GPT-6.1 Sol agent at xhigh, and OCR with the configured DeepSeek provider assisted with the extraction and review. The earlier VCS implementation was authored on the contributor's fork. No unrelated plugin co-author trailers are carried into this PR.
Related: #1738, #1910.