From 222b1a2fdeea6bc6f9d1949f5d2e4479de7c570e Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Wed, 29 May 2019 14:32:16 +0100 Subject: [PATCH] Extract setting of path. --- autoload/gitgutter.vim | 17 ++++++++++------- autoload/gitgutter/utility.vim | 2 ++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/autoload/gitgutter.vim b/autoload/gitgutter.vim index 187bd32..b138c1f 100644 --- a/autoload/gitgutter.vim +++ b/autoload/gitgutter.vim @@ -27,13 +27,9 @@ function! gitgutter#process_buffer(bufnr, force) abort call s:setup_maps(a:bufnr) - let p = gitgutter#utility#repo_path(a:bufnr, 0) - if type(p) != s:t_string || empty(p) - 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 + let how = s:setup_path(a:bufnr, function('gitgutter#process_buffer', [a:bufnr, a:force])) + if [how] == ['async'] " avoid string-to-number conversion if how is a number + return endif if a:force || s:has_fresh_changes(a:bufnr) @@ -149,6 +145,13 @@ function! s:setup_maps(bufnr) call gitgutter#utility#setbufvar(a:bufnr, 'mapped', 1) endfunction +function! s:setup_path(bufnr, continuation) + let p = gitgutter#utility#repo_path(a:bufnr, 0) + if type(p) != s:t_string || empty(p) + return gitgutter#utility#set_repo_path(a:bufnr, a:continuation) + endif +endfunction + function! s:has_fresh_changes(bufnr) abort return getbufvar(a:bufnr, 'changedtick') != gitgutter#utility#getbufvar(a:bufnr, 'tick') endfunction diff --git a/autoload/gitgutter/utility.vim b/autoload/gitgutter/utility.vim index 6f13181..424b3eb 100644 --- a/autoload/gitgutter/utility.vim +++ b/autoload/gitgutter/utility.vim @@ -130,6 +130,8 @@ endfunction " continuation - a funcref to call after setting the repo path asynchronously. +" +" Returns 'async' if the the path is set asynchronously, 0 otherwise. function! gitgutter#utility#set_repo_path(bufnr, continuation) abort " Values of path: " * non-empty string - path