mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-12 13:23:52 -05:00
Make FugitiveConfig(callback) asynchronous
This commit is contained in:
@@ -928,6 +928,9 @@ endfunction
|
|||||||
|
|
||||||
function! s:ConfigCallback(r, into) abort
|
function! s:ConfigCallback(r, into) abort
|
||||||
let dict = a:into[1]
|
let dict = a:into[1]
|
||||||
|
if has_key(dict, 'job')
|
||||||
|
call remove(dict, 'job')
|
||||||
|
endif
|
||||||
let lines = a:r.exit_status ? [] : split(tr(join(a:r.stdout, "\1"), "\1\n", "\n\1"), "\1", 1)[0:-2]
|
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
|
for line in lines
|
||||||
let key = matchstr(line, "^[^\n]*")
|
let key = matchstr(line, "^[^\n]*")
|
||||||
@@ -940,8 +943,12 @@ function! s:ConfigCallback(r, into) abort
|
|||||||
call add(dict[key], strpart(line, len(key) + 1))
|
call add(dict[key], strpart(line, len(key) + 1))
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
let callbacks = remove(dict, 'callbacks')
|
||||||
lockvar! dict
|
lockvar! dict
|
||||||
let a:into[0] = s:ConfigTimestamps(dict.git_dir, dict)
|
let a:into[0] = s:ConfigTimestamps(dict.git_dir, dict)
|
||||||
|
for callback in callbacks
|
||||||
|
call call(callback[0], [dict] + callback[1:-1])
|
||||||
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let s:config_prototype = {}
|
let s:config_prototype = {}
|
||||||
@@ -955,7 +962,11 @@ function! fugitive#Config(...) abort
|
|||||||
let callback = a:000
|
let callback = a:000
|
||||||
elseif a:0 > 1 && type(a:2) == type(function('tr'))
|
elseif a:0 > 1 && type(a:2) == type(function('tr'))
|
||||||
if type(a:1) == type({}) && has_key(a:1, 'GetAll')
|
if type(a:1) == type({}) && has_key(a:1, 'GetAll')
|
||||||
call call(a:2, [a:1] + a:000[2:-1])
|
if has_key(a:1, 'callbacks')
|
||||||
|
call add(a:1.callbacks, a:000[1:-1])
|
||||||
|
else
|
||||||
|
call call(a:2, [a:1] + a:000[2:-1])
|
||||||
|
endif
|
||||||
return a:1
|
return a:1
|
||||||
else
|
else
|
||||||
let dir = s:Dir(a:1)
|
let dir = s:Dir(a:1)
|
||||||
@@ -980,15 +991,22 @@ function! fugitive#Config(...) abort
|
|||||||
let git_dir = s:GitDir(dir)
|
let git_dir = s:GitDir(dir)
|
||||||
let dir_key = len(git_dir) ? git_dir : '_'
|
let dir_key = len(git_dir) ? git_dir : '_'
|
||||||
let [ts, dict] = get(s:config, dir_key, ['new', {}])
|
let [ts, dict] = get(s:config, dir_key, ['new', {}])
|
||||||
if ts !=# s:ConfigTimestamps(git_dir, dict)
|
if !has_key(dict, 'job') && ts !=# s:ConfigTimestamps(git_dir, dict)
|
||||||
let dict = copy(s:config_prototype)
|
let dict = copy(s:config_prototype)
|
||||||
let dict.git_dir = git_dir
|
let dict.git_dir = git_dir
|
||||||
let into = ['running', dict]
|
let into = ['running', dict]
|
||||||
|
let dict.callbacks = []
|
||||||
let exec = fugitive#Execute([dir, 'config', '--list', '-z', '--'], function('s:ConfigCallback'), into)
|
let exec = fugitive#Execute([dir, 'config', '--list', '-z', '--'], function('s:ConfigCallback'), into)
|
||||||
call fugitive#Wait(exec)
|
if has_key(exec, 'job')
|
||||||
|
let dict.job = exec.job
|
||||||
|
endif
|
||||||
let s:config[dir_key] = into
|
let s:config[dir_key] = into
|
||||||
endif
|
endif
|
||||||
if exists('callback')
|
if !exists('l:callback')
|
||||||
|
call fugitive#Wait(dict)
|
||||||
|
elseif has_key(dict, 'callbacks')
|
||||||
|
call add(dict.callbacks, callback)
|
||||||
|
else
|
||||||
call call(callback[0], [dict] + callback[1:-1])
|
call call(callback[0], [dict] + callback[1:-1])
|
||||||
endif
|
endif
|
||||||
return len(name) ? get(fugitive#ConfigGetAll(name, dict), 0, default) : dict
|
return len(name) ? get(fugitive#ConfigGetAll(name, dict), 0, default) : dict
|
||||||
@@ -1003,6 +1021,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')
|
||||||
|
call fugitive#Wait(config)
|
||||||
return name =~# '\.' ? copy(get(config, name, [])) : []
|
return name =~# '\.' ? copy(get(config, name, [])) : []
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -1014,6 +1033,7 @@ function! fugitive#ConfigGetRegexp(pattern, ...) abort
|
|||||||
let config = fugitive#Config(a:0 ? a:1 : s:Dir())
|
let config = fugitive#Config(a:0 ? a:1 : s:Dir())
|
||||||
let pattern = a:pattern
|
let pattern = a:pattern
|
||||||
endif
|
endif
|
||||||
|
call fugitive#Wait(config)
|
||||||
let filtered = map(filter(copy(config), 'v:key =~# "\\." && v:key =~# pattern'), 'copy(v:val)')
|
let filtered = map(filter(copy(config), 'v:key =~# "\\." && v:key =~# pattern'), 'copy(v:val)')
|
||||||
if pattern !~# '\\\@<!\%(\\\\\)*\\z[se]'
|
if pattern !~# '\\\@<!\%(\\\\\)*\\z[se]'
|
||||||
return filtered
|
return filtered
|
||||||
@@ -1030,6 +1050,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')
|
||||||
|
call fugitive#Wait(self)
|
||||||
return name =~# '\.' ? copy(get(self, name, [])) : []
|
return name =~# '\.' ? copy(get(self, name, [])) : []
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user