mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-12 21:33:53 -05:00
Improve flexibility of public API argument order
This allows tomfoolery like FugitiveConfig(dir)->FugitiveConfigGet(key). I'm not sure I want to officially endorse this usage, but if nothing else it makes interactive debugging a bit more fluid.
This commit is contained in:
@@ -420,11 +420,16 @@ function! fugitive#PrepareDirEnvGitArgv(...) abort
|
|||||||
throw 'fugitive: Git 1.8.5 or higher required'
|
throw 'fugitive: Git 1.8.5 or higher required'
|
||||||
endif
|
endif
|
||||||
let git = s:GitCmd()
|
let git = s:GitCmd()
|
||||||
if a:0 && type(a:1) ==# type([])
|
let list_args = []
|
||||||
let cmd = a:000[1:-1] + a:1
|
let cmd = []
|
||||||
|
for arg in a:000
|
||||||
|
if type(arg) ==# type([])
|
||||||
|
call extend(list_args, arg)
|
||||||
else
|
else
|
||||||
let cmd = copy(a:000)
|
call add(cmd, arg)
|
||||||
endif
|
endif
|
||||||
|
endfor
|
||||||
|
call extend(cmd, list_args)
|
||||||
let env = {}
|
let env = {}
|
||||||
let i = 0
|
let i = 0
|
||||||
while i < len(cmd)
|
while i < len(cmd)
|
||||||
@@ -675,7 +680,7 @@ function! fugitive#Config(...) abort
|
|||||||
let name = ''
|
let name = ''
|
||||||
let default = get(a:, 3, '')
|
let default = get(a:, 3, '')
|
||||||
if a:0 >= 2 && type(a:2) == type({}) && has_key(a:2, 'GetAll')
|
if a:0 >= 2 && type(a:2) == type({}) && has_key(a:2, 'GetAll')
|
||||||
return fugitive#ConfigGetAll(a:1, a:2)
|
return get(fugitive#ConfigGetAll(a:1, a:2), 0, default)
|
||||||
elseif a:0 >= 2
|
elseif a:0 >= 2
|
||||||
let dir = s:Dir(a:2)
|
let dir = s:Dir(a:2)
|
||||||
let name = a:1
|
let name = a:1
|
||||||
@@ -718,20 +723,32 @@ function! fugitive#Config(...) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#ConfigGetAll(name, ...) abort
|
function! fugitive#ConfigGetAll(name, ...) abort
|
||||||
|
if type(a:name) !=# type('') && a:0
|
||||||
|
let config = fugitive#Config(a:0)
|
||||||
|
let name = a:1
|
||||||
|
else
|
||||||
let config = fugitive#Config(a:0 ? a:1 : s:Dir())
|
let config = fugitive#Config(a:0 ? a:1 : s:Dir())
|
||||||
let name = substitute(a:name, '^[^.]\+\|[^.]\+$', '\L&', 'g')
|
let name = a:name
|
||||||
|
endif
|
||||||
|
let name = substitute(name, '^[^.]\+\|[^.]\+$', '\L&', 'g')
|
||||||
return copy(get(config, name, []))
|
return copy(get(config, name, []))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#ConfigGetRegexp(pattern, ...) abort
|
function! fugitive#ConfigGetRegexp(pattern, ...) abort
|
||||||
|
if type(a:pattern) !=# type('') && a:0
|
||||||
|
let config = fugitive#Config(a:0)
|
||||||
|
let pattern = a:1
|
||||||
|
else
|
||||||
let config = fugitive#Config(a:0 ? a:1 : s:Dir())
|
let config = fugitive#Config(a:0 ? a:1 : s:Dir())
|
||||||
let filtered = map(filter(copy(config), 'v:key =~# "\\." && v:key =~# a:pattern'), 'copy(v:val)')
|
let pattern = a:pattern
|
||||||
if a:pattern !~# '\\\@<!\%(\\\\\)*\\z[se]'
|
endif
|
||||||
|
let filtered = map(filter(copy(config), 'v:key =~# "\\." && v:key =~# pattern'), 'copy(v:val)')
|
||||||
|
if pattern !~# '\\\@<!\%(\\\\\)*\\z[se]'
|
||||||
return filtered
|
return filtered
|
||||||
endif
|
endif
|
||||||
let transformed = {}
|
let transformed = {}
|
||||||
for [k, v] in items(filtered)
|
for [k, v] in items(filtered)
|
||||||
let k = matchstr(k, a:pattern)
|
let k = matchstr(k, pattern)
|
||||||
if len(k)
|
if len(k)
|
||||||
let transformed[k] = v
|
let transformed[k] = v
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -72,11 +72,19 @@ endfunction
|
|||||||
" An optional second argument provides the Git dir, or the buffer number of a
|
" An optional second argument provides the Git dir, or the buffer number of a
|
||||||
" buffer with a Git dir. The default is the current buffer.
|
" buffer with a Git dir. The default is the current buffer.
|
||||||
function! FugitiveFind(...) abort
|
function! FugitiveFind(...) abort
|
||||||
|
if a:0 && type(a:1) ==# type({})
|
||||||
|
return call('fugitive#Find', a:000[1:-1] + [FugitiveGitDir(a:1)])
|
||||||
|
else
|
||||||
return fugitive#Find(a:0 ? a:1 : bufnr(''), FugitiveGitDir(a:0 > 1 ? a:2 : -1))
|
return fugitive#Find(a:0 ? a:1 : bufnr(''), FugitiveGitDir(a:0 > 1 ? a:2 : -1))
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! FugitivePath(...) abort
|
function! FugitivePath(...) abort
|
||||||
if a:0 > 1
|
if a:0 > 2 && type(a:1) ==# type({})
|
||||||
|
return fugitive#Path(a:2, a:3, FugitiveGitDir(a:1))
|
||||||
|
elseif a:0 && type(a:1) ==# type({})
|
||||||
|
return FugitiveReal(a:0 > 1 ? a:2 : @%)
|
||||||
|
elseif a:0 > 1
|
||||||
return fugitive#Path(a:1, a:2, FugitiveGitDir(a:0 > 2 ? a:3 : -1))
|
return fugitive#Path(a:1, a:2, FugitiveGitDir(a:0 > 2 ? a:3 : -1))
|
||||||
else
|
else
|
||||||
return FugitiveReal(a:0 ? a:1 : @%)
|
return FugitiveReal(a:0 ? a:1 : @%)
|
||||||
@@ -182,11 +190,20 @@ endfunction
|
|||||||
" An optional second argument provides the Git dir, or the buffer number of a
|
" An optional second argument provides the Git dir, or the buffer number of a
|
||||||
" buffer with a Git dir. The default is the current buffer.
|
" buffer with a Git dir. The default is the current buffer.
|
||||||
function! FugitiveHead(...) abort
|
function! FugitiveHead(...) abort
|
||||||
let dir = FugitiveGitDir(a:0 > 1 ? a:2 : -1)
|
if a:0 && type(a:1) ==# type({})
|
||||||
|
let dir = FugitiveGitDir(a:1)
|
||||||
|
let arg = get(a:, 2, 0)
|
||||||
|
elseif a:0 > 1
|
||||||
|
let dir = FugitiveGitDir(a:2)
|
||||||
|
let arg = a:1
|
||||||
|
else
|
||||||
|
let dir = FugitiveGitDir()
|
||||||
|
let args = get(a:, 1, 0)
|
||||||
|
endif
|
||||||
if empty(dir)
|
if empty(dir)
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
return fugitive#Head(a:0 ? a:1 : 0, dir)
|
return fugitive#Head(arg, dir)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! FugitiveStatusline(...) abort
|
function! FugitiveStatusline(...) abort
|
||||||
|
|||||||
Reference in New Issue
Block a user