mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-20 11:25:34 +00:00
tree: fill in valid id to null tree, rename function to empty()
If a null tree were written to the store, GitBackend would crash because of invalid hash length.
This commit is contained in:
parent
bf2cb55ea7
commit
ed1c07e73e
5 changed files with 10 additions and 9 deletions
|
@ -1315,7 +1315,7 @@ impl TreeState {
|
||||||
let new_matcher = PrefixMatcher::new(&sparse_patterns);
|
let new_matcher = PrefixMatcher::new(&sparse_patterns);
|
||||||
let added_matcher = DifferenceMatcher::new(&new_matcher, &old_matcher);
|
let added_matcher = DifferenceMatcher::new(&new_matcher, &old_matcher);
|
||||||
let removed_matcher = DifferenceMatcher::new(&old_matcher, &new_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 added_stats = self.update(&empty_tree, &tree, &added_matcher).block_on()?;
|
||||||
let removed_stats = self
|
let removed_stats = self
|
||||||
.update(&tree, &empty_tree, &removed_matcher)
|
.update(&tree, &empty_tree, &removed_matcher)
|
||||||
|
|
|
@ -625,7 +625,7 @@ where
|
||||||
if let Some(id) = id {
|
if let Some(id) = id {
|
||||||
store.get_tree(dir, id)
|
store.get_tree(dir, id)
|
||||||
} else {
|
} 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)?))
|
Ok(Some(tree_id_merge.try_map(get_tree)?))
|
||||||
|
|
|
@ -209,7 +209,7 @@ impl MergedTree {
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let subdir = self.dir().join(name);
|
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 }))
|
Ok(Some(MergedTree { trees }))
|
||||||
|
@ -642,7 +642,7 @@ impl<'matcher> TreeDiffIterator<'matcher> {
|
||||||
if let Some(trees) = values.to_tree_merge(store, dir)? {
|
if let Some(trees) = values.to_tree_merge(store, dir)? {
|
||||||
Ok(trees)
|
Ok(trees)
|
||||||
} else {
|
} else {
|
||||||
Ok(Merge::resolved(Tree::null(store.clone(), dir.to_owned())))
|
Ok(Merge::resolved(Tree::empty(store.clone(), dir.to_owned())))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -846,7 +846,7 @@ impl<'matcher> TreeDiffStreamImpl<'matcher> {
|
||||||
) -> BackendResult<Tree> {
|
) -> BackendResult<Tree> {
|
||||||
match value {
|
match value {
|
||||||
Some(TreeValue::Tree(tree_id)) => store.get_tree_async(dir, tree_id).await,
|
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())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -863,7 +863,7 @@ impl<'matcher> TreeDiffStreamImpl<'matcher> {
|
||||||
.await?;
|
.await?;
|
||||||
builder.build()
|
builder.build()
|
||||||
} else {
|
} else {
|
||||||
Merge::resolved(Tree::null(store, dir.clone()))
|
Merge::resolved(Tree::empty(store, dir.clone()))
|
||||||
};
|
};
|
||||||
Ok(MergedTree { trees })
|
Ok(MergedTree { trees })
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
Tree {
|
||||||
store,
|
store,
|
||||||
dir,
|
dir,
|
||||||
id: TreeId::new(vec![]),
|
id,
|
||||||
data: Arc::new(backend::Tree::default()),
|
data: Arc::new(backend::Tree::default()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,7 +136,7 @@ impl TreeBuilder {
|
||||||
let (parent, basename) = dir.split().expect("root must be populated");
|
let (parent, basename) = dir.split().expect("root must be populated");
|
||||||
let tree = populate_trees(tree_cache, store, parent)?
|
let tree = populate_trees(tree_cache, store, parent)?
|
||||||
.sub_tree(basename)?
|
.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))
|
Ok(tree_cache.entry(dir.to_owned()).or_insert(tree))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue