mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 19:43:47 -05:00
Use fresh temp files for every diff
Originally the plugin used fresh temp files for every diff. But it wrote to those files with `:write` which made Vim's buffer numbers increase unnecessarily (see #297) so the plugin changed to reuse the same temp files each time (seea871d857). However this has the problem that after Vim has been open for a while, e.g. a few days, the operating system can clean up the temp directory holding those temp files. The next time the plugin runs a diff, Vim throws an error because it cannot write to the temp files because their directory has disappeared (see #395, #433). In the meantime the plugin changed how it writes the temp files to use `writefile()` (see4e911819). This removed the problem of rapidly increasing buffer numbers. Now the buffer number problem has gone, the plugin can revert to using fresh temp files each time.
This commit is contained in:
@@ -12,9 +12,6 @@ endfunction
|
|||||||
|
|
||||||
let s:c_flag = s:git_supports_command_line_config_override()
|
let s:c_flag = s:git_supports_command_line_config_override()
|
||||||
|
|
||||||
|
|
||||||
let s:temp_from = tempname()
|
|
||||||
let s:temp_buffer = tempname()
|
|
||||||
let s:counter = 0
|
let s:counter = 0
|
||||||
|
|
||||||
" Returns a diff of the buffer against the index or the working tree.
|
" Returns a diff of the buffer against the index or the working tree.
|
||||||
@@ -78,6 +75,9 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
|
|||||||
throw 'gitgutter not tracked'
|
throw 'gitgutter not tracked'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let temp_from = tempname()
|
||||||
|
let temp_buffer = tempname()
|
||||||
|
|
||||||
" Wrap compound commands in parentheses to make Windows happy.
|
" Wrap compound commands in parentheses to make Windows happy.
|
||||||
" bash doesn't mind the parentheses.
|
" bash doesn't mind the parentheses.
|
||||||
let cmd = '('
|
let cmd = '('
|
||||||
@@ -90,7 +90,7 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
|
|||||||
" second gitgutter#process_buffer() writing the file (synchronously, below)
|
" second gitgutter#process_buffer() writing the file (synchronously, below)
|
||||||
" and the first gitgutter#process_buffer()'s async job reading it (with
|
" and the first gitgutter#process_buffer()'s async job reading it (with
|
||||||
" git-diff).
|
" git-diff).
|
||||||
let buff_file = s:temp_buffer.'.'.a:bufnr
|
let buff_file = temp_buffer.'.'.a:bufnr
|
||||||
|
|
||||||
" Add a counter to avoid a similar race with two quick writes of the same buffer.
|
" Add a counter to avoid a similar race with two quick writes of the same buffer.
|
||||||
" Use a modulus greater than a maximum reasonable number of visible buffers.
|
" Use a modulus greater than a maximum reasonable number of visible buffers.
|
||||||
@@ -110,7 +110,7 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
|
|||||||
" Without the buffer number, from_file would have a race in the shell
|
" Without the buffer number, from_file would have a race in the shell
|
||||||
" between the second process writing it (with git-show) and the first
|
" between the second process writing it (with git-show) and the first
|
||||||
" reading it (with git-diff).
|
" reading it (with git-diff).
|
||||||
let from_file = s:temp_from.'.'.a:bufnr
|
let from_file = temp_from.'.'.a:bufnr
|
||||||
|
|
||||||
" Add a counter to avoid a similar race with two quick writes of the same buffer.
|
" Add a counter to avoid a similar race with two quick writes of the same buffer.
|
||||||
let from_file .= '.'.s:counter
|
let from_file .= '.'.s:counter
|
||||||
|
|||||||
Reference in New Issue
Block a user