mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-06 03:22:59 +00:00
working_copy: add a helper for getting the current tree
The code for getting the current tree object was repeated a few times over. I'm going to soon make it return a `MergedTree` and I don't want to repeat that code (it's more complicated than the current code).
This commit is contained in:
parent
863f1760f9
commit
5b8c1e013f
1 changed files with 24 additions and 32 deletions
|
@ -564,6 +564,10 @@ impl TreeState {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn current_tree(&self) -> Result<Tree, BackendError> {
|
||||||
|
self.store.get_tree(&RepoPath::root(), &self.tree_id)
|
||||||
|
}
|
||||||
|
|
||||||
fn write_file_to_store(
|
fn write_file_to_store(
|
||||||
&self,
|
&self,
|
||||||
path: &RepoPath,
|
path: &RepoPath,
|
||||||
|
@ -646,7 +650,7 @@ impl TreeState {
|
||||||
|
|
||||||
trace_span!("traverse filesystem").in_scope(|| -> Result<(), SnapshotError> {
|
trace_span!("traverse filesystem").in_scope(|| -> Result<(), SnapshotError> {
|
||||||
let matcher = IntersectionMatcher::new(sparse_matcher.as_ref(), fsmonitor_matcher);
|
let matcher = IntersectionMatcher::new(sparse_matcher.as_ref(), fsmonitor_matcher);
|
||||||
let current_tree = self.store.get_tree(&RepoPath::root(), &self.tree_id)?;
|
let current_tree = self.current_tree()?;
|
||||||
let current_tree = MergedTree::legacy(current_tree);
|
let current_tree = MergedTree::legacy(current_tree);
|
||||||
let directory_to_visit = DirectoryToVisit {
|
let directory_to_visit = DirectoryToVisit {
|
||||||
dir: RepoPath::root(),
|
dir: RepoPath::root(),
|
||||||
|
@ -710,10 +714,7 @@ impl TreeState {
|
||||||
self.tree_id = tree_builder.write_tree();
|
self.tree_id = tree_builder.write_tree();
|
||||||
});
|
});
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) {
|
||||||
let tree = self
|
let tree = self.current_tree().unwrap();
|
||||||
.store
|
|
||||||
.get_tree(&RepoPath::root(), &self.tree_id)
|
|
||||||
.unwrap();
|
|
||||||
let tree_paths: HashSet<_> = tree
|
let tree_paths: HashSet<_> = tree
|
||||||
.entries_matching(sparse_matcher.as_ref())
|
.entries_matching(sparse_matcher.as_ref())
|
||||||
.map(|(path, _)| path)
|
.map(|(path, _)| path)
|
||||||
|
@ -1149,10 +1150,7 @@ impl TreeState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_out(&mut self, new_tree: &Tree) -> Result<CheckoutStats, CheckoutError> {
|
pub fn check_out(&mut self, new_tree: &Tree) -> Result<CheckoutStats, CheckoutError> {
|
||||||
let old_tree = self
|
let old_tree = self.current_tree().map_err(|err| match err {
|
||||||
.store
|
|
||||||
.get_tree(&RepoPath::root(), &self.tree_id)
|
|
||||||
.map_err(|err| match err {
|
|
||||||
err @ BackendError::ObjectNotFound { .. } => CheckoutError::SourceNotFound {
|
err @ BackendError::ObjectNotFound { .. } => CheckoutError::SourceNotFound {
|
||||||
source: Box::new(err),
|
source: Box::new(err),
|
||||||
},
|
},
|
||||||
|
@ -1167,10 +1165,7 @@ impl TreeState {
|
||||||
&mut self,
|
&mut self,
|
||||||
sparse_patterns: Vec<RepoPath>,
|
sparse_patterns: Vec<RepoPath>,
|
||||||
) -> Result<CheckoutStats, CheckoutError> {
|
) -> Result<CheckoutStats, CheckoutError> {
|
||||||
let tree = self
|
let tree = self.current_tree().map_err(|err| match err {
|
||||||
.store
|
|
||||||
.get_tree(&RepoPath::root(), &self.tree_id)
|
|
||||||
.map_err(|err| match err {
|
|
||||||
err @ BackendError::ObjectNotFound { .. } => CheckoutError::SourceNotFound {
|
err @ BackendError::ObjectNotFound { .. } => CheckoutError::SourceNotFound {
|
||||||
source: Box::new(err),
|
source: Box::new(err),
|
||||||
},
|
},
|
||||||
|
@ -1295,10 +1290,7 @@ impl TreeState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reset(&mut self, new_tree: &Tree) -> Result<(), ResetError> {
|
pub fn reset(&mut self, new_tree: &Tree) -> Result<(), ResetError> {
|
||||||
let old_tree = self
|
let old_tree = self.current_tree().map_err(|err| match err {
|
||||||
.store
|
|
||||||
.get_tree(&RepoPath::root(), &self.tree_id)
|
|
||||||
.map_err(|err| match err {
|
|
||||||
err @ BackendError::ObjectNotFound { .. } => ResetError::SourceNotFound {
|
err @ BackendError::ObjectNotFound { .. } => ResetError::SourceNotFound {
|
||||||
source: Box::new(err),
|
source: Box::new(err),
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue