Switch out new and old official functions

This commit is contained in:
Tim Pope 2018-05-28 17:59:19 -04:00
parent b129752c07
commit 01e7a7e1e6
2 changed files with 71 additions and 63 deletions

View File

@ -346,16 +346,16 @@ HEAD^:Makefile The file named Makefile in the parent of HEAD
STATUSLINE *fugitive-statusline* STATUSLINE *fugitive-statusline*
*fugitive#statusline()* *FugitiveStatusline()* *fugitive#statusline()*
Add %{fugitive#statusline()} to your statusline to get an indicator including Add %{FugitiveStatusline()} to your statusline to get an indicator including
the current branch and the currently edited file's commit. If you don't have the current branch and the currently edited file's commit. If you don't have
a statusline, this one matches the default when 'ruler' is set: a statusline, this one matches the default when 'ruler' is set:
> >
set statusline=%<%f\ %h%m%r%{fugitive#statusline()}%=%-14.(%l,%c%V%)\ %P set statusline=%<%f\ %h%m%r%{FugitiveStatusline()}%=%-14.(%l,%c%V%)\ %P
< <
*fugitive#head(...)* *FugitiveHead(...)* *fugitive#head(...)*
Use fugitive#head() to return the name of the current branch. If the current Use FugitiveHead() to return the name of the current branch. If the current
HEAD is detached, fugitive#head() will return the empty string, unless the HEAD is detached, FugitiveHead() will return the empty string, unless the
optional argument is given, in which case the hash of the current commit will optional argument is given, in which case the hash of the current commit will
be truncated to the given number of characters. be truncated to the given number of characters.

View File

@ -153,18 +153,18 @@ let s:abstract_prototype = {}
" Section: Initialization " Section: Initialization
function! fugitive#is_git_dir(path) abort function! FugitiveIsGitDir(path) abort
let path = s:sub(a:path, '[\/]$', '') . '/' let path = s:sub(a:path, '[\/]$', '') . '/'
return getfsize(path.'HEAD') > 10 && ( return getfsize(path.'HEAD') > 10 && (
\ isdirectory(path.'objects') && isdirectory(path.'refs') || \ isdirectory(path.'objects') && isdirectory(path.'refs') ||
\ getftype(path.'commondir') ==# 'file') \ getftype(path.'commondir') ==# 'file')
endfunction endfunction
function! FugitiveIsGitDir(path) abort function! fugitive#is_git_dir(path) abort
return fugitive#is_git_dir(a:path) return FugitiveIsGitDir(a:path)
endfunction endfunction
function! fugitive#extract_git_dir(path) abort function! FugitiveExtractGitDir(path) abort
if s:shellslash(a:path) =~# '^fugitive://.*//' if s:shellslash(a:path) =~# '^fugitive://.*//'
return matchstr(s:shellslash(a:path), '\C^fugitive://\zs.\{-\}\ze//') return matchstr(s:shellslash(a:path), '\C^fugitive://\zs.\{-\}\ze//')
endif endif
@ -185,10 +185,10 @@ function! fugitive#extract_git_dir(path) abort
if index(split($GIT_CEILING_DIRECTORIES, ':'), root) >= 0 if index(split($GIT_CEILING_DIRECTORIES, ':'), root) >= 0
break break
endif endif
if root ==# $GIT_WORK_TREE && fugitive#is_git_dir($GIT_DIR) if root ==# $GIT_WORK_TREE && FugitiveIsGitDir($GIT_DIR)
return simplify(fnamemodify(expand($GIT_DIR), ':p:s?[\/]$??')) return simplify(fnamemodify(expand($GIT_DIR), ':p:s?[\/]$??'))
endif endif
if fugitive#is_git_dir($GIT_DIR) if FugitiveIsGitDir($GIT_DIR)
" Ensure that we've cached the worktree " Ensure that we've cached the worktree
call s:configured_tree(simplify(fnamemodify(expand($GIT_DIR), ':p:s?[\/]$??'))) call s:configured_tree(simplify(fnamemodify(expand($GIT_DIR), ':p:s?[\/]$??')))
if has_key(s:dir_for_worktree, root) if has_key(s:dir_for_worktree, root)
@ -197,18 +197,18 @@ function! fugitive#extract_git_dir(path) abort
endif endif
let dir = s:sub(root, '[\/]$', '') . '/.git' let dir = s:sub(root, '[\/]$', '') . '/.git'
let type = getftype(dir) let type = getftype(dir)
if type ==# 'dir' && fugitive#is_git_dir(dir) if type ==# 'dir' && FugitiveIsGitDir(dir)
return dir return dir
elseif type ==# 'link' && fugitive#is_git_dir(dir) elseif type ==# 'link' && FugitiveIsGitDir(dir)
return resolve(dir) return resolve(dir)
elseif type !=# '' && filereadable(dir) elseif type !=# '' && filereadable(dir)
let line = get(readfile(dir, '', 1), 0, '') let line = get(readfile(dir, '', 1), 0, '')
if line =~# '^gitdir: \.' && fugitive#is_git_dir(root.'/'.line[8:-1]) if line =~# '^gitdir: \.' && FugitiveIsGitDir(root.'/'.line[8:-1])
return simplify(root.'/'.line[8:-1]) return simplify(root.'/'.line[8:-1])
elseif line =~# '^gitdir: ' && fugitive#is_git_dir(line[8:-1]) elseif line =~# '^gitdir: ' && FugitiveIsGitDir(line[8:-1])
return line[8:-1] return line[8:-1]
endif endif
elseif fugitive#is_git_dir(root) elseif FugitiveIsGitDir(root)
return root return root
endif endif
let previous = root let previous = root
@ -217,16 +217,16 @@ function! fugitive#extract_git_dir(path) abort
return '' return ''
endfunction endfunction
function! FugitiveExtractGitDir(path) abort function! fugitive#extract_git_dir(path) abort
return fugitive#extract_git_dir(a:path) return FugitiveExtractGitDir(a:path)
endfunction endfunction
function! fugitive#detect(path) abort function! FugitiveDetect(path) abort
if exists('b:git_dir') && (b:git_dir ==# '' || b:git_dir =~# '/$') if exists('b:git_dir') && (b:git_dir ==# '' || b:git_dir =~# '/$')
unlet b:git_dir unlet b:git_dir
endif endif
if !exists('b:git_dir') if !exists('b:git_dir')
let dir = fugitive#extract_git_dir(a:path) let dir = FugitiveExtractGitDir(a:path)
if dir !=# '' if dir !=# ''
let b:git_dir = dir let b:git_dir = dir
if empty(fugitive#buffer().path()) if empty(fugitive#buffer().path())
@ -269,17 +269,17 @@ function! fugitive#detect(path) abort
endif endif
endfunction endfunction
function! FugitiveDetect(path) abort function! fugitive#detect(path) abort
return fugitive#detect(a:path) return FugitiveDetect(a:path)
endfunction endfunction
augroup fugitive augroup fugitive
autocmd! autocmd!
autocmd BufNewFile,BufReadPost * call fugitive#detect(expand('%:p')) autocmd BufNewFile,BufReadPost * call FugitiveDetect(expand('%:p'))
autocmd FileType netrw call fugitive#detect(expand('%:p')) autocmd FileType netrw call FugitiveDetect(expand('%:p'))
autocmd User NERDTreeInit,NERDTreeNewRoot call fugitive#detect(b:NERDTree.root.path.str()) autocmd User NERDTreeInit,NERDTreeNewRoot call FugitiveDetect(b:NERDTree.root.path.str())
autocmd VimEnter * if expand('<amatch>')==''|call fugitive#detect(getcwd())|endif autocmd VimEnter * if expand('<amatch>')==''|call FugitiveDetect(getcwd())|endif
autocmd CmdWinEnter * call fugitive#detect(expand('#:p')) autocmd CmdWinEnter * call FugitiveDetect(expand('#:p'))
autocmd BufWinLeave * execute getwinvar(+bufwinnr(+expand('<abuf>')), 'fugitive_leave') autocmd BufWinLeave * execute getwinvar(+bufwinnr(+expand('<abuf>')), 'fugitive_leave')
augroup END augroup END
@ -291,7 +291,7 @@ let s:worktree_for_dir = {}
let s:dir_for_worktree = {} let s:dir_for_worktree = {}
function! s:repo(...) abort function! s:repo(...) abort
let dir = a:0 ? a:1 : (exists('b:git_dir') && b:git_dir !=# '' ? b:git_dir : fugitive#extract_git_dir(expand('%:p'))) let dir = a:0 ? a:1 : (exists('b:git_dir') && b:git_dir !=# '' ? b:git_dir : FugitiveExtractGitDir(expand('%:p')))
if dir !=# '' if dir !=# ''
if has_key(s:repos, dir) if has_key(s:repos, dir)
let repo = get(s:repos, dir) let repo = get(s:repos, dir)
@ -774,7 +774,7 @@ function! s:Git(bang, mods, args) abort
else else
call s:ExecuteInTree('!'.git.' '.args) call s:ExecuteInTree('!'.git.' '.args)
if has('win32') if has('win32')
call fugitive#reload_status() call fugitive#ReloadStatus()
endif endif
endif endif
return matchstr(a:args, '\v\C\\@<!%(\\\\)*\|\zs.*') return matchstr(a:args, '\v\C\\@<!%(\\\\)*\|\zs.*')
@ -812,8 +812,8 @@ call s:command("-bar -bang -range=-1 Gstatus :execute s:Status(<bang>0, <count>,
augroup fugitive_status augroup fugitive_status
autocmd! autocmd!
if !has('win32') if !has('win32')
autocmd FocusGained,ShellCmdPost * call fugitive#reload_status() autocmd FocusGained,ShellCmdPost * call fugitive#ReloadStatus()
autocmd BufDelete term://* call fugitive#reload_status() autocmd BufDelete term://* call fugitive#ReloadStatus()
endif endif
augroup END augroup END
@ -829,7 +829,7 @@ function! s:Status(bang, count, mods) abort
return '' return ''
endfunction endfunction
function! fugitive#reload_status() abort function! fugitive#ReloadStatus() abort
if exists('s:reloading_status') if exists('s:reloading_status')
return return
endif endif
@ -862,8 +862,8 @@ function! fugitive#reload_status() abort
endtry endtry
endfunction endfunction
function! fugitive#ReloadStatus() abort function! fugitive#reload_status() abort
return fugitive#reload_status() return fugitive#ReloadStatus()
endfunction endfunction
function! s:stage_info(lnum) abort function! s:stage_info(lnum) abort
@ -1187,7 +1187,7 @@ function! s:Commit(mods, args, ...) abort
endif endif
call delete(outfile) call delete(outfile)
call delete(errorfile) call delete(errorfile)
call fugitive#reload_status() call fugitive#ReloadStatus()
endtry endtry
endfunction endfunction
@ -1305,7 +1305,7 @@ function! s:Merge(cmd, bang, args) abort
endif endif
execute cd fnameescape(cwd) execute cd fnameescape(cwd)
endtry endtry
call fugitive#reload_status() call fugitive#ReloadStatus()
if empty(filter(getqflist(),'v:val.valid')) if empty(filter(getqflist(),'v:val.valid'))
if !had_merge_msg && filereadable(s:repo().dir('MERGE_MSG')) if !had_merge_msg && filereadable(s:repo().dir('MERGE_MSG'))
cclose cclose
@ -1465,7 +1465,7 @@ function! s:Edit(cmd, bang, mods, ...) abort
if a:cmd ==# 'read' if a:cmd ==# 'read'
silent execute '1,'.last.'delete_' silent execute '1,'.last.'delete_'
endif endif
call fugitive#reload_status() call fugitive#ReloadStatus()
diffupdate diffupdate
return 'redraw|echo '.string(':!'.git.' '.args) return 'redraw|echo '.string(':!'.git.' '.args)
else else
@ -1681,7 +1681,7 @@ function! s:Write(force,...) abort
endif endif
endfor endfor
endfor endfor
call fugitive#reload_status() call fugitive#ReloadStatus()
return 'checktime' return 'checktime'
endfunction endfunction
@ -1954,7 +1954,7 @@ function! s:Move(force, rename, destination) abort
if isdirectory(destination) if isdirectory(destination)
let destination = fnamemodify(s:sub(destination,'/$','').'/'.expand('%:t'),':.') let destination = fnamemodify(s:sub(destination,'/$','').'/'.expand('%:t'),':.')
endif endif
call fugitive#reload_status() call fugitive#ReloadStatus()
if empty(s:buffer().commit()) if empty(s:buffer().commit())
if isdirectory(destination) if isdirectory(destination)
return 'keepalt edit '.s:fnameescape(destination) return 'keepalt edit '.s:fnameescape(destination)
@ -2002,7 +2002,7 @@ function! s:Remove(after, force) abort
let v:errmsg = 'fugitive: '.s:sub(message,'error:.*\zs\n\(.*-f.*',' (add ! to force)') let v:errmsg = 'fugitive: '.s:sub(message,'error:.*\zs\n\(.*-f.*',' (add ! to force)')
return 'echoerr '.string(v:errmsg) return 'echoerr '.string(v:errmsg)
else else
call fugitive#reload_status() call fugitive#ReloadStatus()
return a:after . (a:force ? '!' : '') return a:after . (a:force ? '!' : '')
endif endif
endfunction endfunction
@ -2621,7 +2621,7 @@ function! s:BufReadIndex() abort
execute cd s:fnameescape(dir) execute cd s:fnameescape(dir)
endtry endtry
set ft=gitcommit set ft=gitcommit
set foldtext=fugitive#foldtext() set foldtext=fugitive#Foldtext()
endif endif
setlocal ro noma nomod noswapfile setlocal ro noma nomod noswapfile
if &bufhidden ==# '' if &bufhidden ==# ''
@ -2667,7 +2667,7 @@ endfunction
function! s:FileRead() abort function! s:FileRead() abort
try try
let repo = s:repo(fugitive#extract_git_dir(expand('<amatch>'))) let repo = s:repo(FugitiveExtractGitDir(expand('<amatch>')))
let path = s:sub(s:sub(matchstr(expand('<amatch>'),'fugitive://.\{-\}//\zs.*'),'/',':'),'^\d:',':&') let path = s:sub(s:sub(matchstr(expand('<amatch>'),'fugitive://.\{-\}//\zs.*'),'/',':'),'^\d:',':&')
let hash = repo.rev_parse(path) let hash = repo.rev_parse(path)
if path =~ '^:' if path =~ '^:'
@ -2726,7 +2726,7 @@ function! s:BufWriteIndexFile() abort
if exists('#BufWritePost') if exists('#BufWritePost')
execute 'doautocmd BufWritePost '.s:fnameescape(expand('%:p')) execute 'doautocmd BufWritePost '.s:fnameescape(expand('%:p'))
endif endif
call fugitive#reload_status() call fugitive#ReloadStatus()
return '' return ''
else else
return 'echoerr '.string('fugitive: '.error) return 'echoerr '.string('fugitive: '.error)
@ -2823,7 +2823,7 @@ endfunction
augroup fugitive_files augroup fugitive_files
autocmd! autocmd!
autocmd BufReadCmd index{,.lock} autocmd BufReadCmd index{,.lock}
\ if fugitive#is_git_dir(expand('<amatch>:p:h')) | \ if FugitiveIsGitDir(expand('<amatch>:p:h')) |
\ exe s:BufReadIndex() | \ exe s:BufReadIndex() |
\ elseif filereadable(expand('<amatch>')) | \ elseif filereadable(expand('<amatch>')) |
\ read <amatch> | \ read <amatch> |
@ -2857,7 +2857,7 @@ augroup fugitive_temp
\ let b:git_dir = s:temp_files[s:cpath(expand('<afile>:p'))].dir | \ let b:git_dir = s:temp_files[s:cpath(expand('<afile>:p'))].dir |
\ let b:git_type = 'temp' | \ let b:git_type = 'temp' |
\ let b:git_args = s:temp_files[s:cpath(expand('<afile>:p'))].args | \ let b:git_args = s:temp_files[s:cpath(expand('<afile>:p'))].args |
\ call fugitive#detect(expand('<afile>:p')) | \ call FugitiveDetect(expand('<afile>:p')) |
\ setlocal bufhidden=delete nobuflisted | \ setlocal bufhidden=delete nobuflisted |
\ nnoremap <buffer> <silent> q :<C-U>bdelete<CR>| \ nnoremap <buffer> <silent> q :<C-U>bdelete<CR>|
\ endif \ endif
@ -2867,7 +2867,7 @@ augroup END
nnoremap <SID>: :<C-U><C-R>=v:count ? v:count : ''<CR> nnoremap <SID>: :<C-U><C-R>=v:count ? v:count : ''<CR>
function! s:GFInit(...) abort function! s:GFInit(...) abort
cnoremap <buffer> <expr> <Plug><cfile> fugitive#cfile() cnoremap <buffer> <expr> <Plug><cfile> fugitive#Cfile()
if !exists('g:fugitive_no_maps') if !exists('g:fugitive_no_maps')
call s:map('n', 'gf', '<SID>:find <Plug><cfile><CR>', '<silent><unique>') call s:map('n', 'gf', '<SID>:find <Plug><cfile><CR>', '<silent><unique>')
call s:map('n', '<C-W>f', '<SID>:sfind <Plug><cfile><CR>', '<silent><unique>') call s:map('n', '<C-W>f', '<SID>:sfind <Plug><cfile><CR>', '<silent><unique>')
@ -3089,7 +3089,7 @@ function! s:GF(mode) abort
endif endif
endfunction endfunction
function! fugitive#cfile() abort function! fugitive#Cfile() abort
let pre = '' let pre = ''
let results = s:cfile() let results = s:cfile()
if empty(results) if empty(results)
@ -3104,8 +3104,8 @@ function! fugitive#cfile() abort
return pre . s:fnameescape(fugitive#repo().translate(results[0])) return pre . s:fnameescape(fugitive#repo().translate(results[0]))
endfunction endfunction
function! fugitive#Cfile() abort function! fugitive#cfile() abort
return fugitive#cfile() return fugitive#Cfile()
endfunction endfunction
" Section: Statusline " Section: Statusline
@ -3119,7 +3119,7 @@ endfunction
call s:add_methods('repo',['head_ref']) call s:add_methods('repo',['head_ref'])
function! fugitive#statusline(...) abort function! fugitive#Statusline(...) abort
if !exists('b:git_dir') if !exists('b:git_dir')
return '' return ''
endif endif
@ -3127,7 +3127,7 @@ function! fugitive#statusline(...) abort
if s:buffer().commit() != '' if s:buffer().commit() != ''
let status .= ':' . s:buffer().commit()[0:7] let status .= ':' . s:buffer().commit()[0:7]
endif endif
let status .= '('.fugitive#head(7).')' let status .= '('.FugitiveHead(7).')'
if &statusline =~# '%[MRHWY]' && &statusline !~# '%[mrhwy]' if &statusline =~# '%[MRHWY]' && &statusline !~# '%[mrhwy]'
return ',GIT'.status return ',GIT'.status
else else
@ -3135,12 +3135,24 @@ function! fugitive#statusline(...) abort
endif endif
endfunction endfunction
function! fugitive#Statusline(...) abort function! fugitive#statusline(...) abort
return fugitive#statusline() return fugitive#Statusline()
endfunction endfunction
function! FugitiveStatusline(...) abort function! FugitiveStatusline(...) abort
return fugitive#statusline() if !exists('b:git_dir')
return ''
endif
return fugitive#Statusline()
endfunction
function! FugitiveHead(...) abort
if !exists('b:git_dir')
return ''
endif
return fugitive#repo().head(a:0 ? a:1 : 0)
endfunction endfunction
function! fugitive#head(...) abort function! fugitive#head(...) abort
@ -3151,18 +3163,14 @@ function! fugitive#head(...) abort
return s:repo().head(a:0 ? a:1 : 0) return s:repo().head(a:0 ? a:1 : 0)
endfunction endfunction
function! FugitiveHead(...) abort
return fugitive#head(a:0 ? a:1 : 0)
endfunction
augroup fugitive_statusline augroup fugitive_statusline
autocmd! autocmd!
autocmd User Flags call Hoist('buffer', function('fugitive#statusline')) autocmd User Flags call Hoist('buffer', function('FugitiveStatusline'))
augroup END augroup END
" Section: Folding " Section: Folding
function! fugitive#foldtext() abort function! fugitive#Foldtext() abort
if &foldmethod !=# 'syntax' if &foldmethod !=# 'syntax'
return foldtext() return foldtext()
endif endif
@ -3205,8 +3213,8 @@ function! fugitive#foldtext() abort
return foldtext() return foldtext()
endfunction endfunction
function! fugitive#Foldtext() abort function! fugitive#foldtext() abort
return fugitive#foldtext() return fugitive#Foldtext()
endfunction endfunction
augroup fugitive_foldtext augroup fugitive_foldtext