(&mut self)
| 507 | } |
| 508 | |
| 509 | fn load_diffs(&mut self) -> Result<()> { |
| 510 | self.conn.execute( |
| 511 | "CREATE TABLE IF NOT EXISTS diffs ( |
| 512 | commit_id TEXT PRIMARY KEY, |
| 513 | files_changed INTEGER, |
| 514 | insertions INTEGER, |
| 515 | deletions INTEGER |
| 516 | )", |
| 517 | [], |
| 518 | )?; |
| 519 | |
| 520 | if let Ok(repo) = git2::Repository::open(&self.git_repo_path) { |
| 521 | let mut revwalk = repo.revwalk().map_err(|e| Error::Vcsql(e.to_string()))?; |
| 522 | revwalk.push_head().ok(); |
| 523 | |
| 524 | for oid in revwalk.filter_map(|r| r.ok()) { |
| 525 | let Ok(commit) = repo.find_commit(oid) else { |
| 526 | continue; |
| 527 | }; |
| 528 | |
| 529 | let commit_tree = match commit.tree() { |
| 530 | Ok(t) => t, |
| 531 | Err(_) => continue, |
| 532 | }; |
| 533 | |
| 534 | let parent_tree = if commit.parent_count() > 0 { |
| 535 | commit.parent(0).ok().and_then(|p| p.tree().ok()) |
| 536 | } else { |
| 537 | None |
| 538 | }; |
| 539 | |
| 540 | let diff = |
| 541 | match repo.diff_tree_to_tree(parent_tree.as_ref(), Some(&commit_tree), None) { |
| 542 | Ok(d) => d, |
| 543 | Err(_) => continue, |
| 544 | }; |
| 545 | |
| 546 | let stats = match diff.stats() { |
| 547 | Ok(s) => s, |
| 548 | Err(_) => continue, |
| 549 | }; |
| 550 | |
| 551 | let commit_id = commit.id().to_string(); |
| 552 | self.conn.execute( |
| 553 | "INSERT OR IGNORE INTO diffs VALUES (?1, ?2, ?3, ?4)", |
| 554 | params![ |
| 555 | commit_id, |
| 556 | stats.files_changed() as i64, |
| 557 | stats.insertions() as i64, |
| 558 | stats.deletions() as i64, |
| 559 | ], |
| 560 | )?; |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | Ok(()) |
| 565 | } |
| 566 |
no test coverage detected