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

Method load_commits

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

Source from the content-addressed store, hash-verified

454 }
455
456 fn load_commits(&mut self) -> Result<()> {
457 self.conn.execute(
458 "CREATE TABLE IF NOT EXISTS commits (
459 id TEXT PRIMARY KEY,
460 short_id TEXT,
461 author_name TEXT,
462 author_email TEXT,
463 authored_at TEXT,
464 summary TEXT,
465 message TEXT,
466 is_merge INTEGER
467 )",
468 [],
469 )?;
470
471 // Use git2 to load commits
472 if let Ok(repo) = git2::Repository::open(&self.git_repo_path) {
473 let mut revwalk = repo.revwalk().map_err(|e| Error::Vcsql(e.to_string()))?;
474 revwalk.push_head().ok();
475
476 for oid in revwalk.filter_map(|r| r.ok()) {
477 if let Ok(commit) = repo.find_commit(oid) {
478 let id = commit.id().to_string();
479 let short_id = &id[..7.min(id.len())];
480 let author = commit.author();
481 let author_name = author.name().unwrap_or("");
482 let author_email = author.email().unwrap_or("");
483 let time = commit.time();
484 let authored_at = format_git_time(time.seconds());
485 let summary = commit.summary().unwrap_or("");
486 let message = commit.message().unwrap_or("");
487 let is_merge = if commit.parent_count() > 1 { 1 } else { 0 };
488
489 self.conn.execute(
490 "INSERT OR IGNORE INTO commits VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)",
491 params![
492 id,
493 short_id,
494 author_name,
495 author_email,
496 authored_at,
497 summary,
498 message,
499 is_merge
500 ],
501 )?;
502 }
503 }
504 }
505
506 Ok(())
507 }
508
509 fn load_diffs(&mut self) -> Result<()> {
510 self.conn.execute(

Callers 1

load_git_tablesMethod · 0.80

Calls 2

format_git_timeFunction · 0.70
executeMethod · 0.45

Tested by

no test coverage detected