forked from mirrors/jj
trees: make entries() function be the recursive one, since it's more common
This commit is contained in:
parent
8ec100713d
commit
9ad225b3b5
5 changed files with 22 additions and 22 deletions
|
@ -259,11 +259,11 @@ impl<'a> TreeEntry<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct TreeEntriesIter<'a> {
|
||||
pub struct TreeEntriesNonRecursiveIter<'a> {
|
||||
iter: std::collections::btree_map::Iter<'a, String, TreeValue>,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for TreeEntriesIter<'a> {
|
||||
impl<'a> Iterator for TreeEntriesNonRecursiveIter<'a> {
|
||||
type Item = TreeEntry<'a>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
|
@ -291,8 +291,8 @@ impl Tree {
|
|||
self.entries.is_empty()
|
||||
}
|
||||
|
||||
pub fn entries(&self) -> TreeEntriesIter {
|
||||
TreeEntriesIter {
|
||||
pub fn entries(&self) -> TreeEntriesNonRecursiveIter {
|
||||
TreeEntriesNonRecursiveIter {
|
||||
iter: self.entries.iter(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ use crate::repo_path::{
|
|||
DirRepoPath, DirRepoPathComponent, FileRepoPath, RepoPath, RepoPathComponent, RepoPathJoin,
|
||||
};
|
||||
use crate::store;
|
||||
use crate::store::{ConflictId, TreeEntriesIter, TreeEntry, TreeId, TreeValue};
|
||||
use crate::store::{ConflictId, TreeEntriesNonRecursiveIter, TreeEntry, TreeId, TreeValue};
|
||||
use crate::store_wrapper::StoreWrapper;
|
||||
use crate::trees::{recursive_tree_diff, TreeValueDiff};
|
||||
use std::pin::Pin;
|
||||
|
@ -90,12 +90,12 @@ impl Tree {
|
|||
&self.data
|
||||
}
|
||||
|
||||
pub fn entries(&self) -> TreeEntriesIter {
|
||||
pub fn entries_non_recursive(&self) -> TreeEntriesNonRecursiveIter {
|
||||
self.data.entries()
|
||||
}
|
||||
|
||||
pub fn entries_recursive(&self) -> TreeWalk {
|
||||
TreeWalk::new(self.clone())
|
||||
pub fn entries(&self) -> TreeEntriesIter {
|
||||
TreeEntriesIter::new(self.clone())
|
||||
}
|
||||
|
||||
pub fn entry<N>(&self, basename: &N) -> Option<TreeEntry>
|
||||
|
@ -194,7 +194,7 @@ impl Tree {
|
|||
|
||||
pub fn conflicts(&self) -> Vec<(RepoPath, ConflictId)> {
|
||||
let mut conflicts = vec![];
|
||||
for (name, value) in self.entries_recursive() {
|
||||
for (name, value) in self.entries() {
|
||||
if let TreeValue::Conflict(id) = value {
|
||||
conflicts.push((name.clone(), id.clone()));
|
||||
}
|
||||
|
@ -203,22 +203,22 @@ impl Tree {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct TreeWalk {
|
||||
stack: Vec<(Pin<Box<Tree>>, TreeEntriesIter<'static>)>,
|
||||
pub struct TreeEntriesIter {
|
||||
stack: Vec<(Pin<Box<Tree>>, TreeEntriesNonRecursiveIter<'static>)>,
|
||||
}
|
||||
|
||||
impl TreeWalk {
|
||||
impl TreeEntriesIter {
|
||||
fn new(tree: Tree) -> Self {
|
||||
let tree = Box::pin(tree);
|
||||
let iter = tree.entries();
|
||||
let iter: TreeEntriesIter<'static> = unsafe { std::mem::transmute(iter) };
|
||||
let iter = tree.entries_non_recursive();
|
||||
let iter: TreeEntriesNonRecursiveIter<'static> = unsafe { std::mem::transmute(iter) };
|
||||
Self {
|
||||
stack: vec![(tree, iter)],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for TreeWalk {
|
||||
impl Iterator for TreeEntriesIter {
|
||||
type Item = (RepoPath, TreeValue);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
|
@ -235,8 +235,8 @@ impl Iterator for TreeWalk {
|
|||
let subtree =
|
||||
tree.known_sub_tree(&DirRepoPathComponent::from(entry.name()), id);
|
||||
let subtree = Box::pin(subtree);
|
||||
let iter = subtree.entries();
|
||||
let subtree_iter: TreeEntriesIter<'static> =
|
||||
let iter = subtree.entries_non_recursive();
|
||||
let subtree_iter: TreeEntriesNonRecursiveIter<'static> =
|
||||
unsafe { std::mem::transmute(iter) };
|
||||
self.stack.push((subtree, subtree_iter));
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ fn diff_entries<'a, E>(
|
|||
tree2: &'a Tree,
|
||||
callback: &mut impl FnMut(&'a str, TreeValueDiff<'a>) -> Result<(), E>,
|
||||
) -> Result<(), E> {
|
||||
let mut it1 = tree1.entries();
|
||||
let mut it2 = tree2.entries();
|
||||
let mut it1 = tree1.entries_non_recursive();
|
||||
let mut it2 = tree2.entries_non_recursive();
|
||||
let mut entry1 = it1.next();
|
||||
let mut entry2 = it2.next();
|
||||
loop {
|
||||
|
|
|
@ -68,7 +68,7 @@ fn test_same_type(use_git: bool) {
|
|||
let side1_tree = write_tree(1);
|
||||
let side2_tree = write_tree(2);
|
||||
|
||||
// Created the merged tree
|
||||
// Create the merged tree
|
||||
let merged_tree_id = trees::merge_trees(&side1_tree, &base_tree, &side2_tree).unwrap();
|
||||
let merged_tree = store
|
||||
.get_tree(&DirRepoPath::root(), &merged_tree_id)
|
||||
|
@ -76,7 +76,7 @@ fn test_same_type(use_git: bool) {
|
|||
|
||||
// Check that we have exactly the paths we expect in the merged tree
|
||||
let names: Vec<&str> = merged_tree
|
||||
.entries()
|
||||
.entries_non_recursive()
|
||||
.map(|entry| entry.name().as_ref())
|
||||
.collect();
|
||||
assert_eq!(
|
||||
|
|
|
@ -565,7 +565,7 @@ fn cmd_files(
|
|||
let mut repo = get_repo(ui, &matches)?;
|
||||
let mut_repo = Arc::get_mut(&mut repo).unwrap();
|
||||
let commit = resolve_revision_arg(ui, mut_repo, sub_matches)?;
|
||||
for (name, _value) in commit.tree().entries_recursive() {
|
||||
for (name, _value) in commit.tree().entries() {
|
||||
writeln!(ui, "{}", name.to_internal_string());
|
||||
}
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in a new issue