Skip to content

[codex] skip unnecessary status untracked scans#423

Merged
genedna merged 2 commits into
mainfrom
codex/status-untracked-scan
Jul 5, 2026
Merged

[codex] skip unnecessary status untracked scans#423
genedna merged 2 commits into
mainfrom
codex/status-untracked-scan

Conversation

@genedna

@genedna genedna commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a status-specific worktree collector that skips untracked discovery for status -uno.
  • Report top-level untracked directories in normal mode without descending into directories that have no tracked descendants.
  • Preserve existing collapsed-directory output and add regressions for unreadable untracked artifact directories.

Why

status should not pay for untracked discovery when the user explicitly hides untracked files, and normal mode can safely report a completely untracked top-level directory without recursively scanning build artifacts. This mirrors the performance concern addressed for pull/restore while preserving status -uall full discovery behavior.

Validation

  • cargo +nightly fmt --all --check
  • LIBRA_SKIP_WEB_BUILD=1 cargo clippy --all-targets --all-features -- -D warnings
  • LIBRA_SKIP_WEB_BUILD=1 cargo test --test command_test untracked_directory -- --nocapture
  • LIBRA_SKIP_WEB_BUILD=1 cargo test --test command_test test_status_with_subdirectories -- --nocapture
  • LIBRA_SKIP_WEB_BUILD=1 cargo test --test command_test status_test -- --nocapture

Signed-off-by: Eli Ma <eli@patch.sh>
Copilot AI review requested due to automatic review settings July 5, 2026 01:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes libra status worktree collection to avoid paying for untracked discovery when the user requests --untracked-files=no, and to avoid descending into fully-untracked top-level directories in normal mode when they have no tracked descendants. It introduces a dedicated status worktree collector and adds regression tests covering unreadable untracked artifact directories.

Changes:

  • Add status_untracked worktree collector to skip untracked discovery for status -uno and to short-circuit top-level untracked directory traversal in normal mode.
  • Wire status to use the new collector and adjust index handling for the new flow.
  • Add Unix-only integration tests ensuring unreadable untracked directories don’t break status -uno and that normal mode reports ?? <dir>/ without descending.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
src/command/status.rs Switches status data collection to use the new status-specific worktree collector.
src/command/status_untracked.rs New module implementing tracked-worktree change detection plus optional untracked/ignored scanning with top-level untracked dir short-circuiting.
src/command/mod.rs Registers the new status_untracked module.
tests/command/status_test.rs Adds regressions for status -uno skipping unreadable untracked dirs and normal-mode top-level dir reporting.

Comment thread src/command/status.rs Outdated
Comment on lines 418 to 422
let needs_index = matches!(args.untracked_files, UntrackedFiles::Normal)
|| matches!(args.porcelain, Some(PorcelainVersion::V2));
let mut maybe_index = if needs_index {
Some(load_status_index()?)
Some(worktree.index)
} else {
Comment thread src/command/status_untracked.rs Outdated
Comment on lines +140 to +147
for entry in std::fs::read_dir(&dir).map_err(|source| StatusError::ListWorkdirFiles {
path: workdir.to_path_buf(),
source,
})? {
let entry = entry.map_err(|source| StatusError::ListWorkdirFiles {
path: workdir.to_path_buf(),
source,
})?;
Comment on lines +154 to +166
let file_type = entry
.file_type()
.map_err(|source| StatusError::ListWorkdirFiles {
path: workdir.to_path_buf(),
source,
})?;
let relative = path
.strip_prefix(workdir)
.map_err(|err| StatusError::ListWorkdirFiles {
path: workdir.to_path_buf(),
source: std::io::Error::other(err.to_string()),
})?
.to_path_buf();
Comment thread src/command/status_untracked.rs Outdated
Comment on lines +47 to +51
unstaged.new = if matches!(untracked_mode, UntrackedFiles::Normal) && include_ignored {
collapse_untracked_directories(scan.untracked, &index)
} else {
scan.untracked
};
Comment on lines +174 to +178
if matches!(untracked_mode, UntrackedFiles::Normal)
&& !include_ignored
&& is_top_level_path(&relative)
&& !has_tracked_descendant(&relative, tracked_files)
{
Signed-off-by: Eli Ma <eli@patch.sh>
@genedna

genedna commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the review feedback in 72de4ab:

  • kept the already-loaded index available for later status rendering paths
  • report untracked scan listing errors against the directory being scanned
  • restored deterministic sorted/deduped normal untracked output
  • precomputed tracked top-level directories to avoid per-directory full tracked-file scans
  • added a regression test for sorted collapsed untracked directories

Local verification:

  • cargo +nightly fmt --all --check
  • LIBRA_SKIP_WEB_BUILD=1 cargo test --test command_test status_test -- --nocapture
  • LIBRA_SKIP_WEB_BUILD=1 cargo clippy --all-targets --all-features -- -D warnings

GitHub CodeQL checks are passing; the Check, Build and Test workflow is still queued, not failing.

@genedna genedna marked this pull request as ready for review July 5, 2026 03:14
Copilot AI review requested due to automatic review settings July 5, 2026 03:14
@genedna genedna merged commit 06370c3 into main Jul 5, 2026
5 of 11 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread src/command/status.rs
Comment on lines +413 to +417
let ignored_files = worktree
.ignored_files
.into_iter()
.map(util::workdir_to_current)
.collect();
Comment on lines +169 to +172
pending_dirs.push(path);
} else if file_type.is_file() {
scan_file(&mut scan, workdir, index, &path, &relative, include_ignored)?;
}
@genedna genedna deleted the codex/status-untracked-scan branch July 5, 2026 06:07
genedna added a commit that referenced this pull request Jul 5, 2026
The no-descend untracked-directory optimization (#423) emitted the
'?? dir/' marker for any top-level untracked directory, deviating from
git: a directory whose entire contents are skip-listed (.libra/.git)
or ignored holds no visible untracked file and must stay invisible.
Test harnesses' isolated '.libra-test-home/' (containing only a nested
.libra) became visible and broke four clean-tree assertions across the
suite. The marker is now gated on a lazy first-hit probe with the same
skip rules; unreadable directories stay reported (cannot verify
emptiness — matches the #423 permission tests). Regression test pins
both directions.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Eli Ma <eli@patch.sh>
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.

2 participants