mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 11:33:48 -05:00
Move #init_buffer() into #process_buffer().
This commit is contained in:
@@ -10,7 +10,6 @@ function! gitgutter#all(force) abort
|
||||
let file = expand('#'.bufnr.':p')
|
||||
if !empty(file)
|
||||
if index(visible, bufnr) != -1
|
||||
call gitgutter#init_buffer(bufnr)
|
||||
call gitgutter#process_buffer(bufnr, a:force)
|
||||
elseif a:force
|
||||
call s:reset_tick(bufnr)
|
||||
@@ -21,22 +20,22 @@ function! gitgutter#all(force) abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Finds the file's path relative to the repo root.
|
||||
function! gitgutter#init_buffer(bufnr)
|
||||
if gitgutter#utility#is_active(a:bufnr)
|
||||
let p = gitgutter#utility#repo_path(a:bufnr, 0)
|
||||
if type(p) != s:t_string || empty(p)
|
||||
call gitgutter#utility#set_repo_path(a:bufnr)
|
||||
call s:setup_maps()
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
function! gitgutter#process_buffer(bufnr, force) abort
|
||||
" NOTE a:bufnr is not necessarily the current buffer.
|
||||
|
||||
if gitgutter#utility#is_active(a:bufnr)
|
||||
|
||||
let p = gitgutter#utility#repo_path(a:bufnr, 0)
|
||||
if type(p) != s:t_string || empty(p)
|
||||
call s:setup_maps()
|
||||
|
||||
let Continuation = function('gitgutter#process_buffer', [a:bufnr, a:force])
|
||||
let ret = gitgutter#utility#set_repo_path(a:bufnr, Continuation)
|
||||
if ret ==# 'async'
|
||||
return
|
||||
endif
|
||||
endif
|
||||
|
||||
if a:force || s:has_fresh_changes(a:bufnr)
|
||||
|
||||
let diff = ''
|
||||
|
||||
@@ -68,9 +68,9 @@ let s:counter = 0
|
||||
" the hunk headers (@@ -x,y +m,n @@); only possible if
|
||||
" grep is available.
|
||||
function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
|
||||
while gitgutter#utility#repo_path(a:bufnr, 0) == -1
|
||||
sleep 5m
|
||||
endwhile
|
||||
if gitgutter#utility#repo_path(a:bufnr, 0) == -1
|
||||
throw 'gitgutter author fail'
|
||||
endif
|
||||
|
||||
if gitgutter#utility#repo_path(a:bufnr, 0) == -2
|
||||
throw 'gitgutter not tracked'
|
||||
|
||||
@@ -120,6 +120,8 @@ let s:set_path_handler = {}
|
||||
function! s:set_path_handler.out(buffer, path) abort
|
||||
let path = s:strip_trailing_new_line(a:path)
|
||||
call gitgutter#utility#setbufvar(a:buffer, 'path', path)
|
||||
|
||||
call self.continuation()
|
||||
endfunction
|
||||
|
||||
function! s:set_path_handler.err(buffer) abort
|
||||
@@ -127,7 +129,8 @@ function! s:set_path_handler.err(buffer) abort
|
||||
endfunction
|
||||
|
||||
|
||||
function! gitgutter#utility#set_repo_path(bufnr) abort
|
||||
" continuation - a funcref to call after setting the repo path asynchronously.
|
||||
function! gitgutter#utility#set_repo_path(bufnr, continuation) abort
|
||||
" Values of path:
|
||||
" * non-empty string - path
|
||||
" * -1 - pending
|
||||
@@ -138,14 +141,16 @@ function! gitgutter#utility#set_repo_path(bufnr) abort
|
||||
|
||||
if g:gitgutter_async && gitgutter#async#available()
|
||||
let handler = copy(s:set_path_handler)
|
||||
let handler.continuation = a:continuation
|
||||
call gitgutter#async#execute(cmd, a:bufnr, handler)
|
||||
return 'async'
|
||||
endif
|
||||
|
||||
let path = gitgutter#utility#system(cmd)
|
||||
if v:shell_error
|
||||
call gitgutter#utility#setbufvar(a:bufnr, 'path', -2)
|
||||
else
|
||||
let path = gitgutter#utility#system(cmd)
|
||||
if v:shell_error
|
||||
call gitgutter#utility#setbufvar(a:bufnr, 'path', -2)
|
||||
else
|
||||
call gitgutter#utility#setbufvar(a:bufnr, 'path', s:strip_trailing_new_line(path))
|
||||
endif
|
||||
call gitgutter#utility#setbufvar(a:bufnr, 'path', s:strip_trailing_new_line(path))
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -190,7 +190,6 @@ function! s:on_bufenter()
|
||||
let t:gitgutter_didtabenter = 0
|
||||
call gitgutter#all(!g:gitgutter_terminal_reports_focus)
|
||||
else
|
||||
call gitgutter#init_buffer(bufnr(''))
|
||||
call gitgutter#process_buffer(bufnr(''), !g:gitgutter_terminal_reports_focus)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user