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

Method populate

crates/vcsql/src/providers/notes.rs:13–66  ·  view source on GitHub ↗
(&self, conn: &Connection, repo: &mut GitRepo)

Source from the content-addressed store, hash-verified

11 }
12
13 fn populate(&self, conn: &Connection, repo: &mut GitRepo) -> Result<()> {
14 let mut stmt = conn.prepare(
15 r#"
16 INSERT INTO notes (
17 notes_ref, target_id, note_id, content, repo
18 ) VALUES (?1, ?2, ?3, ?4, ?5)
19 "#,
20 )?;
21
22 let repo_path = repo.path().to_string();
23 let git_repo = repo.inner();
24
25 // Find all notes refs
26 for reference in git_repo.references()?.flatten() {
27 if let Some(name) = reference.name() {
28 if name.starts_with("refs/notes/") {
29 let notes_ref = name.to_string();
30
31 // Get the notes tree
32 if let Ok(tree) = reference.peel_to_tree() {
33 tree.walk(git2::TreeWalkMode::PreOrder, |_, entry| {
34 // Note entries are named with the target object's SHA
35 if let Some(target_name) = entry.name() {
36 if entry.kind() == Some(git2::ObjectType::Blob) {
37 let target_id = target_name.to_string();
38 let note_id = entry.id().to_string();
39
40 // Read note content
41 let content =
42 if let Ok(blob) = git_repo.find_blob(entry.id()) {
43 if !blob.is_binary() {
44 String::from_utf8_lossy(blob.content()).to_string()
45 } else {
46 String::new()
47 }
48 } else {
49 String::new()
50 };
51
52 let _ = stmt.execute((
53 &notes_ref, &target_id, &note_id, &content, &repo_path,
54 ));
55 }
56 }
57 git2::TreeWalkResult::Ok
58 })
59 .ok();
60 }
61 }
62 }
63 }
64
65 Ok(())
66 }
67}

Callers

nothing calls this directly

Calls 3

pathMethod · 0.80
innerMethod · 0.80
executeMethod · 0.45

Tested by

no test coverage detected