Backfill the GIT_SHA_INDEX from existing imported changes. Scans all changes on the current view, looks for `unhashed.git.sha`, and populates the index. Idempotent — skips already-indexed SHAs.
(&self)
| 2624 | /// Scans all changes on the current view, looks for `unhashed.git.sha`, |
| 2625 | /// and populates the index. Idempotent — skips already-indexed SHAs. |
| 2626 | pub fn backfill_git_sha_index(&self) -> Result<usize, RepositoryError> { |
| 2627 | use crate::HistoryOptions; |
| 2628 | use atomic_core::pristine::GitShaIndexTxnT; |
| 2629 | |
| 2630 | let entries = self.log(HistoryOptions::default())?; |
| 2631 | let mut count = 0; |
| 2632 | |
| 2633 | for entry in &entries { |
| 2634 | if let Ok(change) = self.load_change(&entry.hash) { |
| 2635 | if let Some(ref unhashed) = change.unhashed { |
| 2636 | if let Some(git) = unhashed.get("git") { |
| 2637 | if let Some(sha) = git.get("sha").and_then(|v| v.as_str()) { |
| 2638 | // Check if already indexed |
| 2639 | { |
| 2640 | let txn = self |
| 2641 | .pristine |
| 2642 | .read_txn() |
| 2643 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 2644 | if txn.has_git_sha(sha).unwrap_or(false) { |
| 2645 | continue; |
| 2646 | } |
| 2647 | } |
| 2648 | // Index it |
| 2649 | if let Err(e) = self.index_git_sha(sha, &entry.hash) { |
| 2650 | log::warn!( |
| 2651 | "Failed to index git SHA {}: {}", |
| 2652 | &sha[..8.min(sha.len())], |
| 2653 | e |
| 2654 | ); |
| 2655 | } else { |
| 2656 | count += 1; |
| 2657 | } |
| 2658 | } |
| 2659 | } |
| 2660 | } |
| 2661 | } |
| 2662 | } |
| 2663 | |
| 2664 | Ok(count) |
| 2665 | } |
| 2666 | } |
no test coverage detected