From 216fad3140d5923ef78b2e4484e35f57326b6eaf Mon Sep 17 00:00:00 2001 From: Alexandru Macovei Date: Tue, 18 Oct 2022 14:37:20 +0300 Subject: [PATCH] Display tags and branches in the revlog (#1371) * give tags a more distinctive appearance in the revlog * store branches on commitlist, and display branch labels on head commits --- CHANGELOG.md | 1 + src/components/commitlist.rs | 52 +++++++++++++++++++++++++++++------- src/tabs/revlog.rs | 7 ++++- src/ui/style.rs | 15 ++++++----- 4 files changed, 58 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fea975dc30..5eafda47d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/src/components/commitlist.rs b/src/components/commitlist.rs index ebe4edc48a..a25960cfd2 100644 --- a/src/components/commitlist.rs +++ b/src/components/commitlist.rs @@ -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, @@ -37,6 +38,7 @@ pub struct CommitList { marked: Vec<(usize, CommitId)>, scroll_state: (Instant, f32), tags: Option, + branches: BTreeMap>, current_size: Cell<(u16, u16)>, scroll_top: Cell, theme: SharedTheme, @@ -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, @@ -314,10 +317,12 @@ impl CommitList { } } + #[allow(clippy::too_many_arguments)] fn get_entry_to_add<'a>( e: &'a LogEntry, selected: bool, tags: Option, + branches: Option, theme: &Theme, width: usize, now: DateTime, @@ -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); @@ -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 { @@ -426,6 +448,7 @@ impl CommitList { e, idx + self.scroll_top.get() == selection, tags, + branches, &self.theme, width, now, @@ -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) { + self.branches.clear(); + + for b in branches { + self.branches + .entry(b.top_commit) + .or_default() + .push(b.name); + } + } } impl DrawableComponent for CommitList { diff --git a/src/tabs/revlog.rs b/src/tabs/revlog.rs index 710617ca1a..5443bc64cc 100644 --- a/src/tabs/revlog.rs +++ b/src/tabs/revlog.rs @@ -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, }; @@ -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); diff --git a/src/ui/style.rs b/src/ui/style.rs index d66ff16bac..8fca7e7760 100644 --- a/src/ui/style.rs +++ b/src/ui/style.rs @@ -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 { @@ -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 } @@ -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 @@ -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, } } }