From 3c0bbe5eb5995d71f1af927bf1262ba3123ea8b6 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 8 Apr 2021 16:03:10 -0600 Subject: [PATCH] Store root entry id --- zed/src/worktree/worktree.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/zed/src/worktree/worktree.rs b/zed/src/worktree/worktree.rs index dea9c1bcdb..a00b0d55c5 100644 --- a/zed/src/worktree/worktree.rs +++ b/zed/src/worktree/worktree.rs @@ -33,6 +33,7 @@ pub struct Worktree(Arc>); struct WorktreeState { id: usize, path: PathBuf, + root_ino: Option, entries: HashMap, file_paths: Vec, histories: HashMap, @@ -55,6 +56,7 @@ impl Worktree { let tree = Self(Arc::new(RwLock::new(WorktreeState { id, path: path.into(), + root_ino: None, entries: HashMap::new(), file_paths: Vec::new(), histories: HashMap::new(), @@ -100,6 +102,7 @@ impl Worktree { } let is_ignored = ignore.matched(&path, metadata.is_dir()).is_ignore(); + self.0.write().root_ino = Some(0); if metadata.file_type().is_dir() { let is_ignored = is_ignored || name == ".git"; let id = self.insert_dir(None, name, ino, is_symlink, is_ignored); @@ -409,6 +412,13 @@ impl Entity for Worktree { type Event = (); } +impl WorktreeState { + fn root_entry(&self) -> Option<&Entry> { + self.root_ino + .and_then(|root_ino| self.entries.get(&root_ino)) + } +} + pub trait WorktreeHandle { fn file(&self, entry_id: usize, app: &AppContext) -> Result; } @@ -504,7 +514,7 @@ impl Iterator for Iter { if !self.started { self.started = true; - return if let Some(entry) = state.entries.get(&0).cloned() { + return if let Some(entry) = state.root_entry().cloned() { self.stack.push(IterStackEntry { entry_id: 0, child_idx: 0, @@ -620,7 +630,7 @@ pub fn match_paths( .iter() .map(|tree| { let skip_prefix = if trees.len() == 1 { - if let Some(Entry::Dir { name, .. }) = tree.entries.get(&0) { + if let Some(Entry::Dir { name, .. }) = tree.root_entry() { let name = name.to_string_lossy(); if name == "/" { 1