Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ categories = ["development-tools", "command-line-utilities"]
readme = "README.md"

[workspace.dependencies]
tracing = "0.1"
anyhow = "1.0.101"
thiserror = "2.0.18"
serde = { version = "1.0.228", features = ["derive"] }
Expand Down
1 change: 1 addition & 0 deletions crates/diffguard-diff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ readme = "README.md"
[dependencies]
anyhow.workspace = true
thiserror.workspace = true
tracing.workspace = true

diffguard-types = { version = "0.2", path = "../diffguard-types" }

Expand Down
26 changes: 25 additions & 1 deletion crates/diffguard-diff/src/unified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ pub fn parse_unified_diff(
scope: Scope,
) -> Result<(Vec<DiffLine>, DiffStats), DiffParseError> {
let mut out: Vec<DiffLine> = Vec::new();
tracing::debug!(input_bytes = diff_text.len(), "diff_parse_start");
let mut current_path: Option<String> = None;

let mut old_line_no: u32 = 0;
Expand Down Expand Up @@ -178,24 +179,40 @@ pub fn parse_unified_diff(
// Detect binary files (Requirements 4.1)
if is_binary_file(raw) {
skip_current_file = true;
tracing::debug!(
path = current_path.as_deref().unwrap_or("<unknown>"),
"file_skip_binary"
);
continue;
}

// Detect submodule changes (Requirements 4.2)
if is_submodule(raw) {
skip_current_file = true;
tracing::debug!(
path = current_path.as_deref().unwrap_or("<unknown>"),
"file_skip_submodule"
);
continue;
}

// Detect deleted files (Requirements 4.5)
if is_deleted_file(raw) {
skip_current_file = !matches!(scope, Scope::Deleted);
tracing::debug!(
path = current_path.as_deref().unwrap_or("<unknown>"),
"file_skip_deleted"
);
continue;
}

// Detect mode changes (Requirements 4.4)
// Mode-only changes are skipped - they have no content to scan
if is_mode_change_only(raw) {
tracing::debug!(
path = current_path.as_deref().unwrap_or("<unknown>"),
"file_skip_mode_only"
);
continue;
}

Expand Down Expand Up @@ -235,8 +252,14 @@ pub fn parse_unified_diff(
new_line_no = hdr.new_start;
in_hunk = true;
pending_removed = false;
tracing::trace!(
old_start = hdr.old_start,
new_start = hdr.new_start,
"hunk_header"
);
}
Err(_) => {
Err(err) => {
tracing::debug!(error = ?err, "diff_parse_error");
// Malformed hunk header - skip this hunk but continue processing
// This allows subsequent files to be processed (Requirements 4.6)
in_hunk = false;
Expand Down Expand Up @@ -341,6 +364,7 @@ pub fn parse_unified_diff(
.map_err(|_| DiffParseError::Overflow(format!("too many lines (> {})", u32::MAX)))?,
};

tracing::debug!(lines_output = out.len(), stats = ?stats, "diff_parse_complete");
Ok((out, stats))
}

Expand Down
Loading
Loading