mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 08:58:21 +00:00
Show remote branches in revlog
This commit is contained in:
parent
b15d24caf8
commit
3af256c75a
3 changed files with 96 additions and 30 deletions
|
|
@ -48,7 +48,7 @@ pub(crate) fn get_branch_name_repo(
|
|||
}
|
||||
|
||||
///
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct LocalBranch {
|
||||
///
|
||||
pub is_head: bool,
|
||||
|
|
@ -59,14 +59,14 @@ pub struct LocalBranch {
|
|||
}
|
||||
|
||||
///
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RemoteBranch {
|
||||
///
|
||||
pub has_tracking: bool,
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum BranchDetails {
|
||||
///
|
||||
Local(LocalBranch),
|
||||
|
|
@ -75,7 +75,7 @@ pub enum BranchDetails {
|
|||
}
|
||||
|
||||
///
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct BranchInfo {
|
||||
///
|
||||
pub name: String,
|
||||
|
|
|
|||
|
|
@ -42,7 +42,8 @@ pub struct CommitList {
|
|||
marked: Vec<(usize, CommitId)>,
|
||||
scroll_state: (Instant, f32),
|
||||
tags: Option<Tags>,
|
||||
branches: BTreeMap<CommitId, Vec<String>>,
|
||||
local_branches: BTreeMap<CommitId, Vec<BranchInfo>>,
|
||||
remote_branches: BTreeMap<CommitId, Vec<BranchInfo>>,
|
||||
current_size: Cell<Option<(u16, u16)>>,
|
||||
scroll_top: Cell<usize>,
|
||||
theme: SharedTheme,
|
||||
|
|
@ -67,7 +68,8 @@ impl CommitList {
|
|||
count_total: 0,
|
||||
scroll_state: (Instant::now(), 0_f32),
|
||||
tags: None,
|
||||
branches: BTreeMap::default(),
|
||||
local_branches: BTreeMap::default(),
|
||||
remote_branches: BTreeMap::default(),
|
||||
current_size: Cell::new(None),
|
||||
scroll_top: Cell::new(0),
|
||||
theme,
|
||||
|
|
@ -297,7 +299,8 @@ impl CommitList {
|
|||
e: &'a LogEntry,
|
||||
selected: bool,
|
||||
tags: Option<String>,
|
||||
branches: Option<String>,
|
||||
local_branches: Option<String>,
|
||||
remote_branches: Option<String>,
|
||||
theme: &Theme,
|
||||
width: usize,
|
||||
now: DateTime<Local>,
|
||||
|
|
@ -358,10 +361,18 @@ impl CommitList {
|
|||
txt.push(Span::styled(tags, theme.tags(selected)));
|
||||
}
|
||||
|
||||
if let Some(branches) = branches {
|
||||
if let Some(local_branches) = local_branches {
|
||||
txt.push(splitter.clone());
|
||||
txt.push(Span::styled(
|
||||
branches,
|
||||
local_branches,
|
||||
theme.branch(selected, true),
|
||||
));
|
||||
}
|
||||
|
||||
if let Some(remote_branches) = remote_branches {
|
||||
txt.push(splitter.clone());
|
||||
txt.push(Span::styled(
|
||||
remote_branches,
|
||||
theme.branch(selected, true),
|
||||
));
|
||||
}
|
||||
|
|
@ -406,12 +417,27 @@ impl CommitList {
|
|||
},
|
||||
);
|
||||
|
||||
let branches = self.branches.get(&e.id).map(|names| {
|
||||
names
|
||||
.iter()
|
||||
.map(|name| format!("{{{name}}}"))
|
||||
.join(" ")
|
||||
});
|
||||
let local_branches =
|
||||
self.local_branches.get(&e.id).map(|local_branch| {
|
||||
local_branch
|
||||
.iter()
|
||||
.map(|local_branch| {
|
||||
format!("{{{0}}}", local_branch.name)
|
||||
})
|
||||
.join(" ")
|
||||
});
|
||||
|
||||
let remote_branches = self
|
||||
.remote_branches
|
||||
.get(&e.id)
|
||||
.map(|remote_branches| {
|
||||
remote_branches
|
||||
.iter()
|
||||
.map(|remote_branch| {
|
||||
format!("[{0}]", remote_branch.name)
|
||||
})
|
||||
.join(" ")
|
||||
});
|
||||
|
||||
let marked = if any_marked {
|
||||
self.is_marked(&e.id)
|
||||
|
|
@ -423,7 +449,8 @@ impl CommitList {
|
|||
e,
|
||||
idx + self.scroll_top.get() == selection,
|
||||
tags,
|
||||
branches,
|
||||
local_branches,
|
||||
remote_branches,
|
||||
&self.theme,
|
||||
width,
|
||||
now,
|
||||
|
|
@ -455,14 +482,31 @@ impl CommitList {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn set_branches(&mut self, branches: Vec<BranchInfo>) {
|
||||
self.branches.clear();
|
||||
pub fn set_local_branches(
|
||||
&mut self,
|
||||
local_branches: Vec<BranchInfo>,
|
||||
) {
|
||||
self.local_branches.clear();
|
||||
|
||||
for b in branches {
|
||||
self.branches
|
||||
.entry(b.top_commit)
|
||||
for local_branch in local_branches {
|
||||
self.local_branches
|
||||
.entry(local_branch.top_commit)
|
||||
.or_default()
|
||||
.push(b.name);
|
||||
.push(local_branch);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_remote_branches(
|
||||
&mut self,
|
||||
remote_branches: Vec<BranchInfo>,
|
||||
) {
|
||||
self.remote_branches.clear();
|
||||
|
||||
for remote_branch in remote_branches {
|
||||
self.remote_branches
|
||||
.entry(remote_branch.top_commit)
|
||||
.or_default()
|
||||
.push(remote_branch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,8 @@ pub struct Revlog {
|
|||
list: CommitList,
|
||||
git_log: AsyncLog,
|
||||
git_tags: AsyncTags,
|
||||
git_branches: AsyncSingleJob<AsyncBranchesJob>,
|
||||
git_local_branches: AsyncSingleJob<AsyncBranchesJob>,
|
||||
git_remote_branches: AsyncSingleJob<AsyncBranchesJob>,
|
||||
queue: Queue,
|
||||
visible: bool,
|
||||
key_config: SharedKeyConfig,
|
||||
|
|
@ -74,7 +75,8 @@ impl Revlog {
|
|||
None,
|
||||
),
|
||||
git_tags: AsyncTags::new(repo.borrow().clone(), sender),
|
||||
git_branches: AsyncSingleJob::new(sender.clone()),
|
||||
git_local_branches: AsyncSingleJob::new(sender.clone()),
|
||||
git_remote_branches: AsyncSingleJob::new(sender.clone()),
|
||||
visible: false,
|
||||
key_config,
|
||||
}
|
||||
|
|
@ -84,7 +86,8 @@ impl Revlog {
|
|||
pub fn any_work_pending(&self) -> bool {
|
||||
self.git_log.is_pending()
|
||||
|| self.git_tags.is_pending()
|
||||
|| self.git_branches.is_pending()
|
||||
|| self.git_local_branches.is_pending()
|
||||
|| self.git_remote_branches.is_pending()
|
||||
|| self.commit_details.any_work_pending()
|
||||
}
|
||||
|
||||
|
|
@ -136,12 +139,26 @@ impl Revlog {
|
|||
}
|
||||
}
|
||||
AsyncGitNotification::Branches => {
|
||||
if let Some(branches) =
|
||||
self.git_branches.take_last()
|
||||
if let Some(local_branches) =
|
||||
self.git_local_branches.take_last()
|
||||
{
|
||||
if let Some(Ok(branches)) = branches.result()
|
||||
if let Some(Ok(local_branches)) =
|
||||
local_branches.result()
|
||||
{
|
||||
self.list.set_branches(branches);
|
||||
self.list
|
||||
.set_local_branches(local_branches);
|
||||
self.update()?;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(remote_branches) =
|
||||
self.git_remote_branches.take_last()
|
||||
{
|
||||
if let Some(Ok(remote_branches)) =
|
||||
remote_branches.result()
|
||||
{
|
||||
self.list
|
||||
.set_remote_branches(remote_branches);
|
||||
self.update()?;
|
||||
}
|
||||
}
|
||||
|
|
@ -505,11 +522,16 @@ impl Component for Revlog {
|
|||
self.visible = true;
|
||||
self.list.clear();
|
||||
|
||||
self.git_branches.spawn(AsyncBranchesJob::new(
|
||||
self.git_local_branches.spawn(AsyncBranchesJob::new(
|
||||
self.repo.borrow().clone(),
|
||||
true,
|
||||
));
|
||||
|
||||
self.git_remote_branches.spawn(AsyncBranchesJob::new(
|
||||
self.repo.borrow().clone(),
|
||||
false,
|
||||
));
|
||||
|
||||
self.update()?;
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Reference in a new issue