Skip to content
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

Display tags and branches in the revlog #1371

Merged
merged 3 commits into from
Oct 18, 2022
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 @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* add `regex-fancy` and `regex-onig` features to allow building Syntect with Onigumara regex engine instead of the default engine based on fancy-regex [[@jirutka](https://github.com/jirutka)]
* add `vendor-openssl` feature to allow building without vendored openssl [[@jirutka](https://github.com/jirutka)]
* allow copying marked commits [[@remique](https://github.com/remique)] ([#1288](https://github.com/extrawurst/gitui/issues/1288))
* display tags and branches in the log view ([#1371](https://github.com/extrawurst/gitui/pull/1371))

### Fixes
* remove insecure dependency `ansi_term` ([#1290](https://github.com/extrawurst/gitui/issues/1290))
Expand Down
52 changes: 43 additions & 9 deletions src/components/commitlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ use crate::{
ui::{calc_scroll_top, draw_scrollbar},
};
use anyhow::Result;
use asyncgit::sync::{CommitId, Tags};
use asyncgit::sync::{BranchInfo, CommitId, Tags};
use chrono::{DateTime, Local};
use crossterm::event::Event;
use itertools::Itertools;
use std::{
borrow::Cow, cell::Cell, cmp, convert::TryFrom, time::Instant,
borrow::Cow, cell::Cell, cmp, collections::BTreeMap,
convert::TryFrom, time::Instant,
};
use tui::{
backend::Backend,
Expand All @@ -37,6 +38,7 @@ pub struct CommitList {
marked: Vec<(usize, CommitId)>,
scroll_state: (Instant, f32),
tags: Option<Tags>,
branches: BTreeMap<CommitId, Vec<String>>,
current_size: Cell<(u16, u16)>,
scroll_top: Cell<usize>,
theme: SharedTheme,
Expand All @@ -58,6 +60,7 @@ impl CommitList {
count_total: 0,
scroll_state: (Instant::now(), 0_f32),
tags: None,
branches: BTreeMap::default(),
current_size: Cell::new((0, 0)),
scroll_top: Cell::new(0),
theme,
Expand Down Expand Up @@ -314,10 +317,12 @@ impl CommitList {
}
}

#[allow(clippy::too_many_arguments)]
fn get_entry_to_add<'a>(
e: &'a LogEntry,
selected: bool,
tags: Option<String>,
branches: Option<String>,
theme: &Theme,
width: usize,
now: DateTime<Local>,
Expand Down Expand Up @@ -373,12 +378,18 @@ impl CommitList {
txt.push(splitter.clone());

// commit tags
txt.push(Span::styled(
Cow::from(tags.map_or_else(String::new, |tags| {
format!(" {}", tags)
})),
theme.tags(selected),
));
if let Some(tags) = tags {
txt.push(splitter.clone());
txt.push(Span::styled(tags, theme.tags(selected)));
}

if let Some(branches) = branches {
txt.push(splitter.clone());
txt.push(Span::styled(
branches,
theme.branch(selected, true),
));
}

txt.push(splitter);

Expand Down Expand Up @@ -413,9 +424,20 @@ impl CommitList {
{
let tags =
self.tags.as_ref().and_then(|t| t.get(&e.id)).map(
|tags| tags.iter().map(|t| &t.name).join(" "),
|tags| {
tags.iter()
.map(|t| format!("<{}>", t.name))
.join(" ")
},
);

let branches = self.branches.get(&e.id).map(|names| {
names
.iter()
.map(|name| format!("[{}]", name))
.join(" ")
});

let marked = if any_marked {
self.is_marked(&e.id)
} else {
Expand All @@ -426,6 +448,7 @@ impl CommitList {
e,
idx + self.scroll_top.get() == selection,
tags,
branches,
&self.theme,
width,
now,
Expand All @@ -444,6 +467,17 @@ impl CommitList {
pub fn select_entry(&mut self, position: usize) {
self.selection = position;
}

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

for b in branches {
self.branches
.entry(b.top_commit)
.or_default()
.push(b.name);
}
}
}

impl DrawableComponent for CommitList {
Expand Down
7 changes: 6 additions & 1 deletion src/tabs/revlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
use anyhow::Result;
use asyncgit::{
cached,
sync::{self, CommitId, RepoPathRef},
sync::{self, get_branches_info, CommitId, RepoPathRef},
AsyncGitNotification, AsyncLog, AsyncTags, CommitFilesParams,
FetchStatus,
};
Expand Down Expand Up @@ -107,6 +107,11 @@ impl Revlog {
self.branch_name.lookup().map(Some).unwrap_or(None),
);

self.list.set_branches(get_branches_info(
&self.repo.borrow(),
true,
)?);

if self.commit_details.is_visible() {
let commit = self.selected_commit();
let tags = self.selected_commit_tags(&commit);
Expand Down
15 changes: 8 additions & 7 deletions src/ui/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub struct Theme {
danger_fg: Color,
push_gauge_bg: Color,
push_gauge_fg: Color,
tag_fg: Color,
branch_fg: Color,
}

impl Theme {
Expand Down Expand Up @@ -64,14 +66,11 @@ impl Theme {
Style::default().add_modifier(Modifier::BOLD)
} else {
Style::default()
};
}
.fg(self.branch_fg);

if selected {
branch.patch(
Style::default()
.fg(self.command_fg)
.bg(self.selection_bg),
)
branch.patch(Style::default().bg(self.selection_bg))
} else {
branch
}
Expand All @@ -89,7 +88,7 @@ impl Theme {

pub fn tags(&self, selected: bool) -> Style {
Style::default()
.fg(self.selected_tab)
.fg(self.tag_fg)
.add_modifier(Modifier::BOLD)
.bg(if selected {
self.selection_bg
Expand Down Expand Up @@ -325,6 +324,8 @@ impl Default for Theme {
danger_fg: Color::Red,
push_gauge_bg: Color::Blue,
push_gauge_fg: Color::Reset,
tag_fg: Color::LightMagenta,
branch_fg: Color::LightYellow,
}
}
}