Add timestamps to branches

This commit is contained in:
Piotr Osiewicz 2023-06-27 13:28:50 +02:00
parent 6747acbb84
commit 3027e4729a
4 changed files with 19 additions and 10 deletions

1
Cargo.lock generated
View file

@ -2549,6 +2549,7 @@ dependencies = [
"smol", "smol",
"sum_tree", "sum_tree",
"tempfile", "tempfile",
"time 0.3.21",
"util", "util",
] ]

View file

@ -17,7 +17,6 @@ pub fn build_branch_list(
) -> BranchList { ) -> BranchList {
Picker::new( Picker::new(
BranchListDelegate { BranchListDelegate {
branches: vec!["Foo".into(), "bar/baz".into()],
matches: vec![], matches: vec![],
project, project,
selected_index: 0, selected_index: 0,
@ -29,7 +28,6 @@ pub fn build_branch_list(
} }
pub struct BranchListDelegate { pub struct BranchListDelegate {
branches: Vec<String>,
matches: Vec<StringMatch>, matches: Vec<StringMatch>,
project: ModelHandle<Project>, project: ModelHandle<Project>,
selected_index: usize, selected_index: usize,
@ -77,8 +75,8 @@ impl PickerDelegate for BranchListDelegate {
.enumerate() .enumerate()
.map(|(ix, command)| StringMatchCandidate { .map(|(ix, command)| StringMatchCandidate {
id: ix, id: ix,
string: command.clone(), char_bag: command.name.chars().collect(),
char_bag: command.chars().collect(), string: command.name.into(),
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
}) })

View file

@ -31,6 +31,7 @@ serde_derive.workspace = true
serde_json.workspace = true serde_json.workspace = true
log.workspace = true log.workspace = true
libc = "0.2" libc = "0.2"
time.workspace = true
[dev-dependencies] [dev-dependencies]
gpui = { path = "../gpui", features = ["test-support"] } gpui = { path = "../gpui", features = ["test-support"] }

View file

@ -16,6 +16,12 @@ use util::ResultExt;
pub use git2::Repository as LibGitRepository; pub use git2::Repository as LibGitRepository;
#[derive(Clone, Debug, Hash, PartialEq)]
pub struct Branch {
pub name: Box<str>,
/// Timestamp of most recent commit, normalized to Unix Epoch format.
pub unix_timestamp: Option<i64>,
}
#[async_trait::async_trait] #[async_trait::async_trait]
pub trait GitRepository: Send { pub trait GitRepository: Send {
fn reload_index(&self); fn reload_index(&self);
@ -27,7 +33,7 @@ pub trait GitRepository: Send {
fn statuses(&self) -> Option<TreeMap<RepoPath, GitFileStatus>>; fn statuses(&self) -> Option<TreeMap<RepoPath, GitFileStatus>>;
fn status(&self, path: &RepoPath) -> Result<Option<GitFileStatus>>; fn status(&self, path: &RepoPath) -> Result<Option<GitFileStatus>>;
fn branches(&self) -> Result<Vec<String>> { fn branches(&self) -> Result<Vec<Branch>> {
Ok(vec![]) Ok(vec![])
} }
fn change_branch(&self, _: &str) -> Result<()> { fn change_branch(&self, _: &str) -> Result<()> {
@ -112,14 +118,17 @@ impl GitRepository for LibGitRepository {
} }
} }
} }
fn branches(&self) -> Result<Vec<String>> { fn branches(&self) -> Result<Vec<Branch>> {
let local_branches = self.branches(Some(BranchType::Local))?; let local_branches = self.branches(Some(BranchType::Local))?;
let valid_branches = local_branches let valid_branches = local_branches
.filter_map(|branch| { .filter_map(|branch| {
branch branch.ok().and_then(|(branch, _)| {
.ok() let name = branch.name().ok().flatten().map(Box::from)?;
.map(|(branch, _)| branch.name().ok().flatten().map(String::from)) Some(Branch {
.flatten() name,
unix_timestamp: None,
})
})
}) })
.collect(); .collect();
Ok(valid_branches) Ok(valid_branches)