mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-17 13:13:35 +08:00
修复非git项目在新会话执行git命令导致加载慢
修复非git项目在新会话执行git命令导致加载慢
This commit is contained in:
parent
eddaec547e
commit
78a9e26476
@ -41,6 +41,7 @@ import {
|
||||
SessionBranchingError,
|
||||
} from '../../utils/sessionBranching.js'
|
||||
import { registerChangedFileAccessRoot, registerFilesystemAccessRoot } from '../services/filesystemAccessRoots.js'
|
||||
import { findGitRoot } from '../../utils/git.js'
|
||||
import { traceCaptureService, trimTraceCallPreviews } from '../services/traceCaptureService.js'
|
||||
|
||||
const workspaceService = new WorkspaceService(
|
||||
@ -711,6 +712,21 @@ async function getGitInfo(sessionId: string): Promise<Response> {
|
||||
}
|
||||
: null
|
||||
|
||||
// Fast check: if workDir is not inside a git repo, skip spawning git commands.
|
||||
// findGitRoot uses fs.stat traversal with LRU cache (<5ms), avoiding 3 slow git
|
||||
// spawns on non-git directories (each can take seconds as git searches upward).
|
||||
const gitRoot = findGitRoot(workDir)
|
||||
if (!gitRoot) {
|
||||
const dirName = workDir.split('/').pop() || workDir.split(path.sep).pop() || ''
|
||||
return Response.json({
|
||||
branch: sessionBranch,
|
||||
repoName: dirName,
|
||||
workDir,
|
||||
changedFiles: 0,
|
||||
worktree,
|
||||
})
|
||||
}
|
||||
|
||||
try {
|
||||
// Get branch name
|
||||
const branchProc = Bun.spawn(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user