From f11b80022fe8646c5c8345486edec38820ad0cad Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Mon, 26 Jul 2021 06:21:59 -0400 Subject: [PATCH] Use jobs for calls to git update-index This is our only use of Git that requires writing to stdin, so shoehorning that behavior onto s:StdoutToFile() frees us from worrying about that when designing a more general purpose API. --- autoload/fugitive.vim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index c26d395..8c23c04 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -629,7 +629,7 @@ function! s:TreeChomp(...) abort throw 'fugitive: error running `' . cmd . '`: ' . out endfunction -function! s:StdoutToFile(out, cmd) abort +function! s:StdoutToFile(out, cmd, ...) abort let [argv, jopts, _] = s:PrepareJob(a:cmd) let exit = [] if exists('*jobstart') @@ -638,6 +638,9 @@ function! s:StdoutToFile(out, cmd) abort \ 'stderr_buffered': v:true, \ 'on_exit': { j, code, _ -> add(exit, code) }}) let job = jobstart(argv, jopts) + if a:0 + call chansend(job, a:1) + endif call chanclose(job, 'stdin') call jobwait([job]) if len(a:out) @@ -654,6 +657,9 @@ function! s:StdoutToFile(out, cmd) abort \ 'err_name': err, \ 'exit_cb': { j, code -> add(exit, code) }}) let job = job_start(argv, jopts) + if a:0 + call ch_sendraw(job, a:1) + endif call ch_close_in(job) while ch_status(job) !=# 'closed' || job_status(job) ==# 'run' exe has('patch-8.2.2366') ? 'sleep! 1m' : 'sleep 1m' @@ -1733,7 +1739,7 @@ endfunction function! s:UpdateIndex(dir, info) abort let info = join(a:info[0:-2]) . "\t" . a:info[-1] . "\n" - let [error, exec_error] = s:SystemError(fugitive#Prepare([a:dir, 'update-index', '--index-info']), info) + let [error, exec_error] = s:StdoutToFile('', [a:dir, 'update-index', '--index-info'], info) return !exec_error ? '' : len(error) ? error : 'unknown update-index error' endfunction