@@ -10,9 +10,10 @@ use crate::{
10
10
ui:: style:: { SharedTheme , Theme } ,
11
11
} ;
12
12
use anyhow:: Result ;
13
- use asyncgit:: sync:: Tags ;
13
+ use asyncgit:: sync:: { BranchInfo , CommitId , Tags } ;
14
14
use chrono:: { DateTime , Local } ;
15
15
use crossterm:: event:: Event ;
16
+ use std:: collections:: BTreeMap ;
16
17
use std:: {
17
18
borrow:: Cow , cell:: Cell , cmp, convert:: TryFrom , time:: Instant ,
18
19
} ;
@@ -26,11 +27,14 @@ use tui::{
26
27
27
28
const ELEMENTS_PER_LINE : usize = 10 ;
28
29
30
+ type Branches = BTreeMap < CommitId , Vec < BranchInfo > > ;
31
+
29
32
///
30
33
pub struct CommitList {
31
34
title : String ,
32
35
selection : usize ,
33
36
branch : Option < String > ,
37
+ local_branch_list : Option < Branches > ,
34
38
count_total : usize ,
35
39
items : ItemBatch ,
36
40
scroll_state : ( Instant , f32 ) ,
@@ -52,6 +56,7 @@ impl CommitList {
52
56
items : ItemBatch :: default ( ) ,
53
57
selection : 0 ,
54
58
branch : None ,
59
+ local_branch_list : None ,
55
60
count_total : 0 ,
56
61
scroll_state : ( Instant :: now ( ) , 0_f32 ) ,
57
62
tags : None ,
@@ -73,6 +78,27 @@ impl CommitList {
73
78
self . branch = name;
74
79
}
75
80
81
+ ///
82
+ pub fn set_local_branch_list (
83
+ & mut self ,
84
+ branch_list : Option < Vec < BranchInfo > > ,
85
+ ) {
86
+ let mut res = Branches :: new ( ) ;
87
+ let mut adder = |key : CommitId , value : BranchInfo | {
88
+ if let Some ( key) = res. get_mut ( & key) {
89
+ key. push ( value)
90
+ } else {
91
+ res. insert ( key, vec ! [ value] ) ;
92
+ }
93
+ } ;
94
+
95
+ for branch in branch_list. unwrap_or_default ( ) {
96
+ adder ( branch. top_commit , branch) ;
97
+ }
98
+
99
+ self . local_branch_list = Some ( res) ;
100
+ }
101
+
76
102
///
77
103
pub const fn selection ( & self ) -> usize {
78
104
self . selection
@@ -192,6 +218,7 @@ impl CommitList {
192
218
e : & ' a LogEntry ,
193
219
selected : bool ,
194
220
tags : Option < String > ,
221
+ local_branches : Option < String > ,
195
222
theme : & Theme ,
196
223
width : usize ,
197
224
now : DateTime < Local > ,
@@ -231,6 +258,16 @@ impl CommitList {
231
258
232
259
txt. push ( splitter. clone ( ) ) ;
233
260
261
+ // branches
262
+ txt. push ( Span :: styled (
263
+ Cow :: from ( if let Some ( branches) = local_branches {
264
+ format ! ( " {}" , branches)
265
+ } else {
266
+ String :: from ( "" )
267
+ } ) ,
268
+ theme. branch_in_log ( selected) ,
269
+ ) ) ;
270
+
234
271
// commit tags
235
272
txt. push ( Span :: styled (
236
273
Cow :: from ( if let Some ( tags) = tags {
@@ -270,10 +307,22 @@ impl CommitList {
270
307
. as_ref ( )
271
308
. and_then ( |t| t. get ( & e. id ) )
272
309
. map ( |tags| tags. join ( " " ) ) ;
310
+ let branches = self
311
+ . local_branch_list
312
+ . as_ref ( )
313
+ . and_then ( |b| b. get ( & e. id ) )
314
+ . map ( |branches| {
315
+ branches
316
+ . iter ( )
317
+ . map ( |b| b. name . to_string ( ) )
318
+ . collect :: < Vec < String > > ( )
319
+ . join ( " " )
320
+ } ) ;
273
321
txt. push ( Self :: get_entry_to_add (
274
322
e,
275
323
idx + self . scroll_top . get ( ) == selection,
276
324
tags,
325
+ branches,
277
326
& self . theme ,
278
327
width,
279
328
now,
0 commit comments