Improve public API argument order flexibility

This commit is contained in:
Tim Pope
2021-08-22 22:04:59 -04:00
parent e7d2e87690
commit 557ef84c6d

View File

@@ -55,7 +55,11 @@ endfunction
" exists, call FooReal("foo://bar"). " exists, call FooReal("foo://bar").
function! FugitiveReal(...) abort function! FugitiveReal(...) abort
let file = a:0 ? a:1 : @% let file = a:0 ? a:1 : @%
if file =~# '^\a\a\+:' || a:0 > 1 if type(file) ==# type({})
let dir = FugitiveGitDir(file)
let tree = s:Tree(dir)
return FugitiveVimPath(empty(tree) ? dir : tree)
elseif file =~# '^\a\a\+:' || a:0 > 1
return call('fugitive#Real', [file] + a:000[1:-1]) return call('fugitive#Real', [file] + a:000[1:-1])
elseif file =~# '^/\|^\a:\|^$' elseif file =~# '^/\|^\a:\|^$'
return file return file
@@ -72,7 +76,7 @@ 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({}) if a:0 && (type(a:1) ==# type({}) || type(a:1) ==# type(0))
return call('fugitive#Find', a:000[1:-1] + [FugitiveGitDir(a:1)]) return call('fugitive#Find', a:000[1:-1] + [FugitiveGitDir(a:1)])
else 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))
@@ -181,7 +185,7 @@ 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
if a:0 && type(a:1) ==# type({}) if a:0 && (type(a:1) ==# type({}) || type(a:1) ==# type('') && a:1 !~# '^\d\+$')
let dir = FugitiveGitDir(a:1) let dir = FugitiveGitDir(a:1)
let arg = get(a:, 2, 0) let arg = get(a:, 2, 0)
elseif a:0 > 1 elseif a:0 > 1