List recent branches
This commit is contained in:
parent
3027e4729a
commit
54fad5969f
2 changed files with 26 additions and 6 deletions
|
@ -2,7 +2,7 @@ use fuzzy::{StringMatch, StringMatchCandidate};
|
||||||
use gpui::{elements::*, AppContext, ModelHandle, MouseState, Task, ViewContext};
|
use gpui::{elements::*, AppContext, ModelHandle, MouseState, Task, ViewContext};
|
||||||
use picker::{Picker, PickerDelegate, PickerEvent};
|
use picker::{Picker, PickerDelegate, PickerEvent};
|
||||||
use project::Project;
|
use project::Project;
|
||||||
use std::sync::Arc;
|
use std::{cmp::Ordering, sync::Arc};
|
||||||
use util::{ResultExt, TryFutureExt};
|
use util::{ResultExt, TryFutureExt};
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
pub fn init(cx: &mut AppContext) {
|
||||||
|
@ -67,9 +67,23 @@ impl PickerDelegate for BranchListDelegate {
|
||||||
.path
|
.path
|
||||||
.to_path_buf();
|
.to_path_buf();
|
||||||
cwd.push(".git");
|
cwd.push(".git");
|
||||||
let branches = project.fs().open_repo(&cwd).unwrap().lock().branches();
|
let mut branches = project
|
||||||
branches
|
.fs()
|
||||||
|
.open_repo(&cwd)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
.lock()
|
||||||
|
.branches()
|
||||||
|
.unwrap();
|
||||||
|
if query.is_empty() {
|
||||||
|
const RECENT_BRANCHES_COUNT: usize = 10;
|
||||||
|
// Do a partial sort to show recent-ish branches first.
|
||||||
|
branches.select_nth_unstable_by(RECENT_BRANCHES_COUNT, |lhs, rhs| {
|
||||||
|
rhs.unix_timestamp.cmp(&lhs.unix_timestamp)
|
||||||
|
});
|
||||||
|
branches.truncate(RECENT_BRANCHES_COUNT);
|
||||||
|
branches.sort_unstable_by(|lhs, rhs| lhs.name.cmp(&rhs.name));
|
||||||
|
}
|
||||||
|
branches
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
|
@ -106,15 +120,14 @@ impl PickerDelegate for BranchListDelegate {
|
||||||
picker
|
picker
|
||||||
.update(&mut cx, |picker, _| {
|
.update(&mut cx, |picker, _| {
|
||||||
let delegate = picker.delegate_mut();
|
let delegate = picker.delegate_mut();
|
||||||
//delegate.branches = actions;
|
|
||||||
delegate.matches = matches;
|
delegate.matches = matches;
|
||||||
delegate.last_query = query;
|
|
||||||
if delegate.matches.is_empty() {
|
if delegate.matches.is_empty() {
|
||||||
delegate.selected_index = 0;
|
delegate.selected_index = 0;
|
||||||
} else {
|
} else {
|
||||||
delegate.selected_index =
|
delegate.selected_index =
|
||||||
core::cmp::min(delegate.selected_index, delegate.matches.len() - 1);
|
core::cmp::min(delegate.selected_index, delegate.matches.len() - 1);
|
||||||
}
|
}
|
||||||
|
delegate.last_query = query;
|
||||||
})
|
})
|
||||||
.log_err();
|
.log_err();
|
||||||
})
|
})
|
||||||
|
|
|
@ -124,9 +124,16 @@ impl GitRepository for LibGitRepository {
|
||||||
.filter_map(|branch| {
|
.filter_map(|branch| {
|
||||||
branch.ok().and_then(|(branch, _)| {
|
branch.ok().and_then(|(branch, _)| {
|
||||||
let name = branch.name().ok().flatten().map(Box::from)?;
|
let name = branch.name().ok().flatten().map(Box::from)?;
|
||||||
|
let timestamp = branch.get().peel_to_commit().ok()?.time();
|
||||||
|
let unix_timestamp = timestamp.seconds();
|
||||||
|
let timezone_offset = timestamp.offset_minutes();
|
||||||
|
let utc_offset =
|
||||||
|
time::UtcOffset::from_whole_seconds(timezone_offset * 60).ok()?;
|
||||||
|
let unix_timestamp =
|
||||||
|
time::OffsetDateTime::from_unix_timestamp(unix_timestamp).ok()?;
|
||||||
Some(Branch {
|
Some(Branch {
|
||||||
name,
|
name,
|
||||||
unix_timestamp: None,
|
unix_timestamp: Some(unix_timestamp.to_offset(utc_offset).unix_timestamp()),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue