Use stderr for in-band job communication

Since stdout can contain arbitrary user data, let's touch it as little
as possible.  When using a pty, this has no effect, as everything goes
through stdout, but I aim to move handle --paginate with this same
pipeline, and that will not use a pty.
This commit is contained in:
Tim Pope
2021-02-15 19:55:12 -05:00
parent 15f32b0008
commit d6809e9ee4

View File

@@ -2294,21 +2294,21 @@ function! s:RunEdit(state, job) abort
endif endif
endfunction endfunction
function! s:RunReceive(state, job, data, ...) abort function! s:RunReceive(state, type, job, data, ...) abort
call add(a:state.log, a:data) call add(a:state.log, a:data)
let data = type(a:data) == type([]) ? join(a:data, "\n") : a:data let data = type(a:data) == type([]) ? join(a:data, "\n") : a:data
if has_key(a:state, 'buffer') if a:type ==# 'err' || a:state.pty
let data = remove(a:state, 'buffer') . data let data = a:state.escape_buffer . data
endif let escape = "\033]51;[^\007]*"
let escape = "\033]51;[^\007]*" let a:state.escape_buffer = matchstr(data, escape . '$')
let a:state.escape_buffer = matchstr(data, escape . '$') if len(a:state.escape_buffer)
if len(a:state.escape_buffer) let data = strpart(data, 0, len(data) - len(a:state.escape_buffer))
let data = strpart(data, 0, len(data) - len(a:state.escape_buffer)) endif
endif let cmd = matchstr(data, escape . "\007")[5:-2]
let cmd = matchstr(data, escape . "\007")[5:-2] let data = substitute(data, escape . "\007", '', 'g')
let data = substitute(data, escape . "\007", '', 'g') if cmd =~# '^fugitive:'
if cmd =~# '^fugitive:' let a:state.request = strpart(cmd, 9)
let a:state.request = strpart(cmd, 9) endif
endif endif
let data = a:state.echo_buffer . data let data = a:state.echo_buffer . data
let a:state.echo_buffer = matchstr(data, "[\r\n]\\+$") let a:state.echo_buffer = matchstr(data, "[\r\n]\\+$")
@@ -2568,11 +2568,12 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort
let args = s:AskPassArgs(dir) + args let args = s:AskPassArgs(dir) + args
endif endif
let env.FUGITIVE_TEMP = state.temp let env.FUGITIVE_TEMP = state.temp
let env.FUGITIVE = state.temp
let editor = 'sh ' . s:TempScript( let editor = 'sh ' . s:TempScript(
\ '[ -f "$FUGITIVE_TEMP.exit" ] && exit 1', \ '[ -f "$FUGITIVE.exit" ] && exit 1',
\ 'echo "$1" > "$FUGITIVE_TEMP.edit"', \ 'echo "$1" > "$FUGITIVE.edit"',
\ 'printf "\033]51;fugitive:edit\007"', \ 'printf "\033]51;fugitive:edit\007" >&2',
\ 'while [ -f "$FUGITIVE_TEMP.edit" -a ! -f "$FUGITIVE_TEMP.exit" ]; do sleep 0.05 2>/dev/null || sleep 1; done', \ 'while [ -f "$FUGITIVE.edit" -a ! -f "$FUGITIVE.exit" ]; do sleep 0.05 2>/dev/null || sleep 1; done',
\ 'exit 0') \ 'exit 0')
call extend(env, { call extend(env, {
\ 'NO_COLOR': '1', \ 'NO_COLOR': '1',
@@ -2590,7 +2591,8 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort
if exists('*job_start') if exists('*job_start')
call extend(jobopts, { call extend(jobopts, {
\ 'mode': 'raw', \ 'mode': 'raw',
\ 'callback': function('s:RunReceive', [state]), \ 'out_cb': function('s:RunReceive', [state, 'out']),
\ 'err_cb': function('s:RunReceive', [state, 'err']),
\ }) \ })
if state.pty if state.pty
let jobopts.pty = 1 let jobopts.pty = 1
@@ -2600,8 +2602,8 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort
let job = jobstart(argv, extend(jobopts, { let job = jobstart(argv, extend(jobopts, {
\ 'pty': state.pty, \ 'pty': state.pty,
\ 'TERM': 'dumb', \ 'TERM': 'dumb',
\ 'on_stdout': function('s:RunReceive', [state]), \ 'on_stdout': function('s:RunReceive', [state, 'out']),
\ 'on_stderr': function('s:RunReceive', [state]), \ 'on_stderr': function('s:RunReceive', [state, 'err']),
\ })) \ }))
endif endif
let state.job = job let state.job = job