MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / is_file_only_on_view

Function is_file_only_on_view

atomic-repository/src/repository/insert.rs:26–68  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

24/// on `REV_STACK_CHANGES` via [`ViewTxnT::get_change_seq`], rather than
25/// linearly scanning the entire change log.
26fn 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)]

Callers 3

write_import_recordedMethod · 0.85
insert_changeMethod · 0.85
write_recordedMethod · 0.85

Calls 5

inode_positionMethod · 0.45
is_rootMethod · 0.45
list_viewsMethod · 0.45
get_viewMethod · 0.45
get_change_seqMethod · 0.45

Tested by

no test coverage detected