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

Method populate

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

Source from the content-addressed store, hash-verified

12 }
13
14 fn populate(&self, conn: &Connection, repo: &mut GitRepo) -> Result<()> {
15 let mut stmt = conn.prepare(
16 r#"
17 INSERT INTO branches (
18 name, full_name, target_id, is_remote, is_head,
19 remote_name, upstream, ahead, behind, repo
20 ) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10)
21 "#,
22 )?;
23
24 let repo_path = repo.path().to_string();
25
26 let head_target = repo
27 .head()
28 .ok()
29 .and_then(|h| h.target())
30 .map(|oid| oid.to_string());
31
32 let is_detached = repo.is_head_detached();
33
34 for branch_result in repo.branches(None)? {
35 let (branch, branch_type) = branch_result?;
36
37 let name = branch.name()?.unwrap_or("").to_string();
38 let reference = branch.get();
39 let full_name = reference.name().unwrap_or("").to_string();
40
41 let target_id = reference
42 .peel_to_commit()
43 .map(|c| c.id().to_string())
44 .unwrap_or_default();
45
46 let is_remote = matches!(branch_type, BranchType::Remote);
47
48 let is_head = if is_detached {
49 false
50 } else {
51 head_target
52 .as_ref()
53 .map(|h| h == &target_id && !is_remote)
54 .unwrap_or(false)
55 && reference.is_branch()
56 && repo
57 .head()
58 .ok()
59 .and_then(|h| h.name().map(|n| n == full_name))
60 .unwrap_or(false)
61 };
62
63 let remote_name: Option<String> = if is_remote {
64 name.split('/').next().map(|s| s.to_string())
65 } else {
66 None
67 };
68
69 let (upstream, ahead, behind) = if !is_remote {
70 if let Ok(upstream_branch) = branch.upstream() {
71 let upstream_name =

Callers

nothing calls this directly

Calls 6

pathMethod · 0.80
headMethod · 0.80
is_head_detachedMethod · 0.80
branchesMethod · 0.80
graph_ahead_behindMethod · 0.80
executeMethod · 0.45

Tested by

no test coverage detected