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

Method populate

crates/vcsql/src/providers/refs.rs:13–79  ·  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 refs (
17 name, full_name, target_id, kind, is_symbolic, symbolic_target, repo
18 ) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)
19 "#,
20 )?;
21
22 let repo_path = repo.path().to_string();
23 let git_repo = repo.inner();
24
25 for reference_result in git_repo.references()? {
26 let reference = reference_result?;
27
28 let full_name = reference.name().unwrap_or("").to_string();
29 let short_name = reference.shorthand().unwrap_or("").to_string();
30
31 let kind = if full_name.starts_with("refs/heads/") {
32 "branch"
33 } else if full_name.starts_with("refs/remotes/") {
34 "remote"
35 } else if full_name.starts_with("refs/tags/") {
36 "tag"
37 } else if full_name.starts_with("refs/notes/") {
38 "note"
39 } else if full_name.starts_with("refs/stash") {
40 "stash"
41 } else {
42 "other"
43 };
44
45 let is_symbolic = reference.kind() == Some(git2::ReferenceType::Symbolic);
46
47 let symbolic_target = if is_symbolic {
48 reference.symbolic_target().map(|s| s.to_string())
49 } else {
50 None
51 };
52
53 let target_id = if is_symbolic {
54 reference
55 .resolve()
56 .ok()
57 .and_then(|r| r.target())
58 .map(|oid| oid.to_string())
59 .unwrap_or_default()
60 } else {
61 reference
62 .target()
63 .map(|oid| oid.to_string())
64 .unwrap_or_default()
65 };
66
67 stmt.execute((
68 &short_name,
69 &full_name,
70 &target_id,

Callers 1

load_tableMethod · 0.45

Calls 3

pathMethod · 0.80
innerMethod · 0.80
executeMethod · 0.45

Tested by

no test coverage detected