From 3027e4729abf2d9c83fe0d06683fa9834a4180f4 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Tue, 27 Jun 2023 13:28:50 +0200 Subject: [PATCH] Add timestamps to branches --- Cargo.lock | 1 + crates/collab_ui/src/branch_list.rs | 6 ++---- crates/fs/Cargo.toml | 1 + crates/fs/src/repository.rs | 21 +++++++++++++++------ 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a9b2e29ea0..a59332520b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2549,6 +2549,7 @@ dependencies = [ "smol", "sum_tree", "tempfile", + "time 0.3.21", "util", ] diff --git a/crates/collab_ui/src/branch_list.rs b/crates/collab_ui/src/branch_list.rs index ddd884523a..7da984a599 100644 --- a/crates/collab_ui/src/branch_list.rs +++ b/crates/collab_ui/src/branch_list.rs @@ -17,7 +17,6 @@ pub fn build_branch_list( ) -> BranchList { Picker::new( BranchListDelegate { - branches: vec!["Foo".into(), "bar/baz".into()], matches: vec![], project, selected_index: 0, @@ -29,7 +28,6 @@ pub fn build_branch_list( } pub struct BranchListDelegate { - branches: Vec, matches: Vec, project: ModelHandle, selected_index: usize, @@ -77,8 +75,8 @@ impl PickerDelegate for BranchListDelegate { .enumerate() .map(|(ix, command)| StringMatchCandidate { id: ix, - string: command.clone(), - char_bag: command.chars().collect(), + char_bag: command.name.chars().collect(), + string: command.name.into(), }) .collect::>() }) diff --git a/crates/fs/Cargo.toml b/crates/fs/Cargo.toml index cb738f567c..b3ebd224b0 100644 --- a/crates/fs/Cargo.toml +++ b/crates/fs/Cargo.toml @@ -31,6 +31,7 @@ serde_derive.workspace = true serde_json.workspace = true log.workspace = true libc = "0.2" +time.workspace = true [dev-dependencies] gpui = { path = "../gpui", features = ["test-support"] } diff --git a/crates/fs/src/repository.rs b/crates/fs/src/repository.rs index af6198eda4..36df0dfb98 100644 --- a/crates/fs/src/repository.rs +++ b/crates/fs/src/repository.rs @@ -16,6 +16,12 @@ use util::ResultExt; pub use git2::Repository as LibGitRepository; +#[derive(Clone, Debug, Hash, PartialEq)] +pub struct Branch { + pub name: Box, + /// Timestamp of most recent commit, normalized to Unix Epoch format. + pub unix_timestamp: Option, +} #[async_trait::async_trait] pub trait GitRepository: Send { fn reload_index(&self); @@ -27,7 +33,7 @@ pub trait GitRepository: Send { fn statuses(&self) -> Option>; fn status(&self, path: &RepoPath) -> Result>; - fn branches(&self) -> Result> { + fn branches(&self) -> Result> { Ok(vec![]) } fn change_branch(&self, _: &str) -> Result<()> { @@ -112,14 +118,17 @@ impl GitRepository for LibGitRepository { } } } - fn branches(&self) -> Result> { + fn branches(&self) -> Result> { let local_branches = self.branches(Some(BranchType::Local))?; let valid_branches = local_branches .filter_map(|branch| { - branch - .ok() - .map(|(branch, _)| branch.name().ok().flatten().map(String::from)) - .flatten() + branch.ok().and_then(|(branch, _)| { + let name = branch.name().ok().flatten().map(Box::from)?; + Some(Branch { + name, + unix_timestamp: None, + }) + }) }) .collect(); Ok(valid_branches)