working_copy: remove return value from TreeState::snapshot()

I'll make TreeState::snapshot() return a boolean denoting whether tree_state
is updated or not. New tree_id can be obtained from TreeState, so let's
remove it from the return value.
This commit is contained in:
Yuya Nishihara 2022-10-02 10:43:57 +09:00
parent 9c33062d11
commit e716fe7abf
2 changed files with 8 additions and 5 deletions

View file

@ -460,8 +460,8 @@ impl TreeState {
} }
/// Look for changes to the working copy. If there are any changes, create /// Look for changes to the working copy. If there are any changes, create
/// a new tree from it and return it, and also update the dirstate on disk. /// a new tree from it.
pub fn snapshot(&mut self, base_ignores: Arc<GitIgnoreFile>) -> Result<TreeId, SnapshotError> { pub fn snapshot(&mut self, base_ignores: Arc<GitIgnoreFile>) -> Result<(), SnapshotError> {
let sparse_matcher = self.sparse_matcher(); let sparse_matcher = self.sparse_matcher();
let mut work = vec![( let mut work = vec![(
RepoPath::root(), RepoPath::root(),
@ -517,7 +517,7 @@ impl TreeState {
tree_builder.remove(file.clone()); tree_builder.remove(file.clone());
} }
self.tree_id = tree_builder.write_tree(); self.tree_id = tree_builder.write_tree();
Ok(self.tree_id.clone()) Ok(())
} }
fn has_files_under(&self, dir: &RepoPath) -> bool { fn has_files_under(&self, dir: &RepoPath) -> bool {
@ -1162,7 +1162,9 @@ impl LockedWorkingCopy<'_> {
// because the TreeState may be long-lived if the library is used in a // because the TreeState may be long-lived if the library is used in a
// long-lived process. // long-lived process.
pub fn snapshot(&mut self, base_ignores: Arc<GitIgnoreFile>) -> Result<TreeId, SnapshotError> { pub fn snapshot(&mut self, base_ignores: Arc<GitIgnoreFile>) -> Result<TreeId, SnapshotError> {
self.wc.tree_state_mut().snapshot(base_ignores) let mut tree_state = self.wc.tree_state_mut();
tree_state.snapshot(base_ignores)?;
Ok(tree_state.current_tree_id().clone())
} }
pub fn check_out(&mut self, new_tree: &Tree) -> Result<CheckoutStats, CheckoutError> { pub fn check_out(&mut self, new_tree: &Tree) -> Result<CheckoutStats, CheckoutError> {

View file

@ -177,7 +177,8 @@ pub fn edit_diff(
std::fs::remove_file(instructions_path).ok(); std::fs::remove_file(instructions_path).ok();
} }
Ok(right_tree_state.snapshot(base_ignores)?) right_tree_state.snapshot(base_ignores)?;
Ok(right_tree_state.current_tree_id().clone())
} }
/// Merge/diff tool loaded from the settings. /// Merge/diff tool loaded from the settings.