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:
Marco Hinz 2017-02-24 17:16:09 +01:00
parent 0a65a0c504
commit 9d0947952e
No known key found for this signature in database
GPG Key ID: 1C980A1B657B4A4F
2 changed files with 17 additions and 9 deletions

View File

@ -35,13 +35,14 @@ function! sy#start() abort
if !exists('b:sy') || b:sy.path != sy_path
call sy#verbose('Register new file.')
let b:sy = {
\ 'path' : sy_path,
\ 'buffer': bufnr(''),
\ 'active': 0,
\ 'vcs' : 'unknown',
\ 'hunks' : [],
\ 'signid': 0x100,
\ 'stats' : [-1, -1, -1] }
\ 'path' : sy_path,
\ 'buffer': bufnr(''),
\ 'active': 0,
\ 'detecting': 0,
\ 'vcs' : 'unknown',
\ 'hunks' : [],
\ 'signid': 0x100,
\ 'stats' : [-1, -1, -1] }
if get(g:, 'signify_disable_by_default')
call sy#verbose('Disabled by default.')
return
@ -60,8 +61,12 @@ function! sy#start() abort
call sy#verbose('Redetecting VCS.')
call sy#repo#detect(1)
else
call sy#verbose('No VCS found. Disabling.')
call sy#disable()
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)

View File

@ -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)