| 56 | } |
| 57 | |
| 58 | fn insert_diff_files( |
| 59 | stmt: &mut rusqlite::Statement, |
| 60 | diff: &git2::Diff, |
| 61 | commit_id: &str, |
| 62 | parent_id: Option<&str>, |
| 63 | repo_path: &str, |
| 64 | ) -> Result<()> { |
| 65 | for (delta_idx, delta) in diff.deltas().enumerate() { |
| 66 | let old_path = delta |
| 67 | .old_file() |
| 68 | .path() |
| 69 | .map(|p| p.to_string_lossy().to_string()); |
| 70 | let new_path = delta |
| 71 | .new_file() |
| 72 | .path() |
| 73 | .map(|p| p.to_string_lossy().to_string()); |
| 74 | |
| 75 | let status = match delta.status() { |
| 76 | Delta::Added => "A", |
| 77 | Delta::Deleted => "D", |
| 78 | Delta::Modified => "M", |
| 79 | Delta::Renamed => "R", |
| 80 | Delta::Copied => "C", |
| 81 | Delta::Typechange => "T", |
| 82 | Delta::Unmodified => "U", |
| 83 | Delta::Ignored => "I", |
| 84 | Delta::Untracked => "?", |
| 85 | Delta::Conflicted => "X", |
| 86 | Delta::Unreadable => "!", |
| 87 | }; |
| 88 | |
| 89 | let is_binary = delta.old_file().is_binary() || delta.new_file().is_binary(); |
| 90 | |
| 91 | // Get line stats for this specific file |
| 92 | let mut insertions = 0i64; |
| 93 | let mut deletions = 0i64; |
| 94 | |
| 95 | if let Ok(Some(patch)) = git2::Patch::from_diff(diff, delta_idx) { |
| 96 | let (_, adds, dels) = patch.line_stats()?; |
| 97 | insertions = adds as i64; |
| 98 | deletions = dels as i64; |
| 99 | } |
| 100 | |
| 101 | // Similarity percentage is not directly available in git2-rs API |
| 102 | // We'd need to compute it ourselves or skip it |
| 103 | let similarity: Option<i64> = None; |
| 104 | |
| 105 | stmt.execute(( |
| 106 | commit_id, |
| 107 | parent_id, |
| 108 | &old_path, |
| 109 | &new_path, |
| 110 | status, |
| 111 | insertions, |
| 112 | deletions, |
| 113 | if is_binary { 1 } else { 0 }, |
| 114 | similarity, |
| 115 | repo_path, |