Check whether a file's creating change exists ONLY on the given view (and no other view). Returns `true` when it is safe to remove the file's TREE / INODES entries because no other view needs them. When the inode has no INODES position (not yet recorded) the function returns `true` — there is nothing to protect. # Complexity O(S × C) in the worst case, where S is the number of views and C is t
(
txn: &T,
inode: Inode,
current_view: &str,
)
| 24 | /// number of visible changes per view. Path deletion is uncommon, and using |
| 25 | /// the canonical inherited-view filter is required for correctness on drafts. |
| 26 | fn is_file_only_on_view<T: GraphTxnT + ViewTxnT + TreeTxnT>( |
| 27 | txn: &T, |
| 28 | inode: Inode, |
| 29 | current_view: &str, |
| 30 | ) -> bool { |
| 31 | // Look up the position for this inode. If there is no position the |
| 32 | // file was never recorded, so removing from TREE is safe. |
| 33 | let position = match txn.inode_position(inode) { |
| 34 | Ok(Some(pos)) => pos, |
| 35 | _ => return true, |
| 36 | }; |
| 37 | |
| 38 | let creating_change = position.change; |
| 39 | if creating_change.is_root() { |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | // Walk every view and check whether the creating change appears on |
| 44 | // any view OTHER than `current_view`. |
| 45 | let view_names = match txn.list_views() { |
| 46 | Ok(names) => names, |
| 47 | Err(_) => return true, |
| 48 | }; |
| 49 | |
| 50 | for name in view_names { |
| 51 | if name == current_view { |
| 52 | continue; |
| 53 | } |
| 54 | let view = match txn.get_view(&name) { |
| 55 | Ok(Some(s)) => s, |
| 56 | _ => continue, |
| 57 | }; |
| 58 | if collect_visible_change_ids(txn, &view) |
| 59 | .map(|ids| ids.contains(&creating_change)) |
| 60 | .unwrap_or(false) |
| 61 | { |
| 62 | // Another view still references this file — not safe to remove. |
| 63 | return false; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | // No other view references the creating change. |
| 68 | true |
| 69 | } |
| 70 | |
| 71 | /// Timing details for the git-import fresh-write path. |
| 72 | #[derive(Debug, Clone, Copy, Default)] |
no test coverage detected