Use fewer buffer variables for status buffer

This commit is contained in:
Tim Pope
2024-02-17 20:44:19 -05:00
parent eedb203ba7
commit ded6eb9da3

View File

@@ -2732,10 +2732,11 @@ function! fugitive#BufReadStatus(cmdbang) abort
if a:cmdbang if a:cmdbang
unlet! b:fugitive_expanded unlet! b:fugitive_expanded
endif endif
unlet! b:fugitive_reltime b:fugitive_type let b:fugitive_type = 'index'
let dir = s:Dir() let dir = s:Dir()
let stat = {'bufnr': bufnr(''), 'reltime': reltime(), 'work_tree': s:Tree(dir)} let stat = {'bufnr': bufnr(''), 'reltime': reltime(), 'work_tree': s:Tree(dir)}
try try
let b:fugitive_loading = stat
let config = fugitive#Config(dir) let config = fugitive#Config(dir)
let cmd = [dir] let cmd = [dir]
@@ -3026,15 +3027,14 @@ function! fugitive#BufReadStatus(cmdbang) abort
call s:AddLogSection(to, 'Unpulled from ' . pull_short, s:QueryLogRange(head, pull_ref, dir)) call s:AddLogSection(to, 'Unpulled from ' . pull_short, s:QueryLogRange(head, pull_ref, dir))
endif endif
let b:fugitive_files = stat.files let bufnr = stat.bufnr
let b:fugitive_diff = stat.diff
let b:fugitive_expanded = stat.expanded
let b:fugitive_reltime = stat.reltime
setlocal noreadonly modifiable setlocal noreadonly modifiable
if len(to.lines) < line('$') if len(to.lines) < line('$')
silent keepjumps execute (len(to.lines)+1) . ',$delete_' silent keepjumps execute (len(to.lines)+1) . ',$delete_'
endif endif
call setline(1, to.lines) call setline(1, to.lines)
call setbufvar(bufnr, 'fugitive_status', stat)
call setbufvar(bufnr, 'fugitive_expanded', stat.expanded)
setlocal nomodified readonly nomodifiable setlocal nomodified readonly nomodifiable
doautocmd <nomodeline> BufReadPost doautocmd <nomodeline> BufReadPost
@@ -3048,7 +3048,7 @@ function! fugitive#BufReadStatus(cmdbang) abort
return s:DoAutocmd('User FugitiveIndex') return s:DoAutocmd('User FugitiveIndex')
finally finally
let b:fugitive_type = 'index' call setbufvar(stat.bufnr, 'fugitive_loading', {})
endtry endtry
endfunction endfunction
@@ -4301,7 +4301,7 @@ function! s:DoAutocmdChanged(dir) abort
endfunction endfunction
function! s:ReloadStatusBuffer() abort function! s:ReloadStatusBuffer() abort
if get(b:, 'fugitive_type', '') !=# 'index' if get(b:, 'fugitive_type', '') !=# 'index' || !empty(get(b:, 'fugitive_loading'))
return '' return ''
endif endif
let original_lnum = line('.') let original_lnum = line('.')
@@ -4340,14 +4340,14 @@ function! s:ExpireStatus(bufnr) abort
endfunction endfunction
function! s:ReloadWinStatus(...) abort function! s:ReloadWinStatus(...) abort
if get(b:, 'fugitive_type', '') !=# 'index' || &modified if get(b:, 'fugitive_type', '') !=# 'index' || !empty(get(b:, 'fugitive_loading')) || &modified
return return
endif endif
if !exists('b:fugitive_reltime') if !exists('b:fugitive_status.reltime')
exe call('s:ReloadStatusBuffer', a:000) exe call('s:ReloadStatusBuffer', a:000)
return return
endif endif
let t = b:fugitive_reltime let t = b:fugitive_status.reltime
if reltimestr(reltime(s:last_time, t)) =~# '-\|\d\{10\}\.' || if reltimestr(reltime(s:last_time, t)) =~# '-\|\d\{10\}\.' ||
\ reltimestr(reltime(get(s:last_times, s:Tree() . '/', t), t)) =~# '-\|\d\{10\}\.' \ reltimestr(reltime(get(s:last_times, s:Tree() . '/', t), t)) =~# '-\|\d\{10\}\.'
exe call('s:ReloadStatusBuffer', a:000) exe call('s:ReloadStatusBuffer', a:000)
@@ -4434,7 +4434,7 @@ augroup fugitive_status
augroup END augroup END
function! s:StatusSectionFile(heading, filename) abort function! s:StatusSectionFile(heading, filename) abort
return get(get(get(b:, 'fugitive_files', {}), a:heading, {}), a:filename, {}) return get(get(get(get(b:, 'fugitive_status', {}), 'files', {}), a:heading, {}), a:filename, {})
endfunction endfunction
function! s:StageInfo(...) abort function! s:StageInfo(...) abort
@@ -4889,7 +4889,7 @@ function! s:StageInline(mode, ...) abort
let lnum -= 1 let lnum -= 1
endwhile endwhile
let info = s:StageInfo(lnum) let info = s:StageInfo(lnum)
let diff_section = get(get(b:, 'fugitive_diff', {}), info.section, {}) let diff_section = get(get(get(b:, 'fugitive_status', {}), 'diff', {}), info.section, {})
if empty(diff_section) if empty(diff_section)
continue continue
endif endif
@@ -5011,7 +5011,7 @@ function! s:StageApply(info, reverse, extra) abort
endif endif
let i = b:fugitive_expanded[info.section][info.filename][0] let i = b:fugitive_expanded[info.section][info.filename][0]
let head = [] let head = []
let diff_lines = fugitive#Wait(b:fugitive_diff[info.section]).stdout let diff_lines = fugitive#Wait(b:fugitive_status.diff[info.section]).stdout
while get(diff_lines, i, '@') !~# '^@' while get(diff_lines, i, '@') !~# '^@'
let line = diff_lines[i] let line = diff_lines[i]
if line ==# '--- /dev/null' if line ==# '--- /dev/null'