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 × log C) where S is the number of views and C is the number of ch
(
txn: &T,
inode: Inode,
current_view: &str,
)
| 24 | /// on `REV_STACK_CHANGES` via [`ViewTxnT::get_change_seq`], rather than |
| 25 | /// linearly scanning the entire change log. |
| 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 | // O(log C) B-tree lookup on REV_STACK_CHANGES instead of |
| 59 | // iterating the entire change log. |
| 60 | if let Ok(Some(_seq)) = txn.get_change_seq(&view, creating_change) { |
| 61 | // Another view still references this file — not safe to remove. |
| 62 | return false; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | // No other view references the creating change. |
| 67 | true |
| 68 | } |
| 69 | |
| 70 | /// Timing details for the git-import fresh-write path. |
| 71 | #[derive(Debug, Clone, Copy, Default)] |
no test coverage detected