Use jobs for :Git --paginate

This commit is contained in:
Tim Pope
2021-08-17 16:58:51 -04:00
parent 952a49f688
commit eafb44a720

View File

@@ -414,10 +414,6 @@ function! s:UserCommandList(...) abort
return git + flags return git + flags
endfunction endfunction
function! s:UserCommand(...) abort
return s:shellesc(call('s:UserCommandList', a:0 ? [a:1] : []) + (a:0 ? a:2 : []))
endfunction
let s:git_versions = {} let s:git_versions = {}
function! fugitive#GitVersion(...) abort function! fugitive#GitVersion(...) abort
let git = s:GitShellCmd() let git = s:GitShellCmd()
@@ -3135,13 +3131,13 @@ function! s:RunWait(state, tmp, job, ...) abort
try try
while get(a:state, 'request', '') !=# 'edit' && s:RunTick(a:job) while get(a:state, 'request', '') !=# 'edit' && s:RunTick(a:job)
call s:RunEcho(a:tmp) call s:RunEcho(a:tmp)
if !get(a:state, 'closed_in') if !get(a:tmp, 'closed_in')
let peek = getchar(1) let peek = getchar(1)
if peek != 0 && !(has('win32') && peek == 128) if peek != 0 && !(has('win32') && peek == 128)
let c = getchar() let c = getchar()
let c = type(c) == type(0) ? nr2char(c) : c let c = type(c) == type(0) ? nr2char(c) : c
if c ==# "\<C-D>" || c ==# "\<Esc>" if c ==# "\<C-D>" || c ==# "\<Esc>"
let a:state.closed_in = 1 let a:tmp.closed_in = 1
let can_pedit = s:RunCloseIn(a:job) && exists('*setbufline') let can_pedit = s:RunCloseIn(a:job) && exists('*setbufline')
for winnr in range(1, winnr('$')) for winnr in range(1, winnr('$'))
if getwinvar(winnr, '&previewwindow') && getbufvar(winbufnr(winnr), '&modified') if getwinvar(winnr, '&previewwindow') && getbufvar(winbufnr(winnr), '&modified')
@@ -3181,7 +3177,7 @@ function! s:RunWait(state, tmp, job, ...) abort
finally finally
if !exists('finished') if !exists('finished')
try try
if a:state.pty && !get(a:state, 'closed_in') if a:state.pty && !get(a:tmp, 'closed_in')
call s:RunSend(a:job, "\<C-C>") call s:RunSend(a:job, "\<C-C>")
elseif type(a:job) == type(0) elseif type(a:job) == type(0)
call jobstop(a:job) call jobstop(a:job)
@@ -3293,7 +3289,7 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort
if args[0] ==# '-c' && len(args) > 1 if args[0] ==# '-c' && len(args) > 1
call extend(flags, remove(args, 0, 1)) call extend(flags, remove(args, 0, 1))
elseif args[0] =~# '^-p$\|^--paginate$' elseif args[0] =~# '^-p$\|^--paginate$'
let pager = 1 let pager = 2
call remove(args, 0) call remove(args, 0)
elseif args[0] =~# '^-P$\|^--no-pager$' elseif args[0] =~# '^-P$\|^--no-pager$'
let pager = 0 let pager = 0
@@ -3359,22 +3355,15 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort
let i += 1 let i += 1
endwhile endwhile
call s:PrepareEnv(env, dir) call s:PrepareEnv(env, dir)
let editcmd = a:line2 ? 'split' : 'edit' if pager is# -1
if pager is# 1
if a:bang && a:line2 >= 0
let editcmd = 'read'
elseif a:bang
let editcmd = 'pedit'
endif
elseif pager is# -1
let pager = fugitive#PagerFor(args, config) let pager = fugitive#PagerFor(args, config)
if a:bang && pager isnot# 1 if a:bang && pager isnot# 1
return 'echoerr ' . string('fugitive: :Git! for temp buffer output has been replaced by :Git --paginate') return 'echoerr ' . string('fugitive: :Git! for temp buffer output has been replaced by :Git --paginate')
endif endif
endif endif
if (s:HasOpt(args, ['add', 'checkout', 'commit', 'stage', 'stash', 'reset'], '-p', '--patch') || if type(pager) ==# type('') ||
\ s:HasOpt(args, ['add', 'clean', 'stage'], '-i', '--interactive') || \ (s:HasOpt(args, ['add', 'checkout', 'commit', 'stage', 'stash', 'reset'], '-p', '--patch') ||
\ type(pager) == type('')) && pager isnot# 1 \ s:HasOpt(args, ['add', 'clean', 'stage'], '-i', '--interactive')) && pager is# 0
let mods = substitute(s:Mods(a:mods), '\<tab\>', '-tab', 'g') let mods = substitute(s:Mods(a:mods), '\<tab\>', '-tab', 'g')
let assign = len(dir) ? '|let b:git_dir = ' . string(dir) : '' let assign = len(dir) ? '|let b:git_dir = ' . string(dir) : ''
let argv = s:UserCommandList(options) + args let argv = s:UserCommandList(options) + args
@@ -3390,9 +3379,6 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort
return mods . 'call term_start(' . string(argv) . ', ' . string(term_opts) . ')' . assign . after return mods . 'call term_start(' . string(argv) . ', ' . string(term_opts) . ')' . assign . after
endif endif
endif endif
if pager is# 1 && editcmd ==# 'read'
return s:ReadExec(a:line1, a:line2, a:range, a:mods, env, args, options) . after
endif
let state = { let state = {
\ 'git': git, \ 'git': git,
\ 'flags': flags, \ 'flags': flags,
@@ -3403,13 +3389,24 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort
\ 'filetype': 'git', \ 'filetype': 'git',
\ 'mods': s:Mods(a:mods), \ 'mods': s:Mods(a:mods),
\ 'file': s:Resolve(tempname())} \ 'file': s:Resolve(tempname())}
if pager is# 1 if pager
let after_edit = ''
if pager is# 2 && a:bang && a:line2 >= 0
let [do_edit, after_edit] = s:ReadPrepare(a:line1, a:line2, a:range, a:mods)
elseif pager is# 2 && a:bang
let do_edit = s:Mods(a:mods) . 'pedit'
elseif a:line2
let do_edit = s:Mods(a:mods) . 'split'
else
let do_edit = s:Mods(a:mods) . 'edit'
call s:BlurStatus()
endif
call extend(env, {'COLUMNS': '' . get(g:, 'fugitive_columns', 80)}, 'keep') call extend(env, {'COLUMNS': '' . get(g:, 'fugitive_columns', 80)}, 'keep')
else else
call extend(env, {'COLUMNS': '' . &columns - 1}, 'keep') call extend(env, {'COLUMNS': '' . &columns - 1}, 'keep')
endif endif
if s:RunJobs() && pager isnot# 1 if s:RunJobs()
let state.pty = get(g:, 'fugitive_pty', has('unix') && !has('win32unix') && (has('patch-8.0.0744') || has('nvim')) && fugitive#GitVersion() !~# '\.windows\>') let state.pty = !pager && get(g:, 'fugitive_pty', has('unix') && !has('win32unix') && (has('patch-8.0.0744') || has('nvim')) && fugitive#GitVersion() !~# '\.windows\>')
if !state.pty if !state.pty
let args = s:AskPassArgs(dir) + args let args = s:AskPassArgs(dir) + args
endif endif
@@ -3417,7 +3414,6 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort
\ 'line_count': 0, \ 'line_count': 0,
\ 'err': '', \ 'err': '',
\ 'out': '', \ 'out': '',
\ 'echo': '',
\ 'escape': ''} \ 'escape': ''}
let env.FUGITIVE = state.file let env.FUGITIVE = state.file
let editor = 'sh ' . s:TempScript( let editor = 'sh ' . s:TempScript(
@@ -3430,16 +3426,24 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort
\ 'NO_COLOR': '1', \ 'NO_COLOR': '1',
\ 'GIT_EDITOR': editor, \ 'GIT_EDITOR': editor,
\ 'GIT_SEQUENCE_EDITOR': editor, \ 'GIT_SEQUENCE_EDITOR': editor,
\ 'GIT_MERGE_AUTOEDIT': '1',
\ 'GIT_PAGER': 'cat', \ 'GIT_PAGER': 'cat',
\ 'PAGER': 'cat'}, 'keep') \ 'PAGER': 'cat'}, 'keep')
if pager
call writefile(['fugitive: aborting edit due to use of pager.'], state.file . '.exit')
let after = '|' . do_edit . ' ' . s:fnameescape(state.file) . after_edit . after
else
let env.GIT_MERGE_AUTOEDIT = '1'
let tmp.echo = ''
endif
let args = s:disable_colors + flags + ['-c', 'advice.waitingForEditor=false'] + args let args = s:disable_colors + flags + ['-c', 'advice.waitingForEditor=false'] + args
let argv = s:UserCommandList({'git': git, 'git_dir': dir}) + args let argv = s:UserCommandList({'git': git, 'git_dir': dir}) + args
let [argv, jobopts] = s:JobOpts(argv, env) let [argv, jobopts] = s:JobOpts(argv, env)
call fugitive#Autowrite() call fugitive#Autowrite()
call writefile([], state.file, 'b') call writefile([], state.file, 'b')
call s:RunSave(state) call s:RunSave(state)
echo "" if has_key(tmp, 'echo')
echo ""
endif
if exists('*job_start') if exists('*job_start')
call extend(jobopts, { call extend(jobopts, {
\ 'mode': 'raw', \ 'mode': 'raw',
@@ -3462,9 +3466,13 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort
\ })) \ }))
endif endif
let state.job = job let state.job = job
if pager
let tmp.closed_in = 1
call s:RunCloseIn(job)
endif
call add(s:resume_queue, [state, tmp, job]) call add(s:resume_queue, [state, tmp, job])
return 'call fugitive#Resume()|silent checktime' . after return 'call fugitive#Resume()|silent checktime' . after
elseif pager is# 1 elseif pager
let pre = s:BuildEnvPrefix(env) let pre = s:BuildEnvPrefix(env)
try try
if exists('+guioptions') && &guioptions =~# '!' if exists('+guioptions') && &guioptions =~# '!'
@@ -3482,10 +3490,7 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort
redraw! redraw!
call s:RunSave(state) call s:RunSave(state)
call s:RunFinished(state) call s:RunFinished(state)
if editcmd ==# 'edit' return do_edit . ' ' . s:fnameescape(state.file) . after_edit .
call s:BlurStatus()
endif
return state.mods . editcmd . ' ' . s:fnameescape(state.file) .
\ '|call fugitive#ReloadStatus(fugitive#Result(' . string(state.file) . '), 1)' . after \ '|call fugitive#ReloadStatus(fugitive#Result(' . string(state.file) . '), 1)' . after
elseif has('win32') elseif has('win32')
return 'echoerr ' . string('fugitive: Vim 8 with job support required to use :Git on Windows') return 'echoerr ' . string('fugitive: Vim 8 with job support required to use :Git on Windows')
@@ -5602,26 +5607,7 @@ function! s:ReadPrepare(line1, count, range, mods) abort
else else
let pre = '' let pre = ''
endif endif
return [pre . 'keepalt ' . mods . after . 'read', delete . 'diffupdate' . (a:count < 0 ? '|' . line('.') : '')] return [pre . 'keepalt ' . mods . after . 'read', '|' . delete . 'diffupdate' . (a:count < 0 ? '|' . line('.') : '')]
endfunction
function! s:ReadExec(line1, count, range, mods, env, args, options) abort
let [read, post] = s:ReadPrepare(a:line1, a:count, a:range, a:mods)
let env = s:BuildEnvPrefix(extend({'COLUMNS': &tw ? &tw : 80}, a:env))
try
if exists('+guioptions') && &guioptions =~# '!'
let guioptions = &guioptions
set guioptions-=!
endif
silent execute read . '!' escape(env . s:UserCommand(a:options, ['--no-pager'] + a:args), '!#%')
finally
if exists('guioptions')
let &guioptions = guioptions
endif
endtry
execute post
call fugitive#ReloadStatus(a:options.dir, 1)
return 'redraw|echo '.string(':!'.s:UserCommand(a:options, a:args))
endfunction endfunction
function! fugitive#ReadCommand(line1, count, range, bang, mods, arg, args) abort function! fugitive#ReadCommand(line1, count, range, bang, mods, arg, args) abort
@@ -5638,7 +5624,7 @@ function! fugitive#ReadCommand(line1, count, range, bang, mods, arg, args) abort
if file =~# '^fugitive:' && a:count is# 0 if file =~# '^fugitive:' && a:count is# 0
return 'exe ' .string('keepalt ' . s:Mods(a:mods) . fugitive#FileReadCmd(file, 0, pre)) . '|diffupdate' return 'exe ' .string('keepalt ' . s:Mods(a:mods) . fugitive#FileReadCmd(file, 0, pre)) . '|diffupdate'
endif endif
return read . ' ' . pre . ' ' . s:fnameescape(file) . '|' . post return read . ' ' . pre . ' ' . s:fnameescape(file) . post
endfunction endfunction
function! fugitive#EditComplete(A, L, P) abort function! fugitive#EditComplete(A, L, P) abort