MCPcopy Create free account
hub / github.com/douglance/devsql / load_diff_files

Method load_diff_files

crates/devsql/src/engine.rs:567–644  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

565 }
566
567 fn load_diff_files(&mut self) -> Result<()> {
568 self.conn.execute(
569 "CREATE TABLE IF NOT EXISTS diff_files (
570 commit_id TEXT,
571 path TEXT,
572 status TEXT,
573 insertions INTEGER,
574 deletions INTEGER
575 )",
576 [],
577 )?;
578
579 if let Ok(repo) = git2::Repository::open(&self.git_repo_path) {
580 let mut revwalk = repo.revwalk().map_err(|e| Error::Vcsql(e.to_string()))?;
581 revwalk.push_head().ok();
582
583 for oid in revwalk.filter_map(|r| r.ok()) {
584 let Ok(commit) = repo.find_commit(oid) else {
585 continue;
586 };
587
588 let commit_tree = match commit.tree() {
589 Ok(t) => t,
590 Err(_) => continue,
591 };
592
593 let parent_tree = if commit.parent_count() > 0 {
594 commit.parent(0).ok().and_then(|p| p.tree().ok())
595 } else {
596 None
597 };
598
599 let diff =
600 match repo.diff_tree_to_tree(parent_tree.as_ref(), Some(&commit_tree), None) {
601 Ok(d) => d,
602 Err(_) => continue,
603 };
604
605 let commit_id = commit.id().to_string();
606
607 for delta_idx in 0..diff.deltas().len() {
608 let delta = diff.deltas().nth(delta_idx).unwrap();
609
610 let path = delta
611 .new_file()
612 .path()
613 .or_else(|| delta.old_file().path())
614 .map(|p| p.to_string_lossy().to_string())
615 .unwrap_or_default();
616
617 let status = match delta.status() {
618 git2::Delta::Added => "A",
619 git2::Delta::Deleted => "D",
620 git2::Delta::Modified => "M",
621 git2::Delta::Renamed => "R",
622 git2::Delta::Copied => "C",
623 _ => "?",
624 };

Callers 1

load_git_tablesMethod · 0.80

Calls 2

pathMethod · 0.80
executeMethod · 0.45

Tested by

no test coverage detected