Fold the Git tree `tree_oid` into the tree OID the prospective gate must compare against: the complete Git tree MINUS the entries this import declares excluded — the conversion policy's Shim-private paths (`.atomic*/`, `.vault/`) and the import-ignore patterns (e.g. a Rust workspace's `Cargo.lock`). The import synthesizes atomic content only for non-excluded entries, so the projected tree legitim
(
git: &GitRepository,
tree_oid: Oid,
policy: &ConversionPolicy,
)
| 1200 | /// bytes and mode, so the gate stays unforgeable evidence that nothing ELSE |
| 1201 | /// diverged between Git and the projection. |
| 1202 | pub(crate) fn import_expected_tree_oid( |
| 1203 | git: &GitRepository, |
| 1204 | tree_oid: Oid, |
| 1205 | policy: &ConversionPolicy, |
| 1206 | ) -> CliResult<GitObjectId> { |
| 1207 | // Fold the Git tree into the tree OID the prospective gate must compare |
| 1208 | // against: the complete Git tree MINUS the entries the versioned |
| 1209 | // conversion policy declares Shim-private (`.atomic*/`, `.vault/`). |
| 1210 | // No tracked path is ever stripped: RFC tree-fidelity (§8.4 table, line |
| 1211 | // 648) and the colocated status contract (line 844) say tracked entries |
| 1212 | // are never excluded by ignore rules (review ::26 R1/R2). Raw component and |
| 1213 | // prefix bytes are carried through verbatim — never lossy-decoded — |
| 1214 | // and tree objects are encoded canonically |
| 1215 | // (`"<mode> <name>\0<oid>"`, git tree-name ordering) so raw non-UTF-8 |
| 1216 | // names and literal `%`-escape lookalikes survive byte-exact. |
| 1217 | fn is_excluded(policy: &ConversionPolicy, raw_path: &[u8]) -> bool { |
| 1218 | if let Ok(path) = RepoPath::from_bytes(raw_path) { |
| 1219 | return policy.exclusions.exclusion(&path).is_some(); |
| 1220 | } |
| 1221 | false |
| 1222 | } |
| 1223 | |
| 1224 | /// Canonical Git tree-object encoding for one directory's entries: |
| 1225 | /// `"<mode:o> <name>\0<oid-raw>"` per entry, in git tree-name order |
| 1226 | /// (byte compare with `/` appended to tree names), hashed through the |
| 1227 | /// workspace's own per-algorithm object hashing. |
| 1228 | fn fold( |
| 1229 | git: &GitRepository, |
| 1230 | tree: &git2::Tree<'_>, |
| 1231 | prefix: Vec<u8>, |
| 1232 | policy: &ConversionPolicy, |
| 1233 | objects: &mut atomic_repository::repository::GitObjectDatabase, |
| 1234 | ) -> CliResult<Option<GitObjectId>> { |
| 1235 | let mut entries: Vec<(Vec<u8>, u32, GitObjectId, bool)> = Vec::new(); |
| 1236 | for entry in tree.iter() { |
| 1237 | let name = entry.name_bytes().to_vec(); |
| 1238 | let mut path = prefix.clone(); |
| 1239 | if !path.is_empty() { |
| 1240 | path.push(b'/'); |
| 1241 | } |
| 1242 | path.extend_from_slice(&name); |
| 1243 | match entry.kind() { |
| 1244 | Some(git2::ObjectType::Tree) => { |
| 1245 | // An excluded directory never reaches the projection; |
| 1246 | // skip the whole subtree. |
| 1247 | if is_excluded(policy, &path) { |
| 1248 | continue; |
| 1249 | } |
| 1250 | let sub = entry |
| 1251 | .to_object(git) |
| 1252 | .and_then(|object| object.peel_to_tree()) |
| 1253 | .map_err(|error| { |
| 1254 | git_error(format!( |
| 1255 | "cannot read Git subtree '{}': {error}", |
| 1256 | atomic_repository::escape_repo_path(&path) |
| 1257 | )) |
| 1258 | })?; |
| 1259 | let Some(sub_oid) = fold(git, &sub, path, policy, objects)? else { |