Repository navigation
perf(git): branch -r + log --no-merges + show blob filter (#55) — 3 leaks fixed - #56
Merged
Merged
Conversation
…ow blob filter (#55) Three concrete leaks in `src/cmds/git/git.rs` measured at: - branch: 0% savings on `-r` (was full passthrough) - log: 3.2% saved + correctness bug (user `-N` changed meaning) - show: 1.6% saved on `<hash>:<path>` (was full passthrough) ## Fix 1: branch -r recognises bare `origin/<branch>` format `filter_branch_output` previously only handled `remotes/`-prefixed lines from `git branch -a`. `git branch -r` emits bare `origin/x` lines that fell through unfiltered AND emitted a useless `* ` header. New `filter_branch_output_with_mode(output, remote_only)` routes them correctly, skips `origin/HEAD -> origin/main` redirect lines, suppresses the empty `* current` header in -r mode. Empirical: `git branch -r` 7221B → 345B = 95.2% savings. ## Fix 2: don't override user's explicit -N with --no-merges Previous code added `--no-merges` whenever user didn't pass `--merges`. So `git log --oneline -5` returned 5 commits from the un-merge tail instead of the actual recent 5. Correctness bug: silently changed the meaning of the user's query. Extracted `should_inject_no_merges(args, user_set_limit)`; only fires when WE set the default limit. Also fixed driving `user_set_limit` from `parse_user_limit().is_some()` rather than the looser `has_limit_flag` heuristic so bare `-n` (no value) doesn't count as user-set. Empirical: `git log --oneline -5` filtered output now matches raw exactly, merges preserved. ## Fix 3: route `git show <hash>:<path>` through read filter Extracts `<path>` from the blob-show arg, detects language via `Language::from_extension`, calls `render_output` with `FilterLevel::Minimal`. Made `render_output` pub(crate) so the git module can call it (no cross-crate API surface change). Empirical: `git show <hash>:src/main.rs` 130KB → 117KB = 10% savings on a Rust blob. ## Pre-PR review fixes (also in this commit) Independent review caught 3 must-fix items: - **P1 (multi-remote dedup collision)**: dedup key stripped the remote prefix, so `origin/feature/x` and `upstream/feature/x` silently collapsed to one entry. Now uses full `<remote>/<branch>` as the key in both -r and -a paths. Test: `test_filter_branch_remote_only_mode_preserves_same_name_across_remotes`. - **P1 (-n standalone misclassified as user-set limit)**: drove `user_set_limit` from `parse_user_limit().is_some()` instead of the looser `has_limit_flag` regex. Bare `-n` (no value) now correctly does NOT suppress the no-merges injection. Test: `test_parse_user_limit_returns_none_for_bare_dash_n`. - **P2 (double-injected --no-color)**: branch list mode now skips the auto --no-color when the user already passed `--no-color` / `--color=never`. Test: `test_branch_list_does_not_double_inject_no_color`. ## Pinning tests added - `test_filter_branch_remote_only_mode_handles_bare_origin_prefix` — fix 1 - `test_filter_branch_remote_only_mode_preserves_same_name_across_remotes` — review P1.1 - `test_filter_branch_back_compat_signature` — wrapper pin - `test_should_inject_no_merges_respects_user_limit` — fix 2 logic - `test_parse_user_limit_returns_none_for_bare_dash_n` — review P1.2 - `test_branch_list_does_not_double_inject_no_color` — review P2 - `test_blob_show_render_through_read_filter` — fix 3 savings floor (≥1% on Rust blob) - `test_blob_show_path_extraction` — fix 3 arg parsing ## Verified - `cargo build` clean - `cargo test --bin contextcrawler` — 2145 pass, 0 fail (was 2141; +8 new tests) - All 8 integration suites green - Empirical re-test all 3 fixes confirms post-merge dashboard projection: - branch -r: 0% → 95.2% - log --oneline -5: correctness preserved (no negative compression) - show <hash>:<path>: 0% → 10% Closes #55.
This was referenced May 18, 2026
Merged
noogalabs
pushed a commit
to noogalabs/contextcrawler
that referenced
this pull request
Jun 4, 2026
…+ annotate scaffolding `cargo build` was emitting 80+ unused-* warnings, drowning real signal from genuine new dead-code introductions (e.g. PR thehoff#58 unused imports went unnoticed for a session). Zero-warning cargo build is the baseline. ## Orphan files deleted (-2953 lines) Audited as fully unreferenced (zero external `use crate::...::X` paths outside the file itself); confirmed by checking that all module-level items are unused in production and the deleted .rs files have no external test depending on their public API. - `src/analytics/security_cmd.rs` (617 lines) -- superseded by `src/hooks/tirith_gate.rs::run_security_dashboard` which backs the current `contextcrawler security` subcommand - `src/analytics/jsonl_rewriter.rs` (557 lines) - `src/analytics/session_compact_cmd.rs` (292 lines) -- session-compact feature inherited from the contextzip merge that never got wired - `src/analytics/ansi_filter.rs` (198 lines) -- only used by the jsonl_rewriter above - `src/cmds/cloud/web_cmd.rs` (472 lines) -- contextzip HTML extractor that was never wired through clap; `cmds/cloud/mod.rs` uses `automod::dir!` so the file got auto-imported as a module without a call site - `src/core/error_cmd.rs` (817 lines) -- language-specific stack-trace compactors that also never got wired Also dropped from mod.rs: - `src/analytics/mod.rs` -- 4 `pub mod` lines - `src/core/mod.rs` -- `pub mod error_cmd;` line ## Legacy hook constants WIRED (instead of deleted) `LEGACY_CLAUDE_HOOK_COMMAND` and `LEGACY_CURSOR_HOOK_COMMAND` were defined as constants but only ever referenced as literal strings elsewhere. Wiring them properly closes two latent bugs: - `src/hooks/integrity.rs::run_verify`: only checked the legacy literal "rtk hook claude" in `settings.json`. Freshly-installed users running the current `CLAUDE_HOOK_COMMAND` ("contextcrawler hook claude") saw "hook not installed" even after a successful `contextcrawler init -g`. Fixed: accept either current or legacy. - `src/hooks/init.rs` cursor hook detection (line 3083 + 3258): only matched the current command. Legacy installs got missed by the skip-install detector AND the uninstall remover. Fixed: accept both. ## Intentional scaffolding annotated #[allow(dead_code)] These are future-wired structures that earn their warnings by design. Annotating with intent so the next reader knows they're not orphans: - `core::utils::ToolPolicy` + `secure_command_with_policy` + `check_args_with_policy` + `policy_deny_message` -- the worked refactor target documented in the module header. Per-tool helpers will migrate onto it. - `main::web_ssrf_block_reason` -- IP classification helper from the deleted web_cmd.rs. Preserved for future SSRF wiring of curl/wget filter or a Rust HTTP client; the classification logic is the expensive part to re-derive. - `cmds::git::git::filter_branch_output` -- back-compat wrapper kept for the back-compat test surface (production switched to filter_branch_output_with_mode in thehoff#56). - `cmds::system::grep_cmd::has_format_flag_raw` -- OsString-typed sibling of the existing String-typed helper; one helper per arg-type so callers don't need to allocate. ## Unused imports removed - `src/cmds/js/lint_cmd.rs` -- `resolved_command` (replaced by `secure_python_command` / `package_manager_exec` earlier this session) - `src/cmds/system/grep_cmd.rs` -- `resolved_command` moved under `#[cfg(test)]` (production uses `secure_rg_command`, tests use the raw baseline) ## Verified - cargo build clean: **0 warnings** (was 80+) - cargo test --bin contextcrawler: 2116 pass / 0 fail (was 2156; delta is the ~40 tests inside the deleted orphan files) - All 9 integration suites green No production behaviour changes apart from the two latent-bug fixes (integrity check + cursor hook detection) which are pure improvements.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three measurement-driven fixes to the git filter (115K input/24h @ 22.9% pre-PR). Includes pre-PR review fixups (3 must-fix items caught + addressed).
Empirical results
git branch -rgit log --oneline -5git show <hash>:<path>Fixes
filter_branch_outputonly handled theremotes/prefix from-a;-remits bareorigin/xand fell through unfiltered + emitted a useless*header. Newfilter_branch_output_with_mode(output, remote_only_mode).-Ngot 5 different commits (the un-merge tail). Now only fires when WE set the default limit. Extractedshould_inject_no_merges(). Also fixeduser_set_limitderivation fromparse_user_limit().is_some()(catches degenerate bare-n).Language::from_extension, route throughcmds::system::read::render_output(madepub(crate)).Pre-PR review fixes (commit
1f178c7)-rmode:origin/feature/xandupstream/feature/xsilently collapsed. Now uses full<remote>/<branch>as key. Also fixed pre-existing same bug in-amode.-nstandalone (no value) misclassified as user-set limit. Switched toparse_user_limit().is_some().--no-colordouble-injection: detect user-provided flag before appending.Pinning tests added (8 new)
--pretty=format:%H)Verified
cargo buildcleancargo test --bin contextcrawler— 2145 pass, 0 fail (was 2141; +8 new tests, all the above)Out of scope (separate issues)
git status --short0% savings on 184 calls/24h — output is structurally compact already; deserves its own UX discussion (group-by-directory? cap at N changes?)rtk git status --shortcalled 4× with identical output) — orthogonal optimisationSuccess criteria (post-merge dashboard)
After deploy + 24h, re-measure git row in
contextcrawler gain:git: 22.9% → ≥45% targetbranchsubset: 46.2% (current) → ≥75% (dominated by-rlift)logsubset: 3.2% → ≥60% (lift driven by removed false-negative compressions)showsubset: 1.6% → ≥10% (blob filter)Closes #55.