From 3af256c75a961dc6a9c716a6fafcacd78f41944a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20R=C3=BC=C3=9Fler?= Date: Sat, 8 Apr 2023 13:32:06 +0200 Subject: [PATCH] Show remote branches in revlog --- asyncgit/src/sync/branch/mod.rs | 8 ++-- src/components/commitlist.rs | 80 +++++++++++++++++++++++++-------- src/tabs/revlog.rs | 38 ++++++++++++---- 3 files changed, 96 insertions(+), 30 deletions(-) diff --git a/asyncgit/src/sync/branch/mod.rs b/asyncgit/src/sync/branch/mod.rs index 89056ecf..a6f019b9 100644 --- a/asyncgit/src/sync/branch/mod.rs +++ b/asyncgit/src/sync/branch/mod.rs @@ -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, diff --git a/src/components/commitlist.rs b/src/components/commitlist.rs index 91e48dd6..bdf67ea8 100644 --- a/src/components/commitlist.rs +++ b/src/components/commitlist.rs @@ -42,7 +42,8 @@ pub struct CommitList { marked: Vec<(usize, CommitId)>, scroll_state: (Instant, f32), tags: Option, - branches: BTreeMap>, + local_branches: BTreeMap>, + remote_branches: BTreeMap>, current_size: Cell>, scroll_top: Cell, 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, - branches: Option, + local_branches: Option, + remote_branches: Option, theme: &Theme, width: usize, now: DateTime, @@ -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) { - self.branches.clear(); + pub fn set_local_branches( + &mut self, + local_branches: Vec, + ) { + 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, + ) { + self.remote_branches.clear(); + + for remote_branch in remote_branches { + self.remote_branches + .entry(remote_branch.top_commit) + .or_default() + .push(remote_branch); } } } diff --git a/src/tabs/revlog.rs b/src/tabs/revlog.rs index 63a02cc3..dfbc71b1 100644 --- a/src/tabs/revlog.rs +++ b/src/tabs/revlog.rs @@ -36,7 +36,8 @@ pub struct Revlog { list: CommitList, git_log: AsyncLog, git_tags: AsyncTags, - git_branches: AsyncSingleJob, + git_local_branches: AsyncSingleJob, + git_remote_branches: AsyncSingleJob, 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(())