mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 17:50:04 +08:00
fix(git): improve branch detection
close https://github.com/SpaceVim/SpaceVim/issues/4142
This commit is contained in:
parent
d5f7ef3332
commit
0f623af900
@ -20,11 +20,11 @@ function! git#branch#run(args) abort
|
||||
call git#logger#info('git-branch cmd:' . string(cmd))
|
||||
call s:JOB.start(cmd,
|
||||
\ {
|
||||
\ 'on_stderr' : function('s:on_stderr'),
|
||||
\ 'on_stdout' : function('s:on_stdout'),
|
||||
\ 'on_exit' : function('s:on_exit'),
|
||||
\ }
|
||||
\ )
|
||||
\ 'on_stderr' : function('s:on_stderr'),
|
||||
\ 'on_stdout' : function('s:on_stdout'),
|
||||
\ 'on_exit' : function('s:on_exit'),
|
||||
\ }
|
||||
\ )
|
||||
|
||||
endfunction
|
||||
|
||||
@ -59,20 +59,21 @@ let s:branch = ''
|
||||
let s:branch_info = {}
|
||||
" {
|
||||
" branch_name : 'xxx',
|
||||
" last_update : 111111, ms
|
||||
" last_update_done : 111111, ms
|
||||
" }
|
||||
let s:job_pwds = {}
|
||||
|
||||
function! s:update_branch_name(pwd, ...) abort
|
||||
let force = get(a:000, 0, 0)
|
||||
let cmd = 'git rev-parse --abbrev-ref HEAD'
|
||||
if force || get(get(s:branch_info, a:pwd, {}), 'last_update', 0) >= localtime() - 1
|
||||
if force || get(get(s:branch_info, a:pwd, {}), 'last_update_done', 0) >= localtime() - 1
|
||||
let jobid = s:JOB.start(cmd,
|
||||
\ {
|
||||
\ 'on_stdout' : function('s:on_stdout_show_branch'),
|
||||
\ 'cwd' : a:pwd,
|
||||
\ }
|
||||
\ )
|
||||
\ 'on_stdout' : function('s:on_stdout_show_branch'),
|
||||
\ 'on_exit' : function('s:on_exit_show_branch'),
|
||||
\ 'cwd' : a:pwd,
|
||||
\ }
|
||||
\ )
|
||||
if jobid > 0
|
||||
call extend(s:job_pwds, {'jobid' . jobid : a:pwd})
|
||||
endif
|
||||
@ -84,10 +85,17 @@ function! s:on_stdout_show_branch(id, data, event) abort
|
||||
let pwd = get(s:job_pwds, 'jobid' . a:id, '')
|
||||
let s:branch_info[pwd] = {
|
||||
\ 'name' : b,
|
||||
\ 'last_update' : localtime(),
|
||||
\ }
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:on_exit_show_branch(id, data, event) abort
|
||||
let pwd = get(s:job_pwds, 'jobid' . a:id, '')
|
||||
call extend(s:branch_info[pwd], {
|
||||
\ 'last_update_done' : localtime(),
|
||||
\ })
|
||||
endfunction
|
||||
|
||||
function! git#branch#current() abort
|
||||
let pwd = getcwd()
|
||||
let branch = get(s:branch_info, pwd, {})
|
||||
|
Loading…
Reference in New Issue
Block a user