repo_path: add stub type to introduce borrowed RepoPathComponent type

The current RepoPathComponent will be renamed to RepoPathComponentBuf, and
new str wrapper will be added as RepoPathComponent.
This commit is contained in:
Yuya Nishihara 2023-11-25 17:46:17 +09:00
parent e14b31a033
commit f2096da2d6
9 changed files with 169 additions and 147 deletions

View file

@ -26,7 +26,7 @@ use thiserror::Error;
use crate::content_hash::ContentHash;
use crate::merge::Merge;
use crate::repo_path::{RepoPath, RepoPathComponent};
use crate::repo_path::{RepoPath, RepoPathComponent, RepoPathComponentBuf};
pub trait ObjectId {
fn new(value: Vec<u8>) -> Self;
@ -358,7 +358,7 @@ impl<'a> TreeEntry<'a> {
}
pub struct TreeEntriesNonRecursiveIterator<'a> {
iter: std::collections::btree_map::Iter<'a, RepoPathComponent, TreeValue>,
iter: std::collections::btree_map::Iter<'a, RepoPathComponentBuf, TreeValue>,
}
impl<'a> Iterator for TreeEntriesNonRecursiveIterator<'a> {
@ -374,7 +374,7 @@ impl<'a> Iterator for TreeEntriesNonRecursiveIterator<'a> {
content_hash! {
#[derive(Default, PartialEq, Eq, Debug, Clone)]
pub struct Tree {
entries: BTreeMap<RepoPathComponent, TreeValue>,
entries: BTreeMap<RepoPathComponentBuf, TreeValue>,
}
}
@ -393,7 +393,7 @@ impl Tree {
}
}
pub fn set(&mut self, name: RepoPathComponent, value: TreeValue) {
pub fn set(&mut self, name: RepoPathComponentBuf, value: TreeValue) {
self.entries.insert(name, value);
}

View file

@ -37,7 +37,7 @@ use crate::backend::{
use crate::file_util::{IoResultExt as _, PathError};
use crate::lock::FileLock;
use crate::merge::{Merge, MergeBuilder};
use crate::repo_path::{RepoPath, RepoPathComponent};
use crate::repo_path::{RepoPath, RepoPathComponentBuf};
use crate::settings::UserSettings;
use crate::stacked_table::{
MutableTable, ReadonlyTable, TableSegment, TableStore, TableStoreError,
@ -766,7 +766,7 @@ impl Backend for GitBackend {
(name, TreeValue::GitSubmodule(id))
}
};
tree.set(RepoPathComponent::from(name), value);
tree.set(RepoPathComponentBuf::from(name), value);
}
Ok(tree)
}

View file

@ -34,7 +34,7 @@ use crate::backend::{
use crate::content_hash::blake2b_hash;
use crate::file_util::persist_content_addressed_temp_file;
use crate::merge::MergeBuilder;
use crate::repo_path::{RepoPath, RepoPathComponent};
use crate::repo_path::{RepoPath, RepoPathComponentBuf};
const COMMIT_ID_LENGTH: usize = 64;
const CHANGE_ID_LENGTH: usize = 16;
@ -368,7 +368,7 @@ fn tree_from_proto(proto: crate::protos::local_store::Tree) -> Tree {
let mut tree = Tree::default();
for proto_entry in proto.entries {
let value = tree_value_from_proto(proto_entry.value.unwrap());
tree.set(RepoPathComponent::from(proto_entry.name), value);
tree.set(RepoPathComponentBuf::from(proto_entry.name), value);
}
tree
}

View file

@ -19,7 +19,7 @@ use std::iter;
use tracing::instrument;
use crate::repo_path::{RepoPath, RepoPathComponent};
use crate::repo_path::{RepoPath, RepoPathComponentBuf};
#[derive(PartialEq, Eq, Debug)]
pub enum Visit {
@ -39,7 +39,7 @@ pub enum Visit {
}
impl Visit {
fn sets(dirs: HashSet<RepoPathComponent>, files: HashSet<RepoPathComponent>) -> Self {
fn sets(dirs: HashSet<RepoPathComponentBuf>, files: HashSet<RepoPathComponentBuf>) -> Self {
if dirs.is_empty() && files.is_empty() {
Self::Nothing
} else {
@ -58,13 +58,13 @@ impl Visit {
#[derive(PartialEq, Eq, Debug)]
pub enum VisitDirs {
All,
Set(HashSet<RepoPathComponent>),
Set(HashSet<RepoPathComponentBuf>),
}
#[derive(PartialEq, Eq, Debug)]
pub enum VisitFiles {
All,
Set(HashSet<RepoPathComponent>),
Set(HashSet<RepoPathComponentBuf>),
}
pub trait Matcher: Sync {
@ -263,7 +263,7 @@ impl Matcher for IntersectionMatcher<'_> {
/// visited.
#[derive(PartialEq, Eq, Debug)]
struct RepoPathTree {
entries: HashMap<RepoPathComponent, RepoPathTree>,
entries: HashMap<RepoPathComponentBuf, RepoPathTree>,
// is_dir/is_file aren't exclusive, both can be set to true. If entries is not empty,
// is_dir should be set.
is_dir: bool,
@ -313,7 +313,7 @@ impl RepoPathTree {
fn walk_to<'a>(
&'a self,
dir: &'a RepoPath,
) -> impl Iterator<Item = (&RepoPathTree, &[RepoPathComponent])> + 'a {
) -> impl Iterator<Item = (&RepoPathTree, &[RepoPathComponentBuf])> + 'a {
iter::successors(
Some((self, dir.components().as_slice())),
|(sub, components)| {
@ -343,7 +343,6 @@ mod tests {
use maplit::hashset;
use super::*;
use crate::repo_path::{RepoPath, RepoPathComponent};
#[test]
fn test_repo_path_tree_empty() {
@ -364,12 +363,12 @@ mod tests {
tree.add_dir(&RepoPath::from_internal_string("dir"));
assert_eq!(
tree.get_visit_sets(&RepoPath::root()),
Visit::sets(hashset! {RepoPathComponent::from("dir")}, hashset! {}),
Visit::sets(hashset! {RepoPathComponentBuf::from("dir")}, hashset! {}),
);
tree.add_dir(&RepoPath::from_internal_string("dir/sub"));
assert_eq!(
tree.get_visit_sets(&RepoPath::from_internal_string("dir")),
Visit::sets(hashset! {RepoPathComponent::from("sub")}, hashset! {}),
Visit::sets(hashset! {RepoPathComponentBuf::from("sub")}, hashset! {}),
);
}
@ -379,11 +378,11 @@ mod tests {
tree.add_file(&RepoPath::from_internal_string("dir/file"));
assert_eq!(
tree.get_visit_sets(&RepoPath::root()),
Visit::sets(hashset! {RepoPathComponent::from("dir")}, hashset! {}),
Visit::sets(hashset! {RepoPathComponentBuf::from("dir")}, hashset! {}),
);
assert_eq!(
tree.get_visit_sets(&RepoPath::from_internal_string("dir")),
Visit::sets(hashset! {}, hashset! {RepoPathComponent::from("file")}),
Visit::sets(hashset! {}, hashset! {RepoPathComponentBuf::from("file")}),
);
}
@ -421,14 +420,17 @@ mod tests {
assert_eq!(
m.visit(&RepoPath::root()),
Visit::sets(
hashset! {RepoPathComponent::from("dir1")},
hashset! {RepoPathComponent::from("file4")}
hashset! {RepoPathComponentBuf::from("dir1")},
hashset! {RepoPathComponentBuf::from("file4")}
)
);
assert_eq!(
m.visit(&RepoPath::from_internal_string("dir1")),
Visit::sets(
hashset! {RepoPathComponent::from("subdir1"), RepoPathComponent::from("subdir2")},
hashset! {
RepoPathComponentBuf::from("subdir1"),
RepoPathComponentBuf::from("subdir2"),
},
hashset! {}
)
);
@ -436,12 +438,15 @@ mod tests {
m.visit(&RepoPath::from_internal_string("dir1/subdir1")),
Visit::sets(
hashset! {},
hashset! {RepoPathComponent::from("file1"), RepoPathComponent::from("file2")}
hashset! {
RepoPathComponentBuf::from("file1"),
RepoPathComponentBuf::from("file2"),
},
)
);
assert_eq!(
m.visit(&RepoPath::from_internal_string("dir1/subdir2")),
Visit::sets(hashset! {}, hashset! {RepoPathComponent::from("file3")})
Visit::sets(hashset! {}, hashset! {RepoPathComponentBuf::from("file3")})
);
}
@ -488,15 +493,15 @@ mod tests {
// shouldn't be visited)
assert_eq!(
m.visit(&RepoPath::root()),
Visit::sets(hashset! {RepoPathComponent::from("foo")}, hashset! {})
Visit::sets(hashset! {RepoPathComponentBuf::from("foo")}, hashset! {})
);
// Inside parent directory "foo/", both subdirectory "bar" and file "bar" may
// match
assert_eq!(
m.visit(&RepoPath::from_internal_string("foo")),
Visit::sets(
hashset! {RepoPathComponent::from("bar")},
hashset! {RepoPathComponent::from("bar")}
hashset! {RepoPathComponentBuf::from("bar")},
hashset! {RepoPathComponentBuf::from("bar")}
)
);
// Inside a directory that matches the prefix, everything matches recursively
@ -533,8 +538,8 @@ mod tests {
assert_eq!(
m.visit(&RepoPath::root()),
Visit::sets(
hashset! {RepoPathComponent::from("foo")},
hashset! {RepoPathComponent::from("foo")}
hashset! {RepoPathComponentBuf::from("foo")},
hashset! {RepoPathComponentBuf::from("foo")}
)
);
// Inside a directory that matches the prefix, everything matches recursively
@ -567,8 +572,14 @@ mod tests {
assert_eq!(
m.visit(&RepoPath::root()),
Visit::sets(
hashset! {RepoPathComponent::from("foo"), RepoPathComponent::from("bar")},
hashset! {RepoPathComponent::from("foo"), RepoPathComponent::from("bar")}
hashset! {
RepoPathComponentBuf::from("foo"),
RepoPathComponentBuf::from("bar"),
},
hashset! {
RepoPathComponentBuf::from("foo"),
RepoPathComponentBuf::from("bar"),
},
)
);
assert_eq!(
@ -609,8 +620,14 @@ mod tests {
assert_eq!(
m.visit(&RepoPath::root()),
Visit::sets(
hashset! {RepoPathComponent::from("foo"), RepoPathComponent::from("bar")},
hashset! {RepoPathComponent::from("foo"), RepoPathComponent::from("bar")}
hashset! {
RepoPathComponentBuf::from("foo"),
RepoPathComponentBuf::from("bar"),
},
hashset! {
RepoPathComponentBuf::from("foo"),
RepoPathComponentBuf::from("bar"),
},
)
);
assert_eq!(
@ -653,8 +670,8 @@ mod tests {
assert_eq!(
m.visit(&RepoPath::root()),
Visit::sets(
hashset! {RepoPathComponent::from("bar")},
hashset! {RepoPathComponent::from("bar")}
hashset! {RepoPathComponentBuf::from("bar")},
hashset! {RepoPathComponentBuf::from("bar")}
)
);
assert_eq!(
@ -697,7 +714,7 @@ mod tests {
assert_eq!(
m.visit(&RepoPath::root()),
Visit::sets(hashset! {RepoPathComponent::from("foo")}, hashset! {})
Visit::sets(hashset! {RepoPathComponentBuf::from("foo")}, hashset! {})
);
assert_eq!(
m.visit(&RepoPath::from_internal_string("bar")),
@ -706,8 +723,8 @@ mod tests {
assert_eq!(
m.visit(&RepoPath::from_internal_string("foo")),
Visit::sets(
hashset! {RepoPathComponent::from("bar")},
hashset! {RepoPathComponent::from("bar")}
hashset! {RepoPathComponentBuf::from("bar")},
hashset! {RepoPathComponentBuf::from("bar")}
)
);
assert_eq!(

View file

@ -30,7 +30,7 @@ use pollster::FutureExt;
use crate::backend::{BackendError, BackendResult, ConflictId, MergedTreeId, TreeId, TreeValue};
use crate::matchers::{EverythingMatcher, Matcher};
use crate::merge::{Merge, MergeBuilder, MergedTreeValue};
use crate::repo_path::{RepoPath, RepoPathComponent};
use crate::repo_path::{RepoPath, RepoPathComponent, RepoPathComponentBuf};
use crate::store::Store;
use crate::tree::{try_resolve_file_conflict, Tree, TreeMergeError};
use crate::tree_builder::TreeBuilder;
@ -268,7 +268,8 @@ impl MergedTree {
}
}
fn sub_tree_recursive(&self, components: &[RepoPathComponent]) -> Option<MergedTree> {
// TODO: switch to borrowed &RepoPath type or RepoPathComponents iterator
fn sub_tree_recursive(&self, components: &[RepoPathComponentBuf]) -> Option<MergedTree> {
if let Some((first, tail)) = components.split_first() {
tail.iter()
.try_fold(self.sub_tree(first)?, |tree, name| tree.sub_tree(name))

View file

@ -22,6 +22,9 @@ use thiserror::Error;
use crate::file_util;
// TODO: make RepoPathComponent a borrowed type
pub type RepoPathComponentBuf = RepoPathComponent;
content_hash! {
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
pub struct RepoPathComponent {
@ -35,22 +38,22 @@ impl RepoPathComponent {
}
}
impl From<&str> for RepoPathComponent {
impl From<&str> for RepoPathComponentBuf {
fn from(value: &str) -> Self {
RepoPathComponent::from(value.to_owned())
RepoPathComponentBuf::from(value.to_owned())
}
}
impl From<String> for RepoPathComponent {
impl From<String> for RepoPathComponentBuf {
fn from(value: String) -> Self {
assert!(is_valid_repo_path_component_str(&value));
RepoPathComponent { value }
RepoPathComponentBuf { value }
}
}
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct RepoPath {
components: Vec<RepoPathComponent>,
components: Vec<RepoPathComponentBuf>,
}
impl Debug for RepoPath {
@ -75,7 +78,7 @@ impl RepoPath {
} else {
let components = value
.split('/')
.map(|value| RepoPathComponent {
.map(|value| RepoPathComponentBuf {
value: value.to_string(),
})
.collect();
@ -91,7 +94,7 @@ impl RepoPath {
let components = relative_path
.components()
.map(|c| match c {
Component::Normal(a) => Some(RepoPathComponent::from(a.to_str().unwrap())),
Component::Normal(a) => Some(RepoPathComponentBuf::from(a.to_str().unwrap())),
// TODO: better to return Err instead of None?
_ => None,
})
@ -99,7 +102,7 @@ impl RepoPath {
Some(RepoPath::from_components(components))
}
pub fn from_components(components: Vec<RepoPathComponent>) -> Self {
pub fn from_components(components: Vec<RepoPathComponentBuf>) -> Self {
RepoPath { components }
}
@ -181,7 +184,7 @@ impl RepoPath {
}
}
pub fn components(&self) -> &Vec<RepoPathComponent> {
pub fn components(&self) -> &Vec<RepoPathComponentBuf> {
&self.components
}
@ -269,11 +272,11 @@ mod tests {
#[test]
fn test_parent() {
let root = RepoPath::root();
let dir_component = RepoPathComponent::from("dir");
let subdir_component = RepoPathComponent::from("subdir");
let dir_component = &RepoPathComponent::from("dir");
let subdir_component = &RepoPathComponent::from("subdir");
let dir = root.join(&dir_component);
let subdir = dir.join(&subdir_component);
let dir = root.join(dir_component);
let subdir = dir.join(subdir_component);
assert_eq!(root.parent(), None);
assert_eq!(dir.parent(), Some(root));
@ -283,15 +286,15 @@ mod tests {
#[test]
fn test_split() {
let root = RepoPath::root();
let dir_component = RepoPathComponent::from("dir");
let file_component = RepoPathComponent::from("file");
let dir_component = &RepoPathComponent::from("dir");
let file_component = &RepoPathComponent::from("file");
let dir = root.join(&dir_component);
let file = dir.join(&file_component);
let dir = root.join(dir_component);
let file = dir.join(file_component);
assert_eq!(root.split(), None);
assert_eq!(dir.split(), Some((root, &dir_component)));
assert_eq!(file.split(), Some((dir, &file_component)));
assert_eq!(dir.split(), Some((root, dir_component)));
assert_eq!(file.split(), Some((dir, file_component)));
}
#[test]
@ -299,13 +302,13 @@ mod tests {
assert_eq!(RepoPath::root().components(), &vec![]);
assert_eq!(
repo_path("dir").components(),
&vec![RepoPathComponent::from("dir")]
&vec![RepoPathComponentBuf::from("dir")]
);
assert_eq!(
repo_path("dir/subdir").components(),
&vec![
RepoPathComponent::from("dir"),
RepoPathComponent::from("subdir")
RepoPathComponentBuf::from("dir"),
RepoPathComponentBuf::from("subdir")
]
);
}

View file

@ -30,7 +30,7 @@ use crate::backend::{
use crate::files::MergeResult;
use crate::matchers::{EverythingMatcher, Matcher};
use crate::merge::{trivial_merge, Merge, MergedTreeValue};
use crate::repo_path::{RepoPath, RepoPathComponent};
use crate::repo_path::{RepoPath, RepoPathComponent, RepoPathComponentBuf};
use crate::store::Store;
use crate::{backend, files};
@ -159,7 +159,8 @@ impl Tree {
self.store.get_tree(subdir, id).unwrap()
}
fn sub_tree_recursive(&self, components: &[RepoPathComponent]) -> Option<Tree> {
// TODO: switch to borrowed &RepoPath type or RepoPathComponents iterator
fn sub_tree_recursive(&self, components: &[RepoPathComponentBuf]) -> Option<Tree> {
if let Some((first, tail)) = components.split_first() {
tail.iter()
.try_fold(self.sub_tree(first)?, |tree, name| tree.sub_tree(name))

View file

@ -112,15 +112,15 @@ fn test_same_type() {
);
// Check the conflicting cases
let component = RepoPathComponent::from("_ab");
match merged_tree.value(&component).unwrap() {
let component = &RepoPathComponent::from("_ab");
match merged_tree.value(component).unwrap() {
TreeValue::Conflict(id) => {
let conflict = store
.read_conflict(&RepoPath::from_internal_string("_ab"), id)
.unwrap();
assert_eq!(
conflict.adds().map(|v| v.as_ref()).collect_vec(),
vec![side1_tree.value(&component), side2_tree.value(&component)]
vec![side1_tree.value(component), side2_tree.value(component)]
);
assert_eq!(
conflict.removes().map(|v| v.as_ref()).collect_vec(),
@ -129,53 +129,53 @@ fn test_same_type() {
}
_ => panic!("unexpected value"),
};
let component = RepoPathComponent::from("a_b");
match merged_tree.value(&component).unwrap() {
let component = &RepoPathComponent::from("a_b");
match merged_tree.value(component).unwrap() {
TreeValue::Conflict(id) => {
let conflict = store
.read_conflict(&RepoPath::from_internal_string("a_b"), id)
.unwrap();
assert_eq!(
conflict.removes().map(|v| v.as_ref()).collect_vec(),
vec![base_tree.value(&component)]
vec![base_tree.value(component)]
);
assert_eq!(
conflict.adds().map(|v| v.as_ref()).collect_vec(),
vec![side2_tree.value(&component), None]
vec![side2_tree.value(component), None]
);
}
_ => panic!("unexpected value"),
};
let component = RepoPathComponent::from("ab_");
match merged_tree.value(&component).unwrap() {
let component = &RepoPathComponent::from("ab_");
match merged_tree.value(component).unwrap() {
TreeValue::Conflict(id) => {
let conflict = store
.read_conflict(&RepoPath::from_internal_string("ab_"), id)
.unwrap();
assert_eq!(
conflict.removes().map(|v| v.as_ref()).collect_vec(),
vec![base_tree.value(&component)]
vec![base_tree.value(component)]
);
assert_eq!(
conflict.adds().map(|v| v.as_ref()).collect_vec(),
vec![side1_tree.value(&component), None]
vec![side1_tree.value(component), None]
);
}
_ => panic!("unexpected value"),
};
let component = RepoPathComponent::from("abc");
match merged_tree.value(&component).unwrap() {
let component = &RepoPathComponent::from("abc");
match merged_tree.value(component).unwrap() {
TreeValue::Conflict(id) => {
let conflict = store
.read_conflict(&RepoPath::from_internal_string("abc"), id)
.unwrap();
assert_eq!(
conflict.removes().map(|v| v.as_ref()).collect_vec(),
vec![base_tree.value(&component)]
vec![base_tree.value(component)]
);
assert_eq!(
conflict.adds().map(|v| v.as_ref()).collect_vec(),
vec![side1_tree.value(&component), side2_tree.value(&component)]
vec![side1_tree.value(component), side2_tree.value(component)]
);
}
_ => panic!("unexpected value"),
@ -411,8 +411,8 @@ fn test_types() {
let merged_tree = merge_trees(&side1_tree, &base_tree, &side2_tree).unwrap();
// Check the conflicting cases
let component = RepoPathComponent::from("normal_executable_symlink");
match merged_tree.value(&component).unwrap() {
let component = &RepoPathComponent::from("normal_executable_symlink");
match merged_tree.value(component).unwrap() {
TreeValue::Conflict(id) => {
let conflict = store
.read_conflict(
@ -422,28 +422,28 @@ fn test_types() {
.unwrap();
assert_eq!(
conflict.removes().map(|v| v.as_ref()).collect_vec(),
vec![base_tree.value(&component)]
vec![base_tree.value(component)]
);
assert_eq!(
conflict.adds().map(|v| v.as_ref()).collect_vec(),
vec![side1_tree.value(&component), side2_tree.value(&component)]
vec![side1_tree.value(component), side2_tree.value(component)]
);
}
_ => panic!("unexpected value"),
};
let component = RepoPathComponent::from("tree_normal_symlink");
match merged_tree.value(&component).unwrap() {
let component = &RepoPathComponent::from("tree_normal_symlink");
match merged_tree.value(component).unwrap() {
TreeValue::Conflict(id) => {
let conflict = store
.read_conflict(&RepoPath::from_internal_string("tree_normal_symlink"), id)
.unwrap();
assert_eq!(
conflict.removes().map(|v| v.as_ref()).collect_vec(),
vec![base_tree.value(&component)]
vec![base_tree.value(component)]
);
assert_eq!(
conflict.adds().map(|v| v.as_ref()).collect_vec(),
vec![side1_tree.value(&component), side2_tree.value(&component)]
vec![side1_tree.value(component), side2_tree.value(component)]
);
}
_ => panic!("unexpected value"),
@ -456,7 +456,7 @@ fn test_simplify_conflict() {
let repo = &test_repo.repo;
let store = repo.store();
let component = RepoPathComponent::from("file");
let component = &RepoPathComponent::from("file");
let path = RepoPath::from_internal_string("file");
let write_tree = |contents: &str| -> Tree { create_single_tree(repo, &[(&path, contents)]) };
@ -468,7 +468,7 @@ fn test_simplify_conflict() {
// Rebase the branch tree to the first upstream tree
let rebased1_tree = merge_trees(&branch_tree, &base_tree, &upstream1_tree).unwrap();
// Make sure we have a conflict (testing the test setup)
match rebased1_tree.value(&component).unwrap() {
match rebased1_tree.value(component).unwrap() {
TreeValue::Conflict(_) => {
// expected
}
@ -479,33 +479,33 @@ fn test_simplify_conflict() {
// both directions.
let rebased_back_tree = merge_trees(&rebased1_tree, &upstream1_tree, &base_tree).unwrap();
assert_eq!(
rebased_back_tree.value(&component),
branch_tree.value(&component)
rebased_back_tree.value(component),
branch_tree.value(component)
);
let rebased_back_tree = merge_trees(&base_tree, &upstream1_tree, &rebased1_tree).unwrap();
assert_eq!(
rebased_back_tree.value(&component),
branch_tree.value(&component)
rebased_back_tree.value(component),
branch_tree.value(component)
);
// Rebase the rebased tree further upstream. The conflict should be simplified
// to not mention the contents from the first rebase.
let further_rebased_tree =
merge_trees(&rebased1_tree, &upstream1_tree, &upstream2_tree).unwrap();
match further_rebased_tree.value(&component).unwrap() {
match further_rebased_tree.value(component).unwrap() {
TreeValue::Conflict(id) => {
let conflict = store
.read_conflict(&RepoPath::from_components(vec![component.clone()]), id)
.unwrap();
assert_eq!(
conflict.removes().map(|v| v.as_ref()).collect_vec(),
vec![base_tree.value(&component)]
vec![base_tree.value(component)]
);
assert_eq!(
conflict.adds().map(|v| v.as_ref()).collect_vec(),
vec![
branch_tree.value(&component),
upstream2_tree.value(&component),
branch_tree.value(component),
upstream2_tree.value(component),
]
);
}
@ -513,18 +513,18 @@ fn test_simplify_conflict() {
};
let further_rebased_tree =
merge_trees(&upstream2_tree, &upstream1_tree, &rebased1_tree).unwrap();
match further_rebased_tree.value(&component).unwrap() {
match further_rebased_tree.value(component).unwrap() {
TreeValue::Conflict(id) => {
let conflict = store.read_conflict(&path, id).unwrap();
assert_eq!(
conflict.removes().map(|v| v.as_ref()).collect_vec(),
vec![base_tree.value(&component)]
vec![base_tree.value(component)]
);
assert_eq!(
conflict.adds().map(|v| v.as_ref()).collect_vec(),
vec![
upstream2_tree.value(&component),
branch_tree.value(&component)
upstream2_tree.value(component),
branch_tree.value(component)
]
);
}

View file

@ -123,9 +123,9 @@ fn test_from_legacy_tree() {
tree_builder.set(file5_path.clone(), TreeValue::Conflict(file5_conflict_id));
// dir1: directory without conflicts
let dir1_basename = RepoPathComponent::from("dir1");
let dir1_basename = &RepoPathComponent::from("dir1");
let dir1_filename = RepoPath::root()
.join(&dir1_basename)
.join(dir1_basename)
.join(&RepoPathComponent::from("file"));
let dir1_filename_id = write_file(store.as_ref(), &dir1_filename, "file5_v2");
tree_builder.set(dir1_filename.clone(), file_value(&dir1_filename_id));
@ -195,8 +195,8 @@ fn test_from_legacy_tree() {
);
// file6: directory without conflicts
assert_eq!(
merged_tree.value(&dir1_basename),
MergedTreeVal::Resolved(tree.value(&dir1_basename))
merged_tree.value(dir1_basename),
MergedTreeVal::Resolved(tree.value(dir1_basename))
);
// Also test that MergedTreeBuilder can create the same tree by starting from an
@ -859,7 +859,7 @@ fn test_diff_dir_file() {
let path4 = RepoPath::from_internal_string("path4");
let path5 = RepoPath::from_internal_string("path5");
let path6 = RepoPath::from_internal_string("path6");
let file = RepoPathComponent::from("file");
let file = &RepoPathComponent::from("file");
let left_base = create_single_tree(
repo,
&[
@ -867,8 +867,8 @@ fn test_diff_dir_file() {
(&path2, "left"),
(&path3, "left"),
(&path4, "left-base"),
(&path5.join(&file), "left"),
(&path6.join(&file), "left"),
(&path5.join(file), "left"),
(&path6.join(file), "left"),
],
);
let left_side1 = create_single_tree(
@ -878,8 +878,8 @@ fn test_diff_dir_file() {
(&path2, "left"),
(&path3, "left"),
(&path4, "left-side1"),
(&path5.join(&file), "left"),
(&path6.join(&file), "left"),
(&path5.join(file), "left"),
(&path6.join(file), "left"),
],
);
let left_side2 = create_single_tree(
@ -889,17 +889,17 @@ fn test_diff_dir_file() {
(&path2, "left"),
(&path3, "left"),
(&path4, "left-side2"),
(&path5.join(&file), "left"),
(&path6.join(&file), "left"),
(&path5.join(file), "left"),
(&path6.join(file), "left"),
],
);
let right_base = create_single_tree(
repo,
&[
(&path1.join(&file), "right"),
(&path1.join(file), "right"),
// path2 absent
// path3 absent
(&path4.join(&file), "right-base"),
(&path4.join(file), "right-base"),
// path5 is absent
// path6 is absent
],
@ -907,10 +907,10 @@ fn test_diff_dir_file() {
let right_side1 = create_single_tree(
repo,
&[
(&path1.join(&file), "right"),
(&path2.join(&file), "right"),
(&path3.join(&file), "right-side1"),
(&path4.join(&file), "right-side1"),
(&path1.join(file), "right"),
(&path2.join(file), "right"),
(&path3.join(file), "right-side1"),
(&path4.join(file), "right-side1"),
(&path5, "right-side1"),
(&path6, "right"),
],
@ -918,12 +918,12 @@ fn test_diff_dir_file() {
let right_side2 = create_single_tree(
repo,
&[
(&path1.join(&file), "right"),
(&path2.join(&file), "right"),
(&path1.join(file), "right"),
(&path2.join(file), "right"),
(&path3, "right-side2"),
(&path4.join(&file), "right-side2"),
(&path4.join(file), "right-side2"),
(&path5, "right-side2"),
(&path6.join(&file), "right"),
(&path6.join(file), "right"),
],
);
let left_merged = MergedTree::new(Merge::from_removes_adds(
@ -948,8 +948,8 @@ fn test_diff_dir_file() {
(left_merged.path_value(&path1), Merge::absent()),
),
(
path1.join(&file),
(Merge::absent(), right_merged.path_value(&path1.join(&file))),
path1.join(file),
(Merge::absent(), right_merged.path_value(&path1.join(file))),
),
// path2: file1 -> directory1+(directory2-absent)
(
@ -957,8 +957,8 @@ fn test_diff_dir_file() {
(left_merged.path_value(&path2), Merge::absent()),
),
(
path2.join(&file),
(Merge::absent(), right_merged.path_value(&path2.join(&file))),
path2.join(file),
(Merge::absent(), right_merged.path_value(&path2.join(file))),
),
// path3: file1 -> directory1+(file1-absent)
(
@ -974,13 +974,13 @@ fn test_diff_dir_file() {
(left_merged.path_value(&path4), Merge::absent()),
),
(
path4.join(&file),
(Merge::absent(), right_merged.path_value(&path4.join(&file))),
path4.join(file),
(Merge::absent(), right_merged.path_value(&path4.join(file))),
),
// path5: directory1 -> file1+(file2-absent)
(
path5.join(&file),
(left_merged.path_value(&path5.join(&file)), Merge::absent()),
path5.join(file),
(left_merged.path_value(&path5.join(file)), Merge::absent()),
),
(
path5.clone(),
@ -988,8 +988,8 @@ fn test_diff_dir_file() {
),
// path6: directory1 -> file1+(directory1-absent)
(
path6.join(&file),
(left_merged.path_value(&path6.join(&file)), Merge::absent()),
path6.join(file),
(left_merged.path_value(&path6.join(file)), Merge::absent()),
),
(
path6.clone(),
@ -1009,8 +1009,8 @@ fn test_diff_dir_file() {
let expected_diff = vec![
// path1: file1 -> directory1
(
path1.join(&file),
(right_merged.path_value(&path1.join(&file)), Merge::absent()),
path1.join(file),
(right_merged.path_value(&path1.join(file)), Merge::absent()),
),
(
path1.clone(),
@ -1018,8 +1018,8 @@ fn test_diff_dir_file() {
),
// path2: file1 -> directory1+(directory2-absent)
(
path2.join(&file),
(right_merged.path_value(&path2.join(&file)), Merge::absent()),
path2.join(file),
(right_merged.path_value(&path2.join(file)), Merge::absent()),
),
(
path2.clone(),
@ -1035,8 +1035,8 @@ fn test_diff_dir_file() {
),
// path4: file1+(file2-file3) -> directory1+(directory2-directory3)
(
path4.join(&file),
(right_merged.path_value(&path4.join(&file)), Merge::absent()),
path4.join(file),
(right_merged.path_value(&path4.join(file)), Merge::absent()),
),
(
path4.clone(),
@ -1048,8 +1048,8 @@ fn test_diff_dir_file() {
(right_merged.path_value(&path5), Merge::absent()),
),
(
path5.join(&file),
(Merge::absent(), left_merged.path_value(&path5.join(&file))),
path5.join(file),
(Merge::absent(), left_merged.path_value(&path5.join(file))),
),
// path6: directory1 -> file1+(directory1-absent)
(
@ -1057,8 +1057,8 @@ fn test_diff_dir_file() {
(right_merged.path_value(&path6), Merge::absent()),
),
(
path6.join(&file),
(Merge::absent(), left_merged.path_value(&path6.join(&file))),
path6.join(file),
(Merge::absent(), left_merged.path_value(&path6.join(file))),
),
];
assert_eq!(actual_diff, expected_diff);
@ -1085,7 +1085,7 @@ fn test_diff_dir_file() {
// Diff while filtering by `path1/file` (file1 -> directory1) as a file
{
let matcher = FilesMatcher::new(&[path1.join(&file)]);
let matcher = FilesMatcher::new(&[path1.join(file)]);
let actual_diff = left_merged
.diff(&right_merged, &matcher)
.map(|(path, diff)| (path, diff.unwrap()))
@ -1093,8 +1093,8 @@ fn test_diff_dir_file() {
let expected_diff = vec![
// path1: file1 -> directory1
(
path1.join(&file),
(Merge::absent(), right_merged.path_value(&path1.join(&file))),
path1.join(file),
(Merge::absent(), right_merged.path_value(&path1.join(file))),
),
];
assert_eq!(actual_diff, expected_diff);
@ -1114,8 +1114,8 @@ fn test_diff_dir_file() {
(left_merged.path_value(&path1), Merge::absent()),
),
(
path1.join(&file),
(Merge::absent(), right_merged.path_value(&path1.join(&file))),
path1.join(file),
(Merge::absent(), right_merged.path_value(&path1.join(file))),
),
];
assert_eq!(actual_diff, expected_diff);