mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-13 05:43:52 -05:00
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.
This commit is contained in:
@@ -926,6 +926,24 @@ function! s:ConfigTimestamps(dir, dict) abort
|
|||||||
return join(map(files, 'getftime(expand(v:val))'), ',')
|
return join(map(files, 'getftime(expand(v:val))'), ',')
|
||||||
endfunction
|
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_prototype = {}
|
||||||
|
|
||||||
let s:config = {}
|
let s:config = {}
|
||||||
@@ -959,38 +977,25 @@ function! fugitive#Config(...) abort
|
|||||||
let dir = s:Dir()
|
let dir = s:Dir()
|
||||||
endif
|
endif
|
||||||
let name = substitute(name, '^[^.]\+\|[^.]\+$', '\L&', 'g')
|
let name = substitute(name, '^[^.]\+\|[^.]\+$', '\L&', 'g')
|
||||||
let dir_key = len(dir) ? dir : '_'
|
let git_dir = s:GitDir(dir)
|
||||||
if has_key(s:config, dir_key) && s:config[dir_key][0] ==# s:ConfigTimestamps(dir, s:config[dir_key][1])
|
let dir_key = len(git_dir) ? git_dir : '_'
|
||||||
let dict = s:config[dir_key][1]
|
let [ts, dict] = get(s:config, dir_key, ['new', {}])
|
||||||
else
|
if ts !=# s:ConfigTimestamps(git_dir, dict)
|
||||||
let dict = copy(s:config_prototype)
|
let dict = copy(s:config_prototype)
|
||||||
let dict.git_dir = s:GitDir(dir)
|
let dict.git_dir = git_dir
|
||||||
let [lines, message, exec_error] = s:NullError([dir, 'config', '--list', '-z', '--'])
|
let into = ['running', dict]
|
||||||
if exec_error
|
let exec = fugitive#Execute([dir, 'config', '--list', '-z', '--'], function('s:ConfigCallback'), into)
|
||||||
return {}
|
call fugitive#Wait(exec)
|
||||||
endif
|
let s:config[dir_key] = into
|
||||||
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
|
|
||||||
endif
|
endif
|
||||||
if exists('callback')
|
if exists('callback')
|
||||||
call call(callback[0], [dict] + callback[1:-1])
|
call call(callback[0], [dict] + callback[1:-1])
|
||||||
endif
|
endif
|
||||||
return len(name) ? get(get(dict, name, []), 0, default) : dict
|
return len(name) ? get(fugitive#ConfigGetAll(name, dict), 0, default) : dict
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#ConfigGetAll(name, ...) abort
|
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 config = fugitive#Config(a:name)
|
||||||
let name = a:1
|
let name = a:1
|
||||||
else
|
else
|
||||||
@@ -998,7 +1003,7 @@ function! fugitive#ConfigGetAll(name, ...) abort
|
|||||||
let name = a:name
|
let name = a:name
|
||||||
endif
|
endif
|
||||||
let name = substitute(name, '^[^.]\+\|[^.]\+$', '\L&', 'g')
|
let name = substitute(name, '^[^.]\+\|[^.]\+$', '\L&', 'g')
|
||||||
return copy(get(config, name, []))
|
return name =~# '\.' ? copy(get(config, name, [])) : []
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#ConfigGetRegexp(pattern, ...) abort
|
function! fugitive#ConfigGetRegexp(pattern, ...) abort
|
||||||
@@ -1025,11 +1030,7 @@ endfunction
|
|||||||
|
|
||||||
function! s:config_GetAll(name) dict abort
|
function! s:config_GetAll(name) dict abort
|
||||||
let name = substitute(a:name, '^[^.]\+\|[^.]\+$', '\L&', 'g')
|
let name = substitute(a:name, '^[^.]\+\|[^.]\+$', '\L&', 'g')
|
||||||
if name =~# '\.'
|
return name =~# '\.' ? copy(get(self, name, [])) : []
|
||||||
return get(self, name, [])
|
|
||||||
else
|
|
||||||
return []
|
|
||||||
endif
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:config_Get(name, ...) dict abort
|
function! s:config_Get(name, ...) dict abort
|
||||||
|
|||||||
Reference in New Issue
Block a user