Avoid running detection more than once
Before this change, it was possible that a buffer was disabled, when Sy was run more than once at startup, e.g. because of `BufEnter` and `FocusGained`. The first call would start the detection and the second call would disable the buffer, because the first call hadn't changed the VCS type from "unknown" yet.
This commit is contained in:
parent
0a65a0c504
commit
9d0947952e
@ -38,6 +38,7 @@ function! sy#start() abort
|
||||
\ 'path' : sy_path,
|
||||
\ 'buffer': bufnr(''),
|
||||
\ 'active': 0,
|
||||
\ 'detecting': 0,
|
||||
\ 'vcs' : 'unknown',
|
||||
\ 'hunks' : [],
|
||||
\ 'signid': 0x100,
|
||||
@ -59,10 +60,14 @@ function! sy#start() abort
|
||||
let b:sy.retry = 0
|
||||
call sy#verbose('Redetecting VCS.')
|
||||
call sy#repo#detect(1)
|
||||
else
|
||||
if get(b:sy, 'detecting')
|
||||
call sy#verbose('Detection is already in progress.')
|
||||
else
|
||||
call sy#verbose('No VCS found. Disabling.')
|
||||
call sy#disable()
|
||||
endif
|
||||
endif
|
||||
else
|
||||
let job_id = get(b:, 'sy_job_id_'.b:sy.vcs)
|
||||
if type(job_id) != type(0) || job_id > 0
|
||||
|
@ -16,6 +16,7 @@ function! sy#repo#detect(do_register) abort
|
||||
endif
|
||||
|
||||
for vcs in vcs_list
|
||||
let b:sy.detecting += 1
|
||||
call sy#repo#get_diff_start(vcs, a:do_register)
|
||||
endfor
|
||||
endfunction
|
||||
@ -61,6 +62,8 @@ function! s:job_exit(bufnr, vcs, exitval, diff, do_register) abort
|
||||
if empty(sy)
|
||||
call sy#verbose(printf('No b:sy found for %s', bufname(a:bufnr)), a:vcs)
|
||||
return
|
||||
elseif sy.vcs == 'unknown' && sy.active
|
||||
let sy.detecting -= 1
|
||||
endif
|
||||
call sy#repo#get_diff_{a:vcs}(sy, a:exitval, a:diff, a:do_register)
|
||||
call setbufvar(a:bufnr, 'sy_job_id_'.a:vcs, 0)
|
||||
|
Loading…
Reference in New Issue
Block a user