Rebuild the FILE_INDEX from the current working copy. Walks every tracked file, stats it on disk, hashes its content, and stores (mtime, size, content_hash) in the FILE_INDEX. After this call, `status` can use the fast stat-comparison path instead of reconstructing graph content for every file. This is essential after `git import` where `restore_from_git` resets all file mtimes, invalidating an
(&self)
| 618 | /// |
| 619 | /// The number of files indexed. |
| 620 | pub fn reindex_working_copy(&self) -> Result<usize, RepositoryError> { |
| 621 | use std::time::SystemTime; |
| 622 | |
| 623 | let tracked = self.list_tracked_files().unwrap_or_default(); |
| 624 | let repo_root = self.root.clone(); |
| 625 | |
| 626 | let mut entries: Vec<(String, i64, u32, u64, Hash)> = Vec::with_capacity(tracked.len()); |
| 627 | |
| 628 | for file in &tracked { |
| 629 | let abs = repo_root.join(&file.path); |
| 630 | if !abs.exists() || abs.is_dir() { |
| 631 | continue; |
| 632 | } |
| 633 | |
| 634 | let metadata = match std::fs::metadata(&abs) { |
| 635 | Ok(m) => m, |
| 636 | Err(_) => continue, |
| 637 | }; |
| 638 | |
| 639 | let mtime = metadata.modified().unwrap_or(SystemTime::UNIX_EPOCH); |
| 640 | let duration = mtime |
| 641 | .duration_since(SystemTime::UNIX_EPOCH) |
| 642 | .unwrap_or_default(); |
| 643 | let secs = duration.as_secs() as i64; |
| 644 | let nanos = duration.subsec_nanos(); |
| 645 | let size = metadata.len(); |
| 646 | |
| 647 | let content_hash = match std::fs::read(&abs) { |
| 648 | Ok(bytes) => Hash::of(&bytes), |
| 649 | Err(_) => continue, |
| 650 | }; |
| 651 | |
| 652 | let path_str = file.path.to_string_lossy().replace('\\', "/"); |
| 653 | entries.push((path_str, secs, nanos, size, content_hash)); |
| 654 | } |
| 655 | |
| 656 | let count = entries.len(); |
| 657 | |
| 658 | // Write in batches of 5000 to avoid holding the write txn too long |
| 659 | for chunk in entries.chunks(5000) { |
| 660 | self.update_file_index(chunk)?; |
| 661 | } |
| 662 | |
| 663 | Ok(count) |
| 664 | } |
| 665 | |
| 666 | /// List tracked files under a given path prefix. |
| 667 | /// Get all tracked files under a directory prefix. |
no test coverage detected