From 3684c01ef4bbf3ad1d5cae258bae0bd044054e9e Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Tue, 2 Jul 2019 02:02:37 -0400 Subject: [PATCH] Smarter :Gstatus reload --- autoload/fugitive.vim | 132 ++++++++++++++++++++++++++++-------------- 1 file changed, 87 insertions(+), 45 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 6163a95..41f778f 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -1441,6 +1441,7 @@ endfunction function! fugitive#BufReadStatus() abort let amatch = s:Slash(expand('%:p')) let b:fugitive_type = 'index' + unlet! b:fugitive_reltime try silent doautocmd BufReadPre let cmd = [fnamemodify(amatch, ':h')] @@ -1653,6 +1654,7 @@ function! fugitive#BufReadStatus() abort endwhile endfor + let b:fugitive_reltime = reltime() return '' catch /^fugitive:/ return 'echoerr ' . string(v:exception) @@ -1699,7 +1701,6 @@ function! fugitive#FileWriteCmd(...) abort if exists('#' . autype . 'WritePost') execute 'doautocmd ' . autype . 'WritePost ' . s:fnameescape(amatch) endif - call fugitive#ReloadStatus() return '' else 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.{-}%($|\\@ 1 ? a:2 : s:CanAutoReloadStatus() + let t = reltime() + for tabnr in range(1, tabpagenr('$')) + call settabvar(tabnr, 'fugitive_reload_status', t) endfor - finally - unlet! s:reloading_status - endtry + call s:ReloadTabStatus() + else + call s:ReloadWinStatus() + endif endfunction function! s:CanAutoReloadStatus() abort return get(g:, 'fugitive_autoreload_status', !has('win32')) endfunction -function! s:AutoReloadStatus(...) abort - if s:CanAutoReloadStatus() - return call('fugitive#ReloadStatus', a:000) - endif -endfunction - augroup fugitive_status autocmd! - autocmd ShellCmdPost * call s:AutoReloadStatus() - autocmd BufDelete term://* call s:AutoReloadStatus() + autocmd BufWritePost * call fugitive#ReloadStatus(-1, 0) + autocmd ShellCmdPost * call fugitive#ReloadStatus() + autocmd BufDelete term://* call fugitive#ReloadStatus() if !has('win32') - autocmd FocusGained * call s:AutoReloadStatus() + autocmd FocusGained * call fugitive#ReloadStatus(-2, 0) endif + autocmd BufEnter index,index.lock + \ call s:ReloadWinStatus() + autocmd TabEnter * + \ if exists('t:fugitive_reload_status') | + \ call s:ReloadTabStatus() | + \ endif augroup END function! s:StageInfo(...) abort @@ -2753,7 +2794,7 @@ function! s:CommitCommand(line1, line2, range, count, bang, mods, reg, arg, args echo line endfor endif - call fugitive#ReloadStatus() + call fugitive#ReloadStatus(dir, 1) return '' else let error = get(errors,-2,get(errors,-1,'!')) @@ -3016,7 +3057,7 @@ function! s:Merge(cmd, bang, mods, args, ...) abort endif execute cdback endtry - call fugitive#ReloadStatus() + call fugitive#ReloadStatus(dir, 1) if empty(filter(getqflist(),'v:val.valid && v:val.type !=# "I"')) if a:cmd =~# '^rebase' && \ 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) if a:bang + let dir = s:Dir() let temp = tempname() try - let cdback = s:Cd(s:Tree()) + let cdback = s:Cd(s:Tree(dir)) let git = s:UserCommand() let args = s:ShellExpand(a:arg) silent! execute '!' . escape(git . ' --no-pager ' . args, '!#%') . @@ -3260,7 +3302,7 @@ function! s:Open(cmd, bang, mods, arg, args) abort call s:BlurStatus() endif silent execute mods . a:cmd temp - call fugitive#ReloadStatus() + call fugitive#ReloadStatus(dir, 1) return 'echo ' . string(':!' . git . ' ' . args) endif