(&self, conn: &Connection, repo: &mut GitRepo)
| 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 = |
nothing calls this directly
no test coverage detected