tree: take sub_tree_recursive() argument as &RepoPath

Since RepoPath is now a slice type, it can be constructed without cloning the
backing buffer. Let's simply use it instead of the iterator type.
This commit is contained in:
Yuya Nishihara 2024-05-23 08:13:30 +09:00
parent cd5e82d0d3
commit f65ba88109
2 changed files with 10 additions and 16 deletions

View file

@ -29,7 +29,7 @@ use itertools::Itertools;
use crate::backend::{BackendResult, ConflictId, MergedTreeId, TreeId, TreeValue};
use crate::matchers::{EverythingMatcher, Matcher};
use crate::merge::{Merge, MergeBuilder, MergedTreeValue};
use crate::repo_path::{RepoPath, RepoPathBuf, RepoPathComponent, RepoPathComponentsIter};
use crate::repo_path::{RepoPath, RepoPathBuf, RepoPathComponent};
use crate::store::Store;
use crate::tree::{try_resolve_file_conflict, Tree};
use crate::tree_builder::TreeBuilder;
@ -247,7 +247,7 @@ impl MergedTree {
pub fn path_value(&self, path: &RepoPath) -> BackendResult<MergedTreeValue> {
assert_eq!(self.dir(), RepoPath::root());
match path.split() {
Some((dir, basename)) => match self.sub_tree_recursive(dir.components())? {
Some((dir, basename)) => match self.sub_tree_recursive(dir)? {
None => Ok(Merge::absent()),
Some(tree) => Ok(tree.value(basename).to_merge()),
},
@ -268,13 +268,10 @@ impl MergedTree {
}
}
/// Look up the tree at the path indicated by `components`.
pub fn sub_tree_recursive(
&self,
components: RepoPathComponentsIter,
) -> BackendResult<Option<MergedTree>> {
/// Look up the tree at the given path.
pub fn sub_tree_recursive(&self, path: &RepoPath) -> BackendResult<Option<MergedTree>> {
let mut current_tree = self.clone();
for name in components {
for name in path.components() {
match current_tree.sub_tree(name)? {
None => {
return Ok(None);

View file

@ -30,7 +30,7 @@ use crate::files::MergeResult;
use crate::matchers::{EverythingMatcher, Matcher};
use crate::merge::{trivial_merge, Merge, MergedTreeValue};
use crate::object_id::ObjectId;
use crate::repo_path::{RepoPath, RepoPathBuf, RepoPathComponent, RepoPathComponentsIter};
use crate::repo_path::{RepoPath, RepoPathBuf, RepoPathComponent};
use crate::store::Store;
use crate::{backend, files};
@ -128,7 +128,7 @@ impl Tree {
assert_eq!(self.dir(), RepoPath::root());
match path.split() {
Some((dir, basename)) => {
let tree = self.sub_tree_recursive(dir.components())?;
let tree = self.sub_tree_recursive(dir)?;
Ok(tree.and_then(|tree| tree.data.value(basename).cloned()))
}
None => Ok(Some(TreeValue::Tree(self.id.clone()))),
@ -154,13 +154,10 @@ impl Tree {
self.store.get_tree(subdir, id).unwrap()
}
/// Look up the tree at the path indicated by `components`.
pub fn sub_tree_recursive(
&self,
components: RepoPathComponentsIter,
) -> BackendResult<Option<Tree>> {
/// Look up the tree at the given path.
pub fn sub_tree_recursive(&self, path: &RepoPath) -> BackendResult<Option<Tree>> {
let mut current_tree = self.clone();
for name in components {
for name in path.components() {
match current_tree.sub_tree(name)? {
None => {
return Ok(None);