mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 17:08:21 +00:00
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
This commit is contained in:
parent
8604b331ae
commit
216fad3140
4 changed files with 58 additions and 17 deletions
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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<Tags>,
|
||||
branches: BTreeMap<CommitId, Vec<String>>,
|
||||
current_size: Cell<(u16, u16)>,
|
||||
scroll_top: Cell<usize>,
|
||||
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<String>,
|
||||
branches: Option<String>,
|
||||
theme: &Theme,
|
||||
width: usize,
|
||||
now: DateTime<Local>,
|
||||
|
|
@ -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<BranchInfo>) {
|
||||
self.branches.clear();
|
||||
|
||||
for b in branches {
|
||||
self.branches
|
||||
.entry(b.top_commit)
|
||||
.or_default()
|
||||
.push(b.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DrawableComponent for CommitList {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue