From bcf7478e6be9c8e425c0f9fb224821748132d4c3 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Wed, 6 Oct 2021 14:44:30 -0400 Subject: [PATCH] Make status buffer diff retrieval asynchronous Resolves: https://github.com/tpope/vim-fugitive/issues/1856 --- autoload/fugitive.vim | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 3c106f5..558c6c7 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -2742,14 +2742,14 @@ function! fugitive#BufReadStatus() abort endfor endif - let diff = {'Staged': [], 'Unstaged': []} + let diff = {'Staged': {'stdout': ['']}, 'Unstaged': {'stdout': ['']}} if len(staged) let diff['Staged'] = - \ s:LinesError(['diff', '--color=never', '--no-ext-diff', '--no-prefix', '--cached'])[0] + \ fugitive#Execute(['diff', '--color=never', '--no-ext-diff', '--no-prefix', '--cached'], function('len')) endif if len(unstaged) let diff['Unstaged'] = - \ s:LinesError(['diff', '--color=never', '--no-ext-diff', '--no-prefix'])[0] + \ fugitive#Execute(['diff', '--color=never', '--no-ext-diff', '--no-prefix'], function('len')) endif let b:fugitive_diff = diff if v:cmdbang @@ -4671,7 +4671,7 @@ function! s:StageInline(mode, ...) abort let diff = [] let index = 0 let start = -1 - for line in b:fugitive_diff[info.section] + for line in fugitive#Wait(b:fugitive_diff[info.section]).stdout if mode ==# 'await' && line[0] ==# '@' let mode = 'capture' endif @@ -4795,10 +4795,11 @@ function! s:StageApply(info, reverse, extra) abort endif let i = b:fugitive_expanded[info.section][info.filename][0] let head = [] - while get(b:fugitive_diff[info.section], i, '@') !~# '^@' - let line = b:fugitive_diff[info.section][i] + let diff_lines = fugitive#Wait(b:fugitive_diff[info.section]).stdout + while get(diff_lines, i, '@') !~# '^@' + let line = diff_lines[i] if line ==# '--- /dev/null' - call add(head, '--- ' . get(b:fugitive_diff[info.section], i + 1, '')[4:-1]) + call add(head, '--- ' . get(diff_lines, i + 1, '')[4:-1]) elseif line !~# '^new file ' call add(head, line) endif