Detailed changes
@@ -6537,6 +6537,12 @@ dependencies = [
"winx",
]
+[[package]]
+name = "take-until"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8bdb6fa0dfa67b38c1e66b7041ba9dcf23b99d8121907cd31c807a332f7a0bbb"
+
[[package]]
name = "target-lexicon"
version = "0.12.5"
@@ -7596,6 +7602,7 @@ dependencies = [
"serde",
"serde_json",
"smol",
+ "take-until",
"tempdir",
"url",
]
@@ -2760,7 +2760,7 @@ async fn test_git_status_sync(
let worktree = worktrees[0].clone();
let snapshot = worktree.read(cx).snapshot();
let root_entry = snapshot.root_git_entry().unwrap();
- assert_eq!(root_entry.status_for(&snapshot, file), status);
+ assert_eq!(root_entry.status_for_file(&snapshot, file), status);
}
// Smoke test status reading
@@ -184,7 +184,7 @@ fn check_path_to_repo_path_errors(relative_file_path: &Path) -> Result<()> {
}
}
-#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum GitFileStatus {
Added,
Modified,
@@ -55,7 +55,7 @@ use std::{
time::{Duration, SystemTime},
};
use sum_tree::{Bias, Edit, SeekTarget, SumTree, TreeMap, TreeSet};
-use util::{paths::HOME, ResultExt, TryFutureExt};
+use util::{paths::HOME, ResultExt, TakeUntilExt, TryFutureExt};
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, PartialOrd, Ord)]
pub struct WorktreeId(usize);
@@ -173,13 +173,37 @@ impl RepositoryEntry {
self.work_directory.contains(snapshot, path)
}
- pub fn status_for(&self, snapshot: &Snapshot, path: &Path) -> Option<GitFileStatus> {
+ pub fn status_for_file(&self, snapshot: &Snapshot, path: &Path) -> Option<GitFileStatus> {
self.work_directory
.relativize(snapshot, path)
.and_then(|repo_path| self.worktree_statuses.get(&repo_path))
.cloned()
}
+ pub fn status_for_path(&self, snapshot: &Snapshot, path: &Path) -> Option<GitFileStatus> {
+ self.work_directory
+ .relativize(snapshot, path)
+ .and_then(|repo_path| {
+ self.worktree_statuses
+ .get_from_while(&repo_path, |repo_path, key, _| key.starts_with(repo_path))
+ .map(|(_, status)| status)
+ // Short circut once we've found the highest level
+ .take_until(|status| status == &&GitFileStatus::Conflict)
+ .reduce(
+ |status_first, status_second| match (status_first, status_second) {
+ (GitFileStatus::Conflict, _) | (_, GitFileStatus::Conflict) => {
+ &GitFileStatus::Conflict
+ }
+ (GitFileStatus::Added, _) | (_, GitFileStatus::Added) => {
+ &GitFileStatus::Added
+ }
+ _ => &GitFileStatus::Modified,
+ },
+ )
+ .copied()
+ })
+ }
+
pub fn build_update(&self, other: &Self) -> proto::RepositoryEntry {
let mut updated_statuses: Vec<proto::StatusEntry> = Vec::new();
let mut removed_statuses: Vec<String> = Vec::new();
@@ -1013,9 +1013,13 @@ impl ProjectPanel {
let entry_range = range.start.saturating_sub(ix)..end_ix - ix;
for entry in &visible_worktree_entries[entry_range] {
let path = &entry.path;
- let status = snapshot
- .repo_for(path)
- .and_then(|entry| entry.status_for(&snapshot, path));
+ let status = (entry.path.parent().is_some() && !entry.is_ignored)
+ .then(|| {
+ snapshot
+ .repo_for(path)
+ .and_then(|entry| entry.status_for_path(&snapshot, path))
+ })
+ .flatten();
let mut details = EntryDetails {
filename: entry
@@ -1,4 +1,4 @@
-use std::{cmp::Ordering, fmt::Debug};
+use std::{cmp::Ordering, fmt::Debug, iter};
use crate::{Bias, Dimension, Edit, Item, KeyedItem, SeekTarget, SumTree, Summary};
@@ -111,6 +111,26 @@ impl<K: Clone + Debug + Default + Ord, V: Clone + Debug> TreeMap<K, V> {
self.0 = new_tree;
}
+
+ pub fn get_from_while<'tree, F>(&'tree self, from: &'tree K, mut f: F) -> impl Iterator<Item = (&K, &V)> + '_
+ where
+ F: FnMut(&K, &K, &V) -> bool + 'tree,
+ {
+ let mut cursor = self.0.cursor::<MapKeyRef<'_, K>>();
+ let from_key = MapKeyRef(Some(from));
+ cursor.seek(&from_key, Bias::Left, &());
+
+ iter::from_fn(move || {
+ let result = cursor.item().and_then(|item| {
+ (f(from, &item.key, &item.value))
+ .then(|| (&item.key, &item.value))
+ });
+ cursor.next(&());
+ result
+ })
+ }
+
+
pub fn update<F, T>(&mut self, key: &K, f: F) -> Option<T>
where
F: FnOnce(&mut V) -> T,
@@ -354,6 +374,28 @@ mod tests {
assert_eq!(map.get(&"c"), Some(&5));
}
+ #[test]
+ fn test_get_from_while() {
+ let mut map = TreeMap::default();
+
+ map.insert("a", 1);
+ map.insert("b", 2);
+ map.insert("baa", 3);
+ map.insert("baaab", 4);
+ map.insert("c", 5);
+
+ let result = map.get_from_while(&"ba", |key, _| key.starts_with(&"ba")).collect::<Vec<_>>();
+
+ assert_eq!(result.len(), 2);
+ assert!(result.iter().find(|(k, _)| k == &&"baa").is_some());
+ assert!(result.iter().find(|(k, _)| k == &&"baaab").is_some());
+
+ let result = map.get_from_while(&"c", |key, _| key.starts_with(&"c")).collect::<Vec<_>>();
+
+ assert_eq!(result.len(), 1);
+ assert!(result.iter().find(|(k, _)| k == &&"c").is_some());
+ }
+
#[test]
fn test_insert_tree() {
let mut map = TreeMap::default();
@@ -26,6 +26,7 @@ serde.workspace = true
serde_json.workspace = true
git2 = { version = "0.15", default-features = false, optional = true }
dirs = "3.0"
+take-until = "0.2.0"
[dev-dependencies]
tempdir.workspace = true
@@ -17,6 +17,8 @@ pub use backtrace::Backtrace;
use futures::Future;
use rand::{seq::SliceRandom, Rng};
+pub use take_until::*;
+
#[macro_export]
macro_rules! debug_panic {
( $($fmt_arg:tt)* ) => {