Smarter :Gstatus reload

This commit is contained in:
Tim Pope 2019-07-02 02:02:37 -04:00
parent 0f46d5ce32
commit 3684c01ef4

View File

@ -1441,6 +1441,7 @@ endfunction
function! fugitive#BufReadStatus() abort function! fugitive#BufReadStatus() abort
let amatch = s:Slash(expand('%:p')) let amatch = s:Slash(expand('%:p'))
let b:fugitive_type = 'index' let b:fugitive_type = 'index'
unlet! b:fugitive_reltime
try try
silent doautocmd BufReadPre silent doautocmd BufReadPre
let cmd = [fnamemodify(amatch, ':h')] let cmd = [fnamemodify(amatch, ':h')]
@ -1653,6 +1654,7 @@ function! fugitive#BufReadStatus() abort
endwhile endwhile
endfor endfor
let b:fugitive_reltime = reltime()
return '' return ''
catch /^fugitive:/ catch /^fugitive:/
return 'echoerr ' . string(v:exception) return 'echoerr ' . string(v:exception)
@ -1699,7 +1701,6 @@ function! fugitive#FileWriteCmd(...) abort
if exists('#' . autype . 'WritePost') if exists('#' . autype . 'WritePost')
execute 'doautocmd ' . autype . 'WritePost ' . s:fnameescape(amatch) execute 'doautocmd ' . autype . 'WritePost ' . s:fnameescape(amatch)
endif endif
call fugitive#ReloadStatus()
return '' return ''
else else
return 'echoerr '.string('fugitive: '.error) return 'echoerr '.string('fugitive: '.error)
@ -1893,9 +1894,6 @@ function! s:GitCommand(line1, line2, range, count, bang, mods, reg, arg, args) a
let args = matchstr(a:arg,'\v\C.{-}%($|\\@<!%(\\\\)*\|)@=') let args = matchstr(a:arg,'\v\C.{-}%($|\\@<!%(\\\\)*\|)@=')
let after = matchstr(a:arg, '\v\C\\@<!%(\\\\)*\zs\|.*') let after = matchstr(a:arg, '\v\C\\@<!%(\\\\)*\zs\|.*')
let tree = s:Tree() let tree = s:Tree()
if !s:CanAutoReloadStatus()
let after = '|call fugitive#ReloadStatus()' . after
endif
let cmd = "exe '!'.escape(" . string(git) . " . ' ' . s:ShellExpand(" . string(args) . "),'!#%')" let cmd = "exe '!'.escape(" . string(git) . " . ' ' . s:ShellExpand(" . string(args) . "),'!#%')"
if s:cpath(tree) !=# s:cpath(getcwd()) if s:cpath(tree) !=# s:cpath(getcwd())
let cd = s:Cd() let cd = s:Cd()
@ -2047,6 +2045,7 @@ function! s:StageSeek(info, fallback) abort
endfunction endfunction
function! s:ReloadStatus(...) abort function! s:ReloadStatus(...) abort
call s:ExpireStatus(-1)
if get(b:, 'fugitive_type', '') !=# 'index' if get(b:, 'fugitive_type', '') !=# 'index'
return '' return ''
endif endif
@ -2058,57 +2057,99 @@ function! s:ReloadStatus(...) abort
return '' return ''
endfunction endfunction
function! fugitive#ReloadStatus(...) abort let s:last_time = reltime()
if exists('s:reloading_status') if !exists('s:last_times')
let s:last_times = {}
endif
function! s:ExpireStatus(bufnr) abort
if a:bufnr == -2
let s:last_time = reltime()
return ''
endif
let dir = s:Dir(a:bufnr)
if len(dir)
let s:last_times[s:cpath(dir)] = reltime()
endif
return ''
endfunction
function! FugitiveReloadCheck() abort
let t = b:fugitive_reltime
return [t, reltimestr(reltime(s:last_time, t)),
\ reltimestr(reltime(get(s:last_times, s:cpath(s:Dir()), t), t))]
endfunction
function! s:ReloadWinStatus(...) abort
if get(b:, 'fugitive_type', '') !=# 'index' || &modified
return return
endif endif
try if !exists('b:fugitive_reltime')
let s:reloading_status = 1 exe s:ReloadStatus()
let mytab = tabpagenr() return
for tab in [mytab] + range(1,tabpagenr('$')) endif
for winnr in range(1,tabpagewinnr(tab,'$')) let t = b:fugitive_reltime
if getbufvar(tabpagebuflist(tab)[winnr-1],'fugitive_type') ==# 'index' if reltimestr(reltime(s:last_time, t)) =~# '-' ||
execute 'tabnext '.tab \ reltimestr(reltime(get(s:last_times, s:cpath(s:Dir()), t), t)) =~# '-'
if winnr != winnr() exe s:ReloadStatus()
execute winnr.'wincmd w' endif
let restorewinnr = 1 endfunction
endif
try function! s:ReloadTabStatus(...) abort
if !&modified let mytab = tabpagenr()
exe s:ReloadStatus() let tab = a:0 ? a:1 : mytab
endif for winnr in range(1, tabpagewinnr(tab, '$'))
finally if getbufvar(tabpagebuflist(tab)[winnr-1], 'fugitive_type') ==# 'index'
if exists('restorewinnr') execute 'tabnext '.tab
unlet restorewinnr if winnr != winnr()
wincmd p execute winnr.'wincmd w'
endif let restorewinnr = 1
execute 'tabnext '.mytab endif
endtry try
call s:ReloadWinStatus()
finally
if exists('restorewinnr')
unlet restorewinnr
wincmd p
endif endif
endfor execute 'tabnext '.mytab
endtry
endif
endfor
unlet! t:fugitive_reload_status
endfunction
function! fugitive#ReloadStatus(...) abort
call s:ExpireStatus(a:0 ? a:1 : -2)
if a:0 > 1 ? a:2 : s:CanAutoReloadStatus()
let t = reltime()
for tabnr in range(1, tabpagenr('$'))
call settabvar(tabnr, 'fugitive_reload_status', t)
endfor endfor
finally call s:ReloadTabStatus()
unlet! s:reloading_status else
endtry call s:ReloadWinStatus()
endif
endfunction endfunction
function! s:CanAutoReloadStatus() abort function! s:CanAutoReloadStatus() abort
return get(g:, 'fugitive_autoreload_status', !has('win32')) return get(g:, 'fugitive_autoreload_status', !has('win32'))
endfunction endfunction
function! s:AutoReloadStatus(...) abort
if s:CanAutoReloadStatus()
return call('fugitive#ReloadStatus', a:000)
endif
endfunction
augroup fugitive_status augroup fugitive_status
autocmd! autocmd!
autocmd ShellCmdPost * call s:AutoReloadStatus() autocmd BufWritePost * call fugitive#ReloadStatus(-1, 0)
autocmd BufDelete term://* call s:AutoReloadStatus() autocmd ShellCmdPost * call fugitive#ReloadStatus()
autocmd BufDelete term://* call fugitive#ReloadStatus()
if !has('win32') if !has('win32')
autocmd FocusGained * call s:AutoReloadStatus() autocmd FocusGained * call fugitive#ReloadStatus(-2, 0)
endif endif
autocmd BufEnter index,index.lock
\ call s:ReloadWinStatus()
autocmd TabEnter *
\ if exists('t:fugitive_reload_status') |
\ call s:ReloadTabStatus() |
\ endif
augroup END augroup END
function! s:StageInfo(...) abort function! s:StageInfo(...) abort
@ -2753,7 +2794,7 @@ function! s:CommitCommand(line1, line2, range, count, bang, mods, reg, arg, args
echo line echo line
endfor endfor
endif endif
call fugitive#ReloadStatus() call fugitive#ReloadStatus(dir, 1)
return '' return ''
else else
let error = get(errors,-2,get(errors,-1,'!')) let error = get(errors,-2,get(errors,-1,'!'))
@ -3016,7 +3057,7 @@ function! s:Merge(cmd, bang, mods, args, ...) abort
endif endif
execute cdback execute cdback
endtry endtry
call fugitive#ReloadStatus() call fugitive#ReloadStatus(dir, 1)
if empty(filter(getqflist(),'v:val.valid && v:val.type !=# "I"')) if empty(filter(getqflist(),'v:val.valid && v:val.type !=# "I"'))
if a:cmd =~# '^rebase' && if a:cmd =~# '^rebase' &&
\ filereadable(fugitive#Find('.git/rebase-merge/amend', dir)) && \ filereadable(fugitive#Find('.git/rebase-merge/amend', dir)) &&
@ -3243,9 +3284,10 @@ function! s:Open(cmd, bang, mods, arg, args) abort
let mods = s:Mods(a:mods) let mods = s:Mods(a:mods)
if a:bang if a:bang
let dir = s:Dir()
let temp = tempname() let temp = tempname()
try try
let cdback = s:Cd(s:Tree()) let cdback = s:Cd(s:Tree(dir))
let git = s:UserCommand() let git = s:UserCommand()
let args = s:ShellExpand(a:arg) let args = s:ShellExpand(a:arg)
silent! execute '!' . escape(git . ' --no-pager ' . args, '!#%') . silent! execute '!' . escape(git . ' --no-pager ' . args, '!#%') .
@ -3260,7 +3302,7 @@ function! s:Open(cmd, bang, mods, arg, args) abort
call s:BlurStatus() call s:BlurStatus()
endif endif
silent execute mods . a:cmd temp silent execute mods . a:cmd temp
call fugitive#ReloadStatus() call fugitive#ReloadStatus(dir, 1)
return 'echo ' . string(':!' . git . ' ' . args) return 'echo ' . string(':!' . git . ' ' . args)
endif endif