diff --git a/lib/src/merged_tree.rs b/lib/src/merged_tree.rs index 98c42be4a0..c39f4bf276 100644 --- a/lib/src/merged_tree.rs +++ b/lib/src/merged_tree.rs @@ -45,7 +45,7 @@ pub enum MergedTree { /// The value at a given path in a `MergedTree`. #[derive(PartialEq, Eq, Hash, Clone, Debug)] -pub enum MergedTreeValue<'a> { +pub enum MergedTreeVal<'a> { /// A single non-conflicted value. Resolved(Option<&'a TreeValue>), /// TODO: Make this a `Merge>` (reference to the @@ -53,11 +53,11 @@ pub enum MergedTreeValue<'a> { Conflict(Merge>), } -impl MergedTreeValue<'_> { +impl MergedTreeVal<'_> { fn to_merge(&self) -> Merge> { match self { - MergedTreeValue::Resolved(value) => Merge::resolved(value.cloned()), - MergedTreeValue::Conflict(merge) => merge.clone(), + MergedTreeVal::Resolved(value) => Merge::resolved(value.cloned()), + MergedTreeVal::Conflict(merge) => merge.clone(), } } } @@ -178,26 +178,26 @@ impl MergedTree { /// `self` is a `Merge`, which happens if the value at the path can be /// trivially merged. Does not recurse, so if `basename` refers to a Tree, /// then a `TreeValue::Tree` will be returned. - pub fn value(&self, basename: &RepoPathComponent) -> MergedTreeValue { + pub fn value(&self, basename: &RepoPathComponent) -> MergedTreeVal { match self { MergedTree::Legacy(tree) => match tree.value(basename) { Some(TreeValue::Conflict(conflict_id)) => { let path = tree.dir().join(basename); let conflict = tree.store().read_conflict(&path, conflict_id).unwrap(); - MergedTreeValue::Conflict(conflict) + MergedTreeVal::Conflict(conflict) } - other => MergedTreeValue::Resolved(other), + other => MergedTreeVal::Resolved(other), }, MergedTree::Merge(trees) => { if let Some(tree) = trees.as_resolved() { - return MergedTreeValue::Resolved(tree.value(basename)); + return MergedTreeVal::Resolved(tree.value(basename)); } let value = trees.map(|tree| tree.value(basename)); if let Some(resolved) = value.resolve_trivial() { - return MergedTreeValue::Resolved(*resolved); + return MergedTreeVal::Resolved(*resolved); } - MergedTreeValue::Conflict(value.map(|x| x.cloned())) + MergedTreeVal::Conflict(value.map(|x| x.cloned())) } } } @@ -238,14 +238,14 @@ impl MergedTree { tree.sub_tree(name).map(MergedTree::Legacy) } else { match self.value(name) { - MergedTreeValue::Resolved(Some(TreeValue::Tree(sub_tree_id))) => { + MergedTreeVal::Resolved(Some(TreeValue::Tree(sub_tree_id))) => { let subdir = self.dir().join(name); Some(MergedTree::resolved( self.store().get_tree(&subdir, sub_tree_id).unwrap(), )) } - MergedTreeValue::Resolved(_) => None, - MergedTreeValue::Conflict(merge) => { + MergedTreeVal::Resolved(_) => None, + MergedTreeVal::Conflict(merge) => { let merged_trees = merge.map(|value| match value { Some(TreeValue::Tree(sub_tree_id)) => { let subdir = self.dir().join(name); @@ -517,7 +517,7 @@ impl<'a> TreeEntriesNonRecursiveIterator<'a> { } impl<'a> Iterator for TreeEntriesNonRecursiveIterator<'a> { - type Item = (&'a RepoPathComponent, MergedTreeValue<'a>); + type Item = (&'a RepoPathComponent, MergedTreeVal<'a>); fn next(&mut self) -> Option { self.basename_iter.next().map(|basename| { @@ -627,8 +627,8 @@ impl<'a> Iterator for ConflictEntriesNonRecursiveIterator<'a> { fn next(&mut self) -> Option { for basename in self.basename_iter.by_ref() { match self.merged_tree.value(basename) { - MergedTreeValue::Resolved(_) => {} - MergedTreeValue::Conflict(tree_values) => { + MergedTreeVal::Resolved(_) => {} + MergedTreeVal::Conflict(tree_values) => { return Some((basename, tree_values)); } } @@ -765,11 +765,7 @@ impl<'a> TreeEntryDiffIterator<'a> { } impl<'a> Iterator for TreeEntryDiffIterator<'a> { - type Item = ( - &'a RepoPathComponent, - MergedTreeValue<'a>, - MergedTreeValue<'a>, - ); + type Item = (&'a RepoPathComponent, MergedTreeVal<'a>, MergedTreeVal<'a>); fn next(&mut self) -> Option { for basename in self.basename_iter.by_ref() { diff --git a/lib/tests/test_merged_tree.rs b/lib/tests/test_merged_tree.rs index 24cc878326..0390e5666b 100644 --- a/lib/tests/test_merged_tree.rs +++ b/lib/tests/test_merged_tree.rs @@ -17,7 +17,7 @@ use jj_lib::backend::{FileId, MergedTreeId, TreeValue}; use jj_lib::files::MergeResult; use jj_lib::matchers::{EverythingMatcher, FilesMatcher}; use jj_lib::merge::{Merge, MergeBuilder}; -use jj_lib::merged_tree::{MergedTree, MergedTreeBuilder, MergedTreeValue}; +use jj_lib::merged_tree::{MergedTree, MergedTreeBuilder, MergedTreeVal}; use jj_lib::repo::Repo; use jj_lib::repo_path::{RepoPath, RepoPathComponent, RepoPathJoin}; use jj_lib::tree::merge_trees; @@ -119,12 +119,12 @@ fn test_from_legacy_tree() { let merged_tree = MergedTree::from_legacy_tree(tree.clone()).unwrap(); assert_eq!( merged_tree.value(&RepoPathComponent::from("missing")), - MergedTreeValue::Resolved(None) + MergedTreeVal::Resolved(None) ); // file1: regular file without conflicts assert_eq!( merged_tree.value(&file1_path.components()[0]), - MergedTreeValue::Resolved(Some(&TreeValue::File { + MergedTreeVal::Resolved(Some(&TreeValue::File { id: file1_id.clone(), executable: false, })) @@ -132,7 +132,7 @@ fn test_from_legacy_tree() { // file2: 3-way conflict assert_eq!( merged_tree.value(&file2_path.components()[0]), - MergedTreeValue::Conflict(Merge::new( + MergedTreeVal::Conflict(Merge::new( vec![Some(file_value(&file2_v1_id)), None], vec![ Some(file_value(&file2_v2_id)), @@ -144,7 +144,7 @@ fn test_from_legacy_tree() { // file3: modify/delete conflict assert_eq!( merged_tree.value(&file3_path.components()[0]), - MergedTreeValue::Conflict(Merge::new( + MergedTreeVal::Conflict(Merge::new( vec![Some(file_value(&file3_v1_id)), None], vec![Some(file_value(&file3_v2_id)), None, None], )) @@ -152,7 +152,7 @@ fn test_from_legacy_tree() { // file4: add/add conflict assert_eq!( merged_tree.value(&file4_path.components()[0]), - MergedTreeValue::Conflict(Merge::new( + MergedTreeVal::Conflict(Merge::new( vec![None, None], vec![ Some(file_value(&file4_v1_id)), @@ -164,7 +164,7 @@ fn test_from_legacy_tree() { // file5: 5-way conflict assert_eq!( merged_tree.value(&file5_path.components()[0]), - MergedTreeValue::Conflict(Merge::new( + MergedTreeVal::Conflict(Merge::new( vec![ Some(file_value(&file5_v1_id)), Some(file_value(&file5_v2_id)), @@ -179,7 +179,7 @@ fn test_from_legacy_tree() { // file6: directory without conflicts assert_eq!( merged_tree.value(&dir1_basename), - MergedTreeValue::Resolved(tree.value(&dir1_basename)) + MergedTreeVal::Resolved(tree.value(&dir1_basename)) ); // Also test that MergedTreeBuilder can create the same tree by starting from an