Skip to content

添加工作树功能、优化提交历史加载逻辑并记录 Git 操作耗时 - #419

Open
xiaoyumuxi wants to merge 29 commits into
previewfrom
codex/issue-383-worktree-management
Open

添加工作树功能、优化提交历史加载逻辑并记录 Git 操作耗时#419
xiaoyumuxi wants to merge 29 commits into
previewfrom
codex/issue-383-worktree-management

Conversation

@xiaoyumuxi

Copy link
Copy Markdown
Collaborator

概要

  • 提交历史与 worktree 状态扫描并发执行,提交历史完成后立即显示。
  • 状态扫描完成后再补充本地修改,避免提交历史被慢速 index/status 扫描阻塞。
  • 为 Git command/read、缓存命中及 worktree inspection 阶段记录耗时到当前应用日志 lithe.log
  • 对 Git 参数、工作目录和 worktree 标识进行脱敏,日志异步写入,避免日志 IO 阻塞 Git 操作。

性能数据

在当前仓库使用真实 Git 命令进行 3 次预热、20 次采样:

场景 Median P95
git log --oneline -30 7.48 ms 7.72 ms
git status --short 24.08 ms 25.06 ms
原顺序:history → status 31.80 ms 32.37 ms
并发执行:history + status 24.60 ms 25.36 ms

当前仓库的 wall-clock 中位数下降约 22.6%。实际收益取决于仓库规模、磁盘和 Git 状态;核心行为是提交历史不再等待状态扫描完成。

日志示例

timestamp_ms=... [git-performance] operation=history duration_ms=8 status=success cache=miss
timestamp_ms=... [git-performance] operation=worktree-inspection phase=history-published worktree=/... duration_ms=9

验证

  • swift test --package-path . --filter GitModuleTests:35 个测试通过
  • macOS 稳定性 harness:35 个测试通过
  • verify-test-stability.sh:通过
  • verify-service-boundaries.sh:通过
  • git diff --check:通过

稳定性报告:.artifacts/test-stability/index.html

@xiaoyumuxi
xiaoyumuxi requested a review from 1lck as a code owner September 2, 2026 16:04
@xiaoyumuxi
xiaoyumuxi changed the base branch from main to preview September 2, 2026 16:11
@xiaoyumuxi xiaoyumuxi changed the title 优化提交历史加载并记录 Git 操作耗时 添加工作树功能、优化提交历史加载逻辑并记录 Git 操作耗时 Sep 2, 2026
Comment thread rust/lithe-core/src/git/mod.rs Outdated
.canonicalize()
.unwrap_or_else(|_| reported_path.clone());
Ok(GitWorktreeResponse {
path: path.to_string(),

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Windows CI 当前会稳定复现失败:git worktree list --porcelain -z 返回的是 C:/... 路径,而新增测试通过 canonicalize() 得到的是 \\?\\C:\\...,导致 git_worktrees_lists_primary_linked_and_locked_metadata 在 Windows 上失败。\n\n另外,后面的 worktree mutation 在 4429 行使用 entry.path == destination 做字符串精确匹配;如果 UI 或调用方传入另一种等价的 Windows 路径表示,合法 worktree 也会被误报为未注册,进而无法锁定、解锁或删除。建议在 Rust Core 边界统一路径规范,并用规范化后的路径进行比较;同时把测试改成验证跨平台稳定的路径契约,而不是依赖 Windows 的 \\?\\ 表示。

@xiaoyumuxi

Copy link
Copy Markdown
Collaborator Author

@xiaoyumuxi\n\n这次 Review 发现一个需要处理的跨平台问题:新增的 worktree 测试在 Windows CI 上失败,原因是 Git 输出的路径格式与 canonicalize() 返回的长路径格式不一致。当前 PR 的 Windows CI required check 也因此失败,所以这个问题会阻塞合并。\n\n建议统一 Rust Core 中 worktree 路径的规范化和比较方式,同时调整测试,避免把平台相关的路径前缀当作稳定契约。还需要补充 Windows 路径、包含非 ASCII 字符路径,以及锁定/解锁/删除操作的验证。\n\n除此之外,整体设计方向是合理的,尤其是把 worktree 管理下沉到 Rust Core,并在 worktree 检查和提交历史加载中加入 generation 校验,值得保留。macOS、Rust Core 和稳定性检查目前通过;Windows required check 仍需修复后重新验证。\n\n当前存在阻塞合并的问题。

let reference = gitReferences.first { $0.fullName == worktree.branch }
let nextLimit = inspection.commits.count + 50
let history = await service.history(at: worktree.url, reference: reference, limit: nextLimit)
guard gitWorktreeInspection?.worktreeID == worktree.id else { return }

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 这里仅按 worktreeID 校验异步结果,无法区分同一路径在下一代 inspection 中产生的新状态。若用户在“加载更多”等待期间刷新或重新检查同一个 worktree,旧请求完成后会用它捕获的 inspection.changes 和旧 history 覆盖新一代结果。建议在请求开始时捕获 worktreeInspectionRequestGeneration,返回后同时校验 generation、worktreeID 和取消状态。


let resolvedHistory = await history
guard generation == worktreeInspectionRequestGeneration, !Task.isCancelled else {
gitWorktreeInspectionLoadState = .idle

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 旧的 inspection 请求返回时,即使 generation 已失效,这里仍会把共享的 gitWorktreeInspectionLoadState 改成 .idle。当用户快速切换 worktree 时,旧请求可能在新请求仍等待 Git history 时完成,导致新请求的 loading 状态被提前清掉,UI 会短暂显示错误的空闲/空结果状态。建议失效或取消的请求直接返回,不要修改共享状态。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant