@@ -8,7 +8,7 @@ use chrono::prelude::*;
88use crossbeam_channel:: Sender ;
99use crossterm:: event:: Event ;
1010use std:: { borrow:: Cow , cmp, convert:: TryFrom , time:: Instant } ;
11- use sync:: CommitInfo ;
11+ use sync:: { CommitInfo , Tags } ;
1212use tui:: {
1313 backend:: Backend ,
1414 layout:: { Alignment , Rect } ,
@@ -24,29 +24,32 @@ struct LogEntry {
2424 hash : String ,
2525}
2626
27- impl From < & CommitInfo > for LogEntry {
28- fn from ( c : & CommitInfo ) -> Self {
27+ impl From < CommitInfo > for LogEntry {
28+ fn from ( c : CommitInfo ) -> Self {
2929 let time =
3030 DateTime :: < Local > :: from ( DateTime :: < Utc > :: from_utc (
3131 NaiveDateTime :: from_timestamp ( c. time , 0 ) ,
3232 Utc ,
3333 ) ) ;
3434 Self {
35- author : c. author . clone ( ) ,
36- msg : c. message . clone ( ) ,
35+ author : c. author ,
36+ msg : c. message ,
3737 time : time. format ( "%Y-%m-%d %H:%M:%S" ) . to_string ( ) ,
38- hash : c. hash [ 0 .. 7 ] . to_string ( ) ,
38+ hash : c. hash ,
3939 }
4040 }
4141}
4242
4343const COLOR_SELECTION_BG : Color = Color :: Blue ;
4444
45+ const STYLE_TAG : Style = Style :: new ( ) . fg ( Color :: Yellow ) ;
4546const STYLE_HASH : Style = Style :: new ( ) . fg ( Color :: Magenta ) ;
4647const STYLE_TIME : Style = Style :: new ( ) . fg ( Color :: Blue ) ;
4748const STYLE_AUTHOR : Style = Style :: new ( ) . fg ( Color :: Green ) ;
4849const STYLE_MSG : Style = Style :: new ( ) . fg ( Color :: Reset ) ;
4950
51+ const STYLE_TAG_SELECTED : Style =
52+ Style :: new ( ) . fg ( Color :: Yellow ) . bg ( COLOR_SELECTION_BG ) ;
5053const STYLE_HASH_SELECTED : Style =
5154 Style :: new ( ) . fg ( Color :: Magenta ) . bg ( COLOR_SELECTION_BG ) ;
5255const STYLE_TIME_SELECTED : Style =
@@ -56,7 +59,7 @@ const STYLE_AUTHOR_SELECTED: Style =
5659const STYLE_MSG_SELECTED : Style =
5760 Style :: new ( ) . fg ( Color :: Reset ) . bg ( COLOR_SELECTION_BG ) ;
5861
59- static ELEMENTS_PER_LINE : usize = 8 ;
62+ static ELEMENTS_PER_LINE : usize = 10 ;
6063static SLICE_SIZE : usize = 1000 ;
6164static SLICE_OFFSET_RELOAD_THRESHOLD : usize = 100 ;
6265
@@ -69,6 +72,7 @@ pub struct Revlog {
6972 visible : bool ,
7073 first_open_done : bool ,
7174 scroll_state : ( Instant , f32 ) ,
75+ tags : Tags ,
7276}
7377
7478impl Revlog {
@@ -82,6 +86,7 @@ impl Revlog {
8286 visible : false ,
8387 first_open_done : false ,
8488 scroll_state : ( Instant :: now ( ) , 0_f32 ) ,
89+ tags : Tags :: new ( ) ,
8590 }
8691 }
8792
@@ -94,7 +99,12 @@ impl Revlog {
9499
95100 let mut txt = Vec :: new ( ) ;
96101 for ( idx, e) in self . items . iter ( ) . enumerate ( ) {
97- Self :: add_entry ( e, idx == selection, & mut txt) ;
102+ let tag = if let Some ( tag_name) = self . tags . get ( & e. hash ) {
103+ tag_name. as_str ( )
104+ } else {
105+ ""
106+ } ;
107+ Self :: add_entry ( e, idx == selection, & mut txt, tag) ;
98108 }
99109
100110 let title =
@@ -138,9 +148,14 @@ impl Revlog {
138148 ) ;
139149
140150 if let Ok ( commits) = commits {
141- self . items . extend ( commits. iter ( ) . map ( LogEntry :: from) ) ;
151+ self . items
152+ . extend ( commits. into_iter ( ) . map ( LogEntry :: from) ) ;
142153 }
143154 }
155+
156+ if self . tags . is_empty ( ) {
157+ self . tags = sync:: get_tags ( CWD ) . unwrap ( ) ;
158+ }
144159 }
145160
146161 fn move_selection ( & mut self , up : bool ) {
@@ -190,6 +205,7 @@ impl Revlog {
190205 e : & ' a LogEntry ,
191206 selected : bool ,
192207 txt : & mut Vec < Text < ' a > > ,
208+ tag : & ' a str ,
193209 ) {
194210 let count_before = txt. len ( ) ;
195211
@@ -204,7 +220,7 @@ impl Revlog {
204220 } ;
205221
206222 txt. push ( Text :: Styled (
207- Cow :: from ( e. hash . as_str ( ) ) ,
223+ Cow :: from ( & e. hash [ 0 .. 7 ] ) ,
208224 if selected {
209225 STYLE_HASH_SELECTED
210226 } else {
@@ -229,6 +245,19 @@ impl Revlog {
229245 STYLE_AUTHOR
230246 } ,
231247 ) ) ;
248+ txt. push ( splitter. clone ( ) ) ;
249+ txt. push ( Text :: Styled (
250+ Cow :: from ( if tag. is_empty ( ) {
251+ String :: from ( "" )
252+ } else {
253+ format ! ( " {}" , tag)
254+ } ) ,
255+ if selected {
256+ STYLE_TAG_SELECTED
257+ } else {
258+ STYLE_TAG
259+ } ,
260+ ) ) ;
232261 txt. push ( splitter) ;
233262 txt. push ( Text :: Styled (
234263 Cow :: from ( e. msg . as_str ( ) ) ,
0 commit comments