commit 7c1f2ed185849c6888dc5ae15cf9eadb4d59cc99 (tree)
parent 8cdb51622fbdbf780edff35ee22d74ad9983698e
Author: Tim Pope <code@tpope.net>
Date: Tue, 24 Aug 2021 00:55:40 -0400
Move config --list parsing into Execute callback
This is 80% of the way to an asynchronous config retrieval. Do we
really want to make a 10 millisecond Git call asynchronous? Hard to
say.
Diffstat:
1 file changed, 31 insertions(+), 30 deletions(-)
diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim
@@ -926,6 +926,24 @@ function! s:ConfigTimestamps(dir, dict) abort
return join(map(files, 'getftime(expand(v:val))'), ',')
endfunction
+function! s:ConfigCallback(r, into) abort
+ let dict = a:into[1]
+ let lines = a:r.exit_status ? [] : split(tr(join(a:r.stdout, "\1"), "\1\n", "\n\1"), "\1", 1)[0:-2]
+ for line in lines
+ let key = matchstr(line, "^[^\n]*")
+ if !has_key(dict, key)
+ let dict[key] = []
+ endif
+ if len(key) ==# len(line)
+ call add(dict[key], 1)
+ else
+ call add(dict[key], strpart(line, len(key) + 1))
+ endif
+ endfor
+ lockvar! dict
+ let a:into[0] = s:ConfigTimestamps(dict.git_dir, dict)
+endfunction
+
let s:config_prototype = {}
let s:config = {}
@@ -959,38 +977,25 @@ function! fugitive#Config(...) abort
let dir = s:Dir()
endif
let name = substitute(name, '^[^.]\+\|[^.]\+$', '\L&', 'g')
- let dir_key = len(dir) ? dir : '_'
- if has_key(s:config, dir_key) && s:config[dir_key][0] ==# s:ConfigTimestamps(dir, s:config[dir_key][1])
- let dict = s:config[dir_key][1]
- else
+ let git_dir = s:GitDir(dir)
+ let dir_key = len(git_dir) ? git_dir : '_'
+ let [ts, dict] = get(s:config, dir_key, ['new', {}])
+ if ts !=# s:ConfigTimestamps(git_dir, dict)
let dict = copy(s:config_prototype)
- let dict.git_dir = s:GitDir(dir)
- let [lines, message, exec_error] = s:NullError([dir, 'config', '--list', '-z', '--'])
- if exec_error
- return {}
- endif
- for line in lines
- let key = matchstr(line, "^[^\n]*")
- if !has_key(dict, key)
- let dict[key] = []
- endif
- if len(key) ==# len(line)
- call add(dict[key], 1)
- else
- call add(dict[key], strpart(line, len(key) + 1))
- endif
- endfor
- let s:config[dir_key] = [s:ConfigTimestamps(dir, dict), dict]
- lockvar! dict
+ let dict.git_dir = git_dir
+ let into = ['running', dict]
+ let exec = fugitive#Execute([dir, 'config', '--list', '-z', '--'], function('s:ConfigCallback'), into)
+ call fugitive#Wait(exec)
+ let s:config[dir_key] = into
endif
if exists('callback')
call call(callback[0], [dict] + callback[1:-1])
endif
- return len(name) ? get(get(dict, name, []), 0, default) : dict
+ return len(name) ? get(fugitive#ConfigGetAll(name, dict), 0, default) : dict
endfunction
function! fugitive#ConfigGetAll(name, ...) abort
- if a:0 && (type(a:name) !=# type('') || (a:name !~# '^[[:alnum:]-]\+\.' && a:1 =~# '^[[:alnum:]-]\+\.'))
+ if a:0 && (type(a:name) !=# type('') || a:name !~# '^[[:alnum:]-]\+\.' && type(a:1) ==# type('') && a:1 =~# '^[[:alnum:]-]\+\.')
let config = fugitive#Config(a:name)
let name = a:1
else
@@ -998,7 +1003,7 @@ function! fugitive#ConfigGetAll(name, ...) abort
let name = a:name
endif
let name = substitute(name, '^[^.]\+\|[^.]\+$', '\L&', 'g')
- return copy(get(config, name, []))
+ return name =~# '\.' ? copy(get(config, name, [])) : []
endfunction
function! fugitive#ConfigGetRegexp(pattern, ...) abort
@@ -1025,11 +1030,7 @@ endfunction
function! s:config_GetAll(name) dict abort
let name = substitute(a:name, '^[^.]\+\|[^.]\+$', '\L&', 'g')
- if name =~# '\.'
- return get(self, name, [])
- else
- return []
- endif
+ return name =~# '\.' ? copy(get(self, name, [])) : []
endfunction
function! s:config_Get(name, ...) dict abort