(&self, conn: &Connection, repo: &mut GitRepo)
| 11 | } |
| 12 | |
| 13 | fn populate(&self, conn: &Connection, repo: &mut GitRepo) -> Result<()> { |
| 14 | let mut stmt = conn.prepare( |
| 15 | r#" |
| 16 | INSERT INTO diffs ( |
| 17 | commit_id, parent_id, files_changed, insertions, deletions, repo |
| 18 | ) VALUES (?1, ?2, ?3, ?4, ?5, ?6) |
| 19 | "#, |
| 20 | )?; |
| 21 | |
| 22 | let repo_path = repo.path().to_string(); |
| 23 | let git_repo = repo.inner(); |
| 24 | |
| 25 | for commit_result in repo.walk_commits()? { |
| 26 | let commit = commit_result?; |
| 27 | let commit_id = commit.id().to_string(); |
| 28 | let tree = commit.tree()?; |
| 29 | |
| 30 | if commit.parent_count() == 0 { |
| 31 | // Root commit - diff against empty tree |
| 32 | let diff = git_repo.diff_tree_to_tree(None, Some(&tree), None)?; |
| 33 | let stats = diff.stats()?; |
| 34 | |
| 35 | stmt.execute(( |
| 36 | &commit_id, |
| 37 | Option::<String>::None, |
| 38 | stats.files_changed() as i64, |
| 39 | stats.insertions() as i64, |
| 40 | stats.deletions() as i64, |
| 41 | &repo_path, |
| 42 | ))?; |
| 43 | } else { |
| 44 | // Diff against each parent |
| 45 | for parent in commit.parents() { |
| 46 | let parent_id = parent.id().to_string(); |
| 47 | let parent_tree = parent.tree()?; |
| 48 | |
| 49 | let diff = git_repo.diff_tree_to_tree(Some(&parent_tree), Some(&tree), None)?; |
| 50 | let stats = diff.stats()?; |
| 51 | |
| 52 | stmt.execute(( |
| 53 | &commit_id, |
| 54 | Some(&parent_id), |
| 55 | stats.files_changed() as i64, |
| 56 | stats.insertions() as i64, |
| 57 | stats.deletions() as i64, |
| 58 | &repo_path, |
| 59 | ))?; |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | Ok(()) |
| 65 | } |
| 66 | } |
nothing calls this directly
no test coverage detected