-
-
Notifications
You must be signed in to change notification settings - Fork 1
F-011: refactor(services): replace byte indexing with strip_prefix #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -995,21 +995,20 @@ impl ContextBuilder { | |
| continue; | ||
| } | ||
| // Detect added/removed import lines | ||
| if (line.starts_with('+') && Self::is_import_line(&line[1..])) | ||
| || (line.starts_with('-') && Self::is_import_line(&line[1..])) | ||
| { | ||
| let action = if line.starts_with('+') { | ||
| "added" | ||
| } else { | ||
| "removed" | ||
| }; | ||
| let (action, content) = if let Some(rest) = line.strip_prefix('+') { | ||
| ("added", rest) | ||
| } else if let Some(rest) = line.strip_prefix('-') { | ||
| ("removed", rest) | ||
| } else { | ||
| continue; | ||
| }; | ||
| if Self::is_import_line(content) { | ||
| let stem = file | ||
| .path | ||
| .file_stem() | ||
| .and_then(|s| s.to_str()) | ||
| .unwrap_or("?"); | ||
| let content = line[1..].trim(); | ||
| imports.push(format!("{}: {} {}", stem, action, content)); | ||
| imports.push(format!("{}: {} {}", stem, action, content.trim())); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -1067,11 +1066,13 @@ impl ContextBuilder { | |
| let filename = file.path.file_name().and_then(|n| n.to_str()).unwrap_or(""); | ||
|
|
||
| for line in file.diff.lines() { | ||
| if !line.starts_with('+') || line.starts_with("+++") { | ||
| if line.starts_with("+++") { | ||
| continue; | ||
| } | ||
| let Some(content) = line.strip_prefix('+') else { | ||
| continue; | ||
| }; | ||
| total_added += 1; | ||
| let content = &line[1..]; | ||
| let trimmed = content.trim(); | ||
|
|
||
| // Error handling patterns | ||
|
|
@@ -1207,13 +1208,17 @@ impl ContextBuilder { | |
| let name = file.path.file_name().and_then(|n| n.to_str()).unwrap_or(""); | ||
|
|
||
| for line in file.diff.lines() { | ||
| let is_removed = line.starts_with('-') && !line.starts_with("---"); | ||
| let is_added = line.starts_with('+') && !line.starts_with("+++"); | ||
| let content = if is_removed || is_added { | ||
| &line[1..] | ||
| if line.starts_with("+++") || line.starts_with("---") { | ||
| continue; | ||
| } | ||
| let (is_added, content) = if let Some(rest) = line.strip_prefix('+') { | ||
| (true, rest) | ||
| } else if let Some(rest) = line.strip_prefix('-') { | ||
| (false, rest) | ||
|
Comment on lines
+1211
to
+1217
|
||
| } else { | ||
| continue; | ||
| }; | ||
| let is_removed = !is_added; | ||
|
|
||
| match name { | ||
| "Cargo.toml" => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -314,8 +314,9 @@ pub fn scan_full_diff_with_patterns( | |||||||||
| } | ||||||||||
|
|
||||||||||
| // Only check added lines | ||||||||||
| if line.starts_with('+') && !line.starts_with("+++") { | ||||||||||
| let content = &line[1..]; | ||||||||||
| if !line.starts_with("+++") | ||||||||||
| && let Some(content) = line.strip_prefix('+') | ||||||||||
| { | ||||||||||
|
Comment on lines
+317
to
+319
|
||||||||||
| if !line.starts_with("+++") | |
| && let Some(content) = line.strip_prefix('+') | |
| { | |
| if let Some(content) = line.strip_prefix('+') { |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -197,13 +197,13 @@ impl CommitSplitter { | |
| let mut indent_only_changes = 0usize; | ||
| let added_lines: Vec<&str> = lines | ||
| .iter() | ||
| .filter(|l| l.starts_with('+') && !l.starts_with("+++")) | ||
| .map(|l| &l[1..]) | ||
| .filter(|l| !l.starts_with("+++")) | ||
| .filter_map(|l| l.strip_prefix('+')) | ||
| .collect(); | ||
| let removed_lines: Vec<&str> = lines | ||
| .iter() | ||
| .filter(|l| l.starts_with('-') && !l.starts_with("---")) | ||
| .map(|l| &l[1..]) | ||
| .filter(|l| !l.starts_with("---")) | ||
| .filter_map(|l| l.strip_prefix('-')) | ||
|
Comment on lines
199
to
+206
|
||
| .collect(); | ||
|
|
||
| for added_line in &added_lines { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
line.starts_with("+++")skip here can drop legitimate added hunk lines whose content begins with"++"(diff line starts with"+++"), which would undercounttotal_addedand bias intent detection. Consider tracking whether the loop is inside a hunk (after@@) and only skipping+++headers outside hunks (or otherwise using more stateful header detection).