Skip to content

Commit 216fad3

Browse files
authored
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
1 parent 8604b33 commit 216fad3

File tree

4 files changed

+58
-17
lines changed

4 files changed

+58
-17
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
* 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)]
2424
* add `vendor-openssl` feature to allow building without vendored openssl [[@jirutka](https://github.com/jirutka)]
2525
* allow copying marked commits [[@remique](https://github.com/remique)] ([#1288](https://github.com/extrawurst/gitui/issues/1288))
26+
* display tags and branches in the log view ([#1371](https://github.com/extrawurst/gitui/pull/1371))
2627

2728
### Fixes
2829
* remove insecure dependency `ansi_term` ([#1290](https://github.com/extrawurst/gitui/issues/1290))

src/components/commitlist.rs

+43-9
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ use crate::{
1010
ui::{calc_scroll_top, draw_scrollbar},
1111
};
1212
use anyhow::Result;
13-
use asyncgit::sync::{CommitId, Tags};
13+
use asyncgit::sync::{BranchInfo, CommitId, Tags};
1414
use chrono::{DateTime, Local};
1515
use crossterm::event::Event;
1616
use itertools::Itertools;
1717
use std::{
18-
borrow::Cow, cell::Cell, cmp, convert::TryFrom, time::Instant,
18+
borrow::Cow, cell::Cell, cmp, collections::BTreeMap,
19+
convert::TryFrom, time::Instant,
1920
};
2021
use tui::{
2122
backend::Backend,
@@ -37,6 +38,7 @@ pub struct CommitList {
3738
marked: Vec<(usize, CommitId)>,
3839
scroll_state: (Instant, f32),
3940
tags: Option<Tags>,
41+
branches: BTreeMap<CommitId, Vec<String>>,
4042
current_size: Cell<(u16, u16)>,
4143
scroll_top: Cell<usize>,
4244
theme: SharedTheme,
@@ -58,6 +60,7 @@ impl CommitList {
5860
count_total: 0,
5961
scroll_state: (Instant::now(), 0_f32),
6062
tags: None,
63+
branches: BTreeMap::default(),
6164
current_size: Cell::new((0, 0)),
6265
scroll_top: Cell::new(0),
6366
theme,
@@ -314,10 +317,12 @@ impl CommitList {
314317
}
315318
}
316319

320+
#[allow(clippy::too_many_arguments)]
317321
fn get_entry_to_add<'a>(
318322
e: &'a LogEntry,
319323
selected: bool,
320324
tags: Option<String>,
325+
branches: Option<String>,
321326
theme: &Theme,
322327
width: usize,
323328
now: DateTime<Local>,
@@ -373,12 +378,18 @@ impl CommitList {
373378
txt.push(splitter.clone());
374379

375380
// commit tags
376-
txt.push(Span::styled(
377-
Cow::from(tags.map_or_else(String::new, |tags| {
378-
format!(" {}", tags)
379-
})),
380-
theme.tags(selected),
381-
));
381+
if let Some(tags) = tags {
382+
txt.push(splitter.clone());
383+
txt.push(Span::styled(tags, theme.tags(selected)));
384+
}
385+
386+
if let Some(branches) = branches {
387+
txt.push(splitter.clone());
388+
txt.push(Span::styled(
389+
branches,
390+
theme.branch(selected, true),
391+
));
392+
}
382393

383394
txt.push(splitter);
384395

@@ -413,9 +424,20 @@ impl CommitList {
413424
{
414425
let tags =
415426
self.tags.as_ref().and_then(|t| t.get(&e.id)).map(
416-
|tags| tags.iter().map(|t| &t.name).join(" "),
427+
|tags| {
428+
tags.iter()
429+
.map(|t| format!("<{}>", t.name))
430+
.join(" ")
431+
},
417432
);
418433

434+
let branches = self.branches.get(&e.id).map(|names| {
435+
names
436+
.iter()
437+
.map(|name| format!("[{}]", name))
438+
.join(" ")
439+
});
440+
419441
let marked = if any_marked {
420442
self.is_marked(&e.id)
421443
} else {
@@ -426,6 +448,7 @@ impl CommitList {
426448
e,
427449
idx + self.scroll_top.get() == selection,
428450
tags,
451+
branches,
429452
&self.theme,
430453
width,
431454
now,
@@ -444,6 +467,17 @@ impl CommitList {
444467
pub fn select_entry(&mut self, position: usize) {
445468
self.selection = position;
446469
}
470+
471+
pub fn set_branches(&mut self, branches: Vec<BranchInfo>) {
472+
self.branches.clear();
473+
474+
for b in branches {
475+
self.branches
476+
.entry(b.top_commit)
477+
.or_default()
478+
.push(b.name);
479+
}
480+
}
447481
}
448482

449483
impl DrawableComponent for CommitList {

src/tabs/revlog.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
use anyhow::Result;
1414
use asyncgit::{
1515
cached,
16-
sync::{self, CommitId, RepoPathRef},
16+
sync::{self, get_branches_info, CommitId, RepoPathRef},
1717
AsyncGitNotification, AsyncLog, AsyncTags, CommitFilesParams,
1818
FetchStatus,
1919
};
@@ -107,6 +107,11 @@ impl Revlog {
107107
self.branch_name.lookup().map(Some).unwrap_or(None),
108108
);
109109

110+
self.list.set_branches(get_branches_info(
111+
&self.repo.borrow(),
112+
true,
113+
)?);
114+
110115
if self.commit_details.is_visible() {
111116
let commit = self.selected_commit();
112117
let tags = self.selected_commit_tags(&commit);

src/ui/style.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ pub struct Theme {
3636
danger_fg: Color,
3737
push_gauge_bg: Color,
3838
push_gauge_fg: Color,
39+
tag_fg: Color,
40+
branch_fg: Color,
3941
}
4042

4143
impl Theme {
@@ -64,14 +66,11 @@ impl Theme {
6466
Style::default().add_modifier(Modifier::BOLD)
6567
} else {
6668
Style::default()
67-
};
69+
}
70+
.fg(self.branch_fg);
6871

6972
if selected {
70-
branch.patch(
71-
Style::default()
72-
.fg(self.command_fg)
73-
.bg(self.selection_bg),
74-
)
73+
branch.patch(Style::default().bg(self.selection_bg))
7574
} else {
7675
branch
7776
}
@@ -89,7 +88,7 @@ impl Theme {
8988

9089
pub fn tags(&self, selected: bool) -> Style {
9190
Style::default()
92-
.fg(self.selected_tab)
91+
.fg(self.tag_fg)
9392
.add_modifier(Modifier::BOLD)
9493
.bg(if selected {
9594
self.selection_bg
@@ -325,6 +324,8 @@ impl Default for Theme {
325324
danger_fg: Color::Red,
326325
push_gauge_bg: Color::Blue,
327326
push_gauge_fg: Color::Reset,
327+
tag_fg: Color::LightMagenta,
328+
branch_fg: Color::LightYellow,
328329
}
329330
}
330331
}

0 commit comments

Comments
 (0)