(&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 reflog ( |
| 18 | ref_name, entry_index, old_id, new_id, |
| 19 | committer_name, committer_email, committed_at, |
| 20 | message, action, repo |
| 21 | ) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10) |
| 22 | "#, |
| 23 | )?; |
| 24 | |
| 25 | let repo_path = repo.path().to_string(); |
| 26 | let git_repo = repo.inner(); |
| 27 | |
| 28 | // Get reflog for HEAD |
| 29 | if let Ok(reflog) = git_repo.reflog("HEAD") { |
| 30 | for (index, entry) in reflog.iter().enumerate() { |
| 31 | let old_id = entry.id_old().to_string(); |
| 32 | let new_id = entry.id_new().to_string(); |
| 33 | |
| 34 | let committer = entry.committer(); |
| 35 | let committer_name = committer.name().unwrap_or("").to_string(); |
| 36 | let committer_email = committer.email().unwrap_or("").to_string(); |
| 37 | let committed_at = format_git_time(committer.when()); |
| 38 | |
| 39 | let message = entry.message().unwrap_or("").to_string(); |
| 40 | let action = extract_action(&message); |
| 41 | |
| 42 | stmt.execute(( |
| 43 | "HEAD", |
| 44 | index as i64, |
| 45 | &old_id, |
| 46 | &new_id, |
| 47 | &committer_name, |
| 48 | &committer_email, |
| 49 | &committed_at, |
| 50 | &message, |
| 51 | &action, |
| 52 | &repo_path, |
| 53 | ))?; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // Get reflog for all branches |
| 58 | for reference in git_repo.references()?.flatten() { |
| 59 | if let Some(name) = reference.name() { |
| 60 | if name.starts_with("refs/heads/") { |
| 61 | if let Ok(reflog) = git_repo.reflog(name) { |
| 62 | for (index, entry) in reflog.iter().enumerate() { |
| 63 | let old_id = entry.id_old().to_string(); |
| 64 | let new_id = entry.id_new().to_string(); |
| 65 | |
| 66 | let committer = entry.committer(); |
| 67 | let committer_name = committer.name().unwrap_or("").to_string(); |
| 68 | let committer_email = committer.email().unwrap_or("").to_string(); |
| 69 | let committed_at = format_git_time(committer.when()); |
| 70 | |
| 71 | let message = entry.message().unwrap_or("").to_string(); |
nothing calls this directly
no test coverage detected