mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 19:43:47 -05:00
Avoid race conditions when processing multiple buffers asynchronously.
Fixes #472.
This commit is contained in:
@@ -52,8 +52,19 @@ function! gitgutter#diff#run_diff(bufnr, preserve_full_diff) abort
|
|||||||
" bash doesn't mind the parentheses.
|
" bash doesn't mind the parentheses.
|
||||||
let cmd = '('
|
let cmd = '('
|
||||||
|
|
||||||
let blob_file = s:temp_index
|
" Append buffer number to avoid race conditions between writing and reading
|
||||||
let buff_file = s:temp_buffer
|
" the files when asynchronously processing multiple buffers.
|
||||||
|
"
|
||||||
|
" Without the buffer number, blob_file would have a race in the shell
|
||||||
|
" between the second process writing it (with git-show) and the first
|
||||||
|
" reading it (with git-diff).
|
||||||
|
let blob_file = s:temp_index.'.'.a:bufnr
|
||||||
|
|
||||||
|
" Without the buffer number, buff_file would have a race between the
|
||||||
|
" second gitgutter#process_buffer() writing the file (synchronously, below)
|
||||||
|
" and the first gitgutter#process_buffer()'s async job reading it (with
|
||||||
|
" git-diff).
|
||||||
|
let buff_file = s:temp_buffer.'.'.a:bufnr
|
||||||
|
|
||||||
let extension = gitgutter#utility#extension(a:bufnr)
|
let extension = gitgutter#utility#extension(a:bufnr)
|
||||||
if !empty(extension)
|
if !empty(extension)
|
||||||
@@ -66,6 +77,7 @@ function! gitgutter#diff#run_diff(bufnr, preserve_full_diff) abort
|
|||||||
let cmd .= g:gitgutter_git_executable.' show '.blob_name.' > '.blob_file.' && '
|
let cmd .= g:gitgutter_git_executable.' show '.blob_name.' > '.blob_file.' && '
|
||||||
|
|
||||||
" Write buffer to temporary file.
|
" Write buffer to temporary file.
|
||||||
|
" Note: this is synchronous.
|
||||||
call s:write_buffer(a:bufnr, buff_file)
|
call s:write_buffer(a:bufnr, buff_file)
|
||||||
|
|
||||||
" Call git-diff with the temporary files.
|
" Call git-diff with the temporary files.
|
||||||
|
|||||||
Reference in New Issue
Block a user