Skip to content

Commit

Permalink
tree: fill in valid id to null tree, rename function to empty()
Browse files Browse the repository at this point in the history
If a null tree were written to the store, GitBackend would crash because of
invalid hash length.
  • Loading branch information
yuja committed Aug 10, 2024
1 parent 2053340 commit 61e4bd4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/src/local_working_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ impl TreeState {
let new_matcher = PrefixMatcher::new(&sparse_patterns);
let added_matcher = DifferenceMatcher::new(&new_matcher, &old_matcher);
let removed_matcher = DifferenceMatcher::new(&old_matcher, &new_matcher);
let empty_tree = MergedTree::resolved(Tree::null(self.store.clone(), RepoPathBuf::root()));
let empty_tree = MergedTree::resolved(Tree::empty(self.store.clone(), RepoPathBuf::root()));
let added_stats = self.update(&empty_tree, &tree, &added_matcher).block_on()?;
let removed_stats = self
.update(&tree, &empty_tree, &removed_matcher)
Expand Down
2 changes: 1 addition & 1 deletion lib/src/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ where
if let Some(id) = id {
store.get_tree(dir, id)
} else {
Ok(Tree::null(store.clone(), dir.to_owned()))
Ok(Tree::empty(store.clone(), dir.to_owned()))
}
};
Ok(Some(tree_id_merge.try_map(get_tree)?))
Expand Down
8 changes: 4 additions & 4 deletions lib/src/merged_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl MergedTree {
}
_ => {
let subdir = self.dir().join(name);
Ok(Tree::null(self.store().clone(), subdir.clone()))
Ok(Tree::empty(self.store().clone(), subdir.clone()))
}
})?;
Ok(Some(MergedTree { trees }))
Expand Down Expand Up @@ -642,7 +642,7 @@ impl<'matcher> TreeDiffIterator<'matcher> {
if let Some(trees) = values.to_tree_merge(store, dir)? {
Ok(trees)
} else {
Ok(Merge::resolved(Tree::null(store.clone(), dir.to_owned())))
Ok(Merge::resolved(Tree::empty(store.clone(), dir.to_owned())))
}
}
}
Expand Down Expand Up @@ -846,7 +846,7 @@ impl<'matcher> TreeDiffStreamImpl<'matcher> {
) -> BackendResult<Tree> {
match value {
Some(TreeValue::Tree(tree_id)) => store.get_tree_async(dir, tree_id).await,
_ => Ok(Tree::null(store.clone(), dir.to_owned())),
_ => Ok(Tree::empty(store.clone(), dir.to_owned())),
}
}

Expand All @@ -863,7 +863,7 @@ impl<'matcher> TreeDiffStreamImpl<'matcher> {
.await?;
builder.build()
} else {
Merge::resolved(Tree::null(store, dir.clone()))
Merge::resolved(Tree::empty(store, dir.clone()))
};
Ok(MergedTree { trees })
}
Expand Down
5 changes: 3 additions & 2 deletions lib/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ impl Tree {
}
}

pub fn null(store: Arc<Store>, dir: RepoPathBuf) -> Self {
pub fn empty(store: Arc<Store>, dir: RepoPathBuf) -> Self {
let id = store.empty_tree_id().clone();
Tree {
store,
dir,
id: TreeId::new(vec![]),
id,
data: Arc::new(backend::Tree::default()),
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/tree_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl TreeBuilder {
let (parent, basename) = dir.split().expect("root must be populated");
let tree = populate_trees(tree_cache, store, parent)?
.sub_tree(basename)?
.unwrap_or_else(|| Tree::null(store.clone(), dir.to_owned()));
.unwrap_or_else(|| Tree::empty(store.clone(), dir.to_owned()));
Ok(tree_cache.entry(dir.to_owned()).or_insert(tree))
}

Expand Down

0 comments on commit 61e4bd4

Please sign in to comment.