Skip to content

Show remote branches in log #1640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* allow `fetch` on status tab [[@alensiljak]](https://github.com/alensiljak) ([#1471](https://github.com/extrawurst/gitui/issues/1471))
* allow `copy` file path on revision files and status tree [[@yanganto]](https://github.com/yanganto) ([#1516](https://github.com/extrawurst/gitui/pull/1516))
* print message of where log will be written if `-l` is set ([#1472](https://github.com/extrawurst/gitui/pull/1472))
* show remote branches in log [[@cruessler](https://github.com/cruessler)] ([#1501](https://github.com/extrawurst/gitui/issues/1501))

### Fixes
* commit msg history ordered the wrong way ([#1445](https://github.com/extrawurst/gitui/issues/1445))
Expand Down
27 changes: 22 additions & 5 deletions asyncgit/src/sync/branch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,34 @@ pub(crate) fn get_branch_name_repo(
}

///
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct LocalBranch {
///
pub is_head: bool,
///
pub has_upstream: bool,
///
pub upstream: Option<UpstreamBranch>,
///
pub remote: Option<String>,
}

///
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct UpstreamBranch {
///
pub reference: String,
}

///
#[derive(Clone, Debug)]
pub struct RemoteBranch {
///
pub has_tracking: bool,
}

///
#[derive(Debug)]
#[derive(Clone, Debug)]
pub enum BranchDetails {
///
Local(LocalBranch),
Expand All @@ -75,7 +84,7 @@ pub enum BranchDetails {
}

///
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct BranchInfo {
///
pub name: String,
Expand Down Expand Up @@ -154,10 +163,18 @@ pub fn get_branches_info(

let name_bytes = branch.name_bytes()?;

let upstream_branch =
upstream.ok().and_then(|upstream| {
bytes2string(upstream.get().name_bytes())
.ok()
.map(|reference| UpstreamBranch { reference })
});

let details = if local {
BranchDetails::Local(LocalBranch {
is_head: branch.is_head(),
has_upstream: upstream.is_ok(),
has_upstream: upstream_branch.is_some(),
upstream: upstream_branch,
remote,
})
} else {
Expand Down
2 changes: 1 addition & 1 deletion asyncgit/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub use branch::{
merge_commit::merge_upstream_commit,
merge_ff::branch_merge_upstream_fastforward,
merge_rebase::merge_upstream_rebase, rename::rename_branch,
validate_branch_name, BranchCompare, BranchInfo,
validate_branch_name, BranchCompare, BranchDetails, BranchInfo,
};
pub use commit::{amend, commit, tag_commit};
pub use commit_details::{
Expand Down
110 changes: 91 additions & 19 deletions src/components/commitlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use crate::{
};
use anyhow::Result;
use asyncgit::sync::{
checkout_commit, BranchInfo, CommitId, RepoPathRef, Tags,
checkout_commit, BranchDetails, BranchInfo, CommitId,
RepoPathRef, Tags,
};
use chrono::{DateTime, Local};
use crossterm::event::Event;
Expand Down Expand Up @@ -42,7 +43,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,
Expand All @@ -67,7 +69,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,
Expand Down Expand Up @@ -297,7 +300,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>,
Expand Down Expand Up @@ -358,10 +362,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),
));
}
Expand Down Expand Up @@ -406,12 +418,54 @@ 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)
.and_then(|remote_branches| {
let filtered_branches: Vec<_> = remote_branches
.iter()
.filter(|remote_branch| {
self.local_branches
.get(&e.id)
.map_or(true, |local_branch| {
local_branch.iter().any(
|local_branch| {
let has_corresponding_local_branch = match &local_branch.details {
BranchDetails::Local(details) =>
details
.upstream
.as_ref()
.map_or(false, |upstream| upstream.reference == remote_branch.reference),
BranchDetails::Remote(_) =>
false,
};

!has_corresponding_local_branch
},
)
})
})
.map(|remote_branch| {
format!("[{0}]", remote_branch.name)
})
.collect();

if filtered_branches.is_empty() {
None
} else {
Some(filtered_branches.join(" "))
}
});

let marked = if any_marked {
self.is_marked(&e.id)
Expand All @@ -423,7 +477,8 @@ impl CommitList {
e,
idx + self.scroll_top.get() == selection,
tags,
branches,
local_branches,
remote_branches,
&self.theme,
width,
now,
Expand Down Expand Up @@ -455,14 +510,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 local_branch in local_branches {
self.local_branches
.entry(local_branch.top_commit)
.or_default()
.push(local_branch);
}
}

pub fn set_remote_branches(
&mut self,
remote_branches: Vec<BranchInfo>,
) {
self.remote_branches.clear();

for b in branches {
self.branches
.entry(b.top_commit)
for remote_branch in remote_branches {
self.remote_branches
.entry(remote_branch.top_commit)
.or_default()
.push(b.name);
.push(remote_branch);
}
}
}
Expand Down
38 changes: 30 additions & 8 deletions src/tabs/revlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
Expand All @@ -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()
}

Expand Down Expand Up @@ -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()?;
}
}
Expand Down Expand Up @@ -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(())
Expand Down