Whether any Git ref under `refs/atomic/keep/…` byte-references the change hash. Unreadable refs count as roots (conservative, CB-13A R1).
(
&self,
_txn: &atomic_core::pristine::ReadTxn,
base32: &str,
)
| 836 | /// Whether any Git ref under `refs/atomic/keep/…` byte-references the |
| 837 | /// change hash. Unreadable refs count as roots (conservative, CB-13A R1). |
| 838 | fn git_keep_refs_reference( |
| 839 | &self, |
| 840 | _txn: &atomic_core::pristine::ReadTxn, |
| 841 | base32: &str, |
| 842 | ) -> Result<bool, RepositoryError> { |
| 843 | // A repository without Git has no keep refs: provable absence (the |
| 844 | // non-git fixture path must prune as before). |
| 845 | let git = match git2::Repository::open(self.root()) { |
| 846 | Ok(git) => git, |
| 847 | Err(_) => return Ok(false), |
| 848 | }; |
| 849 | let _keep_prefix = "refs/atomic/keep/"; |
| 850 | let mut any_ref = false; |
| 851 | for reference in git |
| 852 | .references_glob("refs/atomic/keep/*") |
| 853 | .map_err(|error| RepositoryError::Database(error.to_string()))? |
| 854 | { |
| 855 | let reference = |
| 856 | reference.map_err(|error| RepositoryError::Database(error.to_string()))?; |
| 857 | any_ref = true; |
| 858 | let bytes: Vec<u8> = reference |
| 859 | .peel_to_commit() |
| 860 | .and_then(|commit| { |
| 861 | let odb = git |
| 862 | .odb() |
| 863 | .map_err(|e| git2::Error::from_str(&e.to_string()))?; |
| 864 | odb.read(commit.id()) |
| 865 | .map(|object| object.data().to_vec()) |
| 866 | .map_err(|e| git2::Error::from_str(&e.to_string())) |
| 867 | }) |
| 868 | .unwrap_or_default(); |
| 869 | // Byte scan: the raw 32-byte hash and its base32 text both pin. |
| 870 | if bytes.windows(32).any(|window| { |
| 871 | window |
| 872 | == Hash::from_base32(base32.as_bytes()) |
| 873 | .map(|h| h.0) |
| 874 | .unwrap_or([0u8; 32]) |
| 875 | }) || String::from_utf8_lossy(&bytes).contains(base32) |
| 876 | { |
| 877 | return Ok(true); |
| 878 | } |
| 879 | } |
| 880 | // No keep refs exist: absence is provable (nothing can be pinned). |
| 881 | let _ = any_ref; |
| 882 | Ok(false) |
| 883 | } |
| 884 | |
| 885 | /// Whether sessions, WIP/shelf workspaces, recovery backups, or the |
| 886 | /// shim workspace metadata still reference the object (CB-13A R1). |