Observe an already-open repository. This helper is also used by the shim to share HEAD interpretation without changing its mutating reconcile path.
(
root: &Path,
repository: &GitRepository,
)
| 532 | /// Observe an already-open repository. This helper is also used by the shim |
| 533 | /// to share HEAD interpretation without changing its mutating reconcile path. |
| 534 | pub fn observe_open_repository( |
| 535 | root: &Path, |
| 536 | repository: &GitRepository, |
| 537 | ) -> Result<GitRepositoryObservation, ObservationError> { |
| 538 | let worktree_git_dir = resolve_path(repository.path(), root)?; |
| 539 | let common_dir = resolve_common_dir(&worktree_git_dir)?; |
| 540 | let worktree_root = repository |
| 541 | .workdir() |
| 542 | .map(|path| resolve_path(path, root)) |
| 543 | .transpose()?; |
| 544 | |
| 545 | let index = repository |
| 546 | .index() |
| 547 | .map_err(|error| ObservationError::new(format!("cannot read Git index: {error}")))?; |
| 548 | let raw_index_path = index |
| 549 | .path() |
| 550 | .map(Path::to_path_buf) |
| 551 | .unwrap_or_else(|| worktree_git_dir.join("index")); |
| 552 | let index_path = resolve_path(&raw_index_path, &worktree_git_dir)?; |
| 553 | let paths = GitAdminPaths { |
| 554 | worktree_root, |
| 555 | worktree_git_dir, |
| 556 | common_dir, |
| 557 | index_path, |
| 558 | }; |
| 559 | |
| 560 | let head = observe_head(repository)?; |
| 561 | let (head_tree_oid, head_tree_entries) = observe_head_tree(repository, &head)?; |
| 562 | let index = observe_index( |
| 563 | repository, |
| 564 | &index, |
| 565 | &paths.index_path, |
| 566 | head_tree_oid, |
| 567 | &head_tree_entries, |
| 568 | )?; |
| 569 | let locks = observe_locks(&paths)?; |
| 570 | let operation = observe_operation(repository, &paths.worktree_git_dir)?; |
| 571 | let refs = observe_refs(repository)?; |
| 572 | let refs_digest = digest_refs(&refs); |
| 573 | |
| 574 | Ok(GitRepositoryObservation { |
| 575 | paths, |
| 576 | head, |
| 577 | head_tree_oid, |
| 578 | index, |
| 579 | locks, |
| 580 | operation, |
| 581 | refs, |
| 582 | refs_digest, |
| 583 | }) |
| 584 | } |
| 585 | |
| 586 | /// Interpret raw HEAD without requiring it to be attached or born. |
| 587 | pub fn observe_head(repository: &GitRepository) -> Result<HeadObservation, ObservationError> { |
no test coverage detected