Git branch strict#11
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a Changesgit-branch-strict feature
Sequence Diagram(s)sequenceDiagram
participant changed_lines_against_origin
participant git diff
participant git ls-files
participant ChangedFileLines
changed_lines_against_origin->>git diff: --unified=0 diff against merge base
changed_lines_against_origin->>git ls-files: --others --exclude-standard -z
git diff-->>changed_lines_against_origin: file headers and hunk headers
changed_lines_against_origin-->>ChangedFileLines: Vec<ChangedFileLines>
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (2)
src/report/duplicate_renderer.rs (1)
282-309: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a duplicate-report test for changed-line suffixes.
Lines 288-295 only cover
changed_lines: None, so the newformat_analyzed_file/format_line_rangespath is untested here. Please add the same(3-17,21)-style assertion thatsrc/report/complexity_renderer.rsnow has, so both renderers stay locked to the same output contract.Suggested test shape
#[test] +fn renders_verbose_changed_line_ranges() { + let report = DuplicateReport { + analyzed_files: 1, + analyzed_extensions: vec!["rs".to_string()], + analyzed_file_paths: Some(vec![AnalyzedFile { + path: PathBuf::from("src/lib.rs"), + changed_lines: Some(vec![ + LineRange { start: 3, end: 17 }, + LineRange { start: 21, end: 21 }, + ]), + }]), + timings: None, + duplicate_blocks: Vec::new(), + }; + let output = render_duplicate_report(&report, true); + assert!(output.contains("Files analyzed:\n- src/lib.rs (3-17,21)\n")); +}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/report/duplicate_renderer.rs` around lines 282 - 309, Add a duplicate-report test covering the changed_lines suffix formatting in duplicate_renderer::renders_analyzed_file_list_only_in_verbose_mode. The current test only exercises AnalyzedFile entries with changed_lines: None, so extend it to include a case with a populated changed_lines range and assert the rendered verbose output matches the same line-range suffix contract used in complexity_renderer’s test (the "(3-17,21)"-style formatting). Use the format_analyzed_file and format_line_ranges output path as the behavior to verify, while keeping the existing verbose/quiet assertions intact.src/lib.rs (1)
98-111: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winShort-circuit duplicate scans when the branch scope is empty.
For
-git-branch/-git-branch-strict,duplicate_discovery_files(config)returnsNone, so a clean branch still recursively discovers/processes all files and runs duplicate detection before filtering to zero. Pass an empty file slice whenbranch_scope.files()is empty.♻️ Proposed fix
let branch_scope = changed_branch_scope(config, current_dir)?; + let branch_files = branch_scope.files(); + let discovery_files = if branch_files.is_some_and(|files| files.is_empty()) { + branch_files + } else { + duplicate_discovery_files(config) + }; let (source_files, discovery_duration) = discover_report_files( config.verbose, current_dir, &config.file_extensions, - duplicate_discovery_files(config), + discovery_files, )?;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/lib.rs` around lines 98 - 111, The duplicate scan path still discovers, processes, and detects duplicates for every file even when the branch scope is empty, which defeats the intended short-circuit for -git-branch/-git-branch-strict. Update the flow around changed_branch_scope, discover_report_files, line::process_source_files, and report::detect_duplicate_blocks so that when branch_scope.files() is empty you pass an empty file slice into discovery and skip downstream processing/detection entirely, letting the later filtering stay empty without doing work.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/cli/help.rs`:
- Around line 41-44: The `-git-branch-strict` help text in `help.rs` is too
broad for duplicate-mode behavior and should be narrowed. Update the wording so
it clearly distinguishes complexity-mode from duplicate-mode, since `lib.rs`’s
duplicate scanning still processes all files and `git-branch-strict` only limits
overlap/changed-line reporting rather than restricting duplicate discovery to
changed files. Keep the incompatibility note with `-files` and `-git-branch`,
and align the text with the actual behavior exposed by the duplicate-detection
flow in `lib.rs` and the CLI help entry.
In `@src/discovery/git.rs`:
- Around line 210-217: The untracked-file path in changed_lines_against_origin
is decoding file contents too early via count_lines, which can fail on non-UTF-8
artifacts before report filtering. Update the logic around count_lines and
merge_changed_file so untracked files are handled without reading/UTF-8-decoding
content here, or are skipped unless they are already known to be supported text
files. Apply the same fix to the duplicated handling at the other referenced
location so strict-mode can continue past binary/generated files.
- Around line 223-235: Handle quoted `+++` diff headers in `parse_changed_lines`
so `current_path` is set correctly for paths with spaces or quotes. Update the
header parsing branch that currently matches `strip_prefix("+++ b/")` and the
`current_path` lookup used before `parse_hunk_range` to also recognize the
quoted `+++ "b/..."` form, or otherwise disable Git path quoting for these
diffs. Keep the `+++ /dev/null` handling intact and ensure the `missing file`
error is no longer triggered for valid quoted paths.
- Around line 79-116: The changed-line collection in `extend_changed_lines` is
merging ranges from `merge_base..HEAD`, `--cached`, and the unstaged diff
without normalizing them to the same tree state. Update the logic in
`src/discovery/git.rs` so `changed_files` is built from one consistent snapshot
before unioning ranges, using the existing helpers like `extend_changed_lines`
and `extend_untracked_changed_lines` to rebase each hunk to the same coordinate
space.
---
Nitpick comments:
In `@src/lib.rs`:
- Around line 98-111: The duplicate scan path still discovers, processes, and
detects duplicates for every file even when the branch scope is empty, which
defeats the intended short-circuit for -git-branch/-git-branch-strict. Update
the flow around changed_branch_scope, discover_report_files,
line::process_source_files, and report::detect_duplicate_blocks so that when
branch_scope.files() is empty you pass an empty file slice into discovery and
skip downstream processing/detection entirely, letting the later filtering stay
empty without doing work.
In `@src/report/duplicate_renderer.rs`:
- Around line 282-309: Add a duplicate-report test covering the changed_lines
suffix formatting in
duplicate_renderer::renders_analyzed_file_list_only_in_verbose_mode. The current
test only exercises AnalyzedFile entries with changed_lines: None, so extend it
to include a case with a populated changed_lines range and assert the rendered
verbose output matches the same line-range suffix contract used in
complexity_renderer’s test (the "(3-17,21)"-style formatting). Use the
format_analyzed_file and format_line_ranges output path as the behavior to
verify, while keeping the existing verbose/quiet assertions intact.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 16660b9b-7397-4fbb-bf55-f4de3b33efcf
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (11)
Cargo.tomlREADME.mdsrc/cli/args.rssrc/cli/help.rssrc/cli/mod.rssrc/discovery/git.rssrc/discovery/mod.rssrc/lib.rssrc/model.rssrc/report/complexity_renderer.rssrc/report/duplicate_renderer.rs
📜 Review details
🔇 Additional comments (12)
Cargo.toml (1)
3-3: LGTM!README.md (1)
4-11: LGTM!Also applies to: 22-27, 45-59, 81-94, 103-119, 153-168
src/report/duplicate_renderer.rs (1)
4-11: LGTM!Also applies to: 63-95, 174-175
src/report/complexity_renderer.rs (1)
4-11: LGTM!Also applies to: 85-122, 222-259
src/lib.rs (1)
14-40: LGTM!Also applies to: 112-117, 136-160, 172-212, 277-277, 292-304, 321-435, 752-804, 940-1016
src/model.rs (1)
3-19: LGTM!src/cli/mod.rs (1)
31-31: LGTM!src/cli/args.rs (2)
23-24: LGTM!Also applies to: 67-77, 117-121, 135-143, 282-283
313-313: LGTM!Also applies to: 361-370, 422-422, 497-516, 526-534
src/cli/help.rs (1)
9-25: LGTM!Also applies to: 56-78, 105-105, 124-124, 134-162
src/discovery/git.rs (1)
7-7: LGTM!src/discovery/mod.rs (1)
7-7: LGTM!
|
@CodeRabbit resume |
✅ Action performedReviews resumed. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/discovery/git.rs`:
- Around line 248-321: The quoted git path parsing in
parse_quoted_diff_path/parse_diff_escape/parse_diff_octal_escape is decoding
octal escapes into chars one byte at a time, which corrupts non-ASCII filenames.
Change the implementation to accumulate raw bytes for the escaped path,
interpret simple and octal escapes as bytes, and then decode the full buffer
once with String::from_utf8 so paths like café.txt are preserved correctly. Keep
the existing error handling and locate the fix in the quoted-path parsing
helpers in src/discovery/git.rs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 9d48a0be-72f7-44e7-9d64-ec255a89131d
📒 Files selected for processing (2)
src/cli/help.rssrc/discovery/git.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- src/cli/help.rs
📜 Review details
🔇 Additional comments (2)
src/discovery/git.rs (2)
199-246: LGTM!
383-390: LGTM!Also applies to: 478-485, 561-645
|
@CodeRabbit resume |
✅ Action performedReviews resumed. |
Summary by CodeRabbit
0.7.4.