From 064a3d6b10622f6fabe524ef3183668732f9fd06 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Wed, 29 May 2019 13:46:33 +0100 Subject: [PATCH] Move #init_buffer() into #process_buffer(). --- autoload/gitgutter.vim | 25 ++++++++++++------------- autoload/gitgutter/diff.vim | 6 +++--- autoload/gitgutter/utility.vim | 19 ++++++++++++------- plugin/gitgutter.vim | 1 - 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/autoload/gitgutter.vim b/autoload/gitgutter.vim index 2e17fdb..7a7890f 100644 --- a/autoload/gitgutter.vim +++ b/autoload/gitgutter.vim @@ -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 = '' diff --git a/autoload/gitgutter/diff.vim b/autoload/gitgutter/diff.vim index b270db7..1965ecc 100644 --- a/autoload/gitgutter/diff.vim +++ b/autoload/gitgutter/diff.vim @@ -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' diff --git a/autoload/gitgutter/utility.vim b/autoload/gitgutter/utility.vim index 049c364..6f13181 100644 --- a/autoload/gitgutter/utility.vim +++ b/autoload/gitgutter/utility.vim @@ -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 diff --git a/plugin/gitgutter.vim b/plugin/gitgutter.vim index 9ca45af..1bb27a1 100644 --- a/plugin/gitgutter.vim +++ b/plugin/gitgutter.vim @@ -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