@@ -66,6 +66,10 @@ function! flog#split_limit(limit) abort
6666 return [a: limit [: l: start - 1 ], a: limit [l: start :]]
6767endfunction
6868
69+ function ! flog#get_sort_type (name) abort
70+ return filter (copy (g: flog_sort_types ), ' v:val.name ==# ' . string (a: name ))[0 ]
71+ endfunction
72+
6973function ! flog#get (dict , key , ... ) abort
7074 if type (a: dict ) != v: t_dict
7175 return v: null
@@ -209,6 +213,7 @@ function! flog#get_internal_default_args() abort
209213 \ ' no_graph' : v: false ,
210214 \ ' no_patch' : v: false ,
211215 \ ' skip' : v: null ,
216+ \ ' sort' : v: null ,
212217 \ ' max_count' : v: null ,
213218 \ ' open_cmd' : ' tabedit' ,
214219 \ ' search' : v: null ,
@@ -319,6 +324,10 @@ function! flog#parse_set_args(args, current_args, defaults) abort
319324 let a: current_args .skip = flog#parse_arg_opt (l: arg )
320325 elseif l: arg == # ' -skip='
321326 let a: current_args .skip = a: defaults .skip
327+ elseif l: arg = ~# ' ^-sort=.\+'
328+ let a: current_args .sort = flog#parse_arg_opt (l: arg )
329+ elseif l: arg == # ' -sort='
330+ let a: current_args .sort = a: defaults .sort
322331 elseif l: arg = ~# ' ^-max-count=\d\+'
323332 let a: current_args .max_count = flog#parse_arg_opt (l: arg )
324333 elseif l: arg == # ' -max-count='
@@ -613,6 +622,12 @@ function! flog#complete_author(arg_lead) abort
613622 return flog#filter_completions (a: arg_lead , l: authors )
614623endfunction
615624
625+ function ! flog#complete_sort (arg_lead) abort
626+ let [l: lead , l: name ] = flog#split_single_completable_arg (a: arg_lead )
627+ let l: sort_types = flog#escape_completions (l: lead , map (copy (g: flog_sort_types ), ' v:val.name' ))
628+ return flog#filter_completions (a: arg_lead , l: sort_types )
629+ endfunction
630+
616631function ! flog#complete (arg_lead, cmd_line, cursor_pos) abort
617632 if a: cmd_line [:a: cursor_pos ] = ~# ' -- '
618633 return []
@@ -636,6 +651,8 @@ function! flog#complete(arg_lead, cmd_line, cursor_pos) abort
636651 return flog#complete_rev (a: arg_lead )
637652 elseif a: arg_lead = ~# ' ^-path='
638653 return flog#complete_path (a: arg_lead )
654+ elseif a: arg_lead = ~# ' ^-sort='
655+ return flog#complete_sort (a: arg_lead )
639656 endif
640657 return flog#filter_completions (a: arg_lead , copy (g: flog_default_completion ))
641658endfunction
@@ -824,6 +841,9 @@ function! flog#build_log_args() abort
824841 if l: opts .skip != v: null
825842 let l: args .= ' --skip=' . shellescape (l: opts .skip )
826843 endif
844+ if l: opts .sort != v: null
845+ let l: sort_type = flog#get_sort_type (l: opts .sort )
846+ let l: args .= ' ' . l: sort_type .args
827847 endif
828848 if l: opts .max_count != v: null
829849 let l: args .= ' --max-count=' . shellescape (l: opts .max_count)
@@ -1123,6 +1143,9 @@ function! flog#set_graph_buffer_title() abort
11231143 if l: opts .skip != v: null
11241144 let l: title .= ' [skip=' . l: opts .skip . ' ]'
11251145 endif
1146+ if l: opts .sort != v: null
1147+ let l: title .= ' [sort=' . l: opts .sort . ' ]'
1148+ endif
11261149 if l: opts .max_count != v: null
11271150 let l: title .= ' [max_count=' . l: opts .max_count . ' ]'
11281151 endif
@@ -1315,6 +1338,30 @@ function! flog#change_skip_by_max_count(multiplier) abort
13151338 call flog#populate_graph_buffer ()
13161339endfunction
13171340
1341+ function ! flog#set_sort_option (sort ) abort
1342+ let l: state = flog#get_state ()
1343+ let l: state .sort = a: sort
1344+ call flog#populate_graph_buffer ()
1345+ endfunction
1346+
1347+ function ! flog#cycle_sort_option () abort
1348+ let l: state = flog#get_state ()
1349+
1350+ if l: state .sort == v: null
1351+ let l: state .sort = g: flog_sort_types [0 ].name
1352+ else
1353+ let l: sort_type = flog#get_sort_type (l: state .sort )
1354+ let l: sort_index = index (g: flog_sort_types , l: sort_type )
1355+ if l: sort_index == len (g: flog_sort_types ) - 1
1356+ let l: state .sort = g: flog_sort_types [0 ].name
1357+ else
1358+ let l: state .sort = g: flog_sort_types [l: sort_index + 1 ].name
1359+ endif
1360+ endif
1361+
1362+ call flog#populate_graph_buffer ()
1363+ endfunction
1364+
13181365" }}}
13191366
13201367" Graph buffer update hook {{{
0 commit comments