From 81963946ed0c1409e36b3d77b1d42af3eebae288 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Wed, 25 Nov 2020 12:33:55 +0000 Subject: [PATCH] Reuse tempfile base names This reverts "Use fresh temp files for every diff" [1]. At the time I did not realise that Vim never checks the existence of its temp directory after creating it at startup; I thought that each call to tempname() generated a fresh file on disk. In fact tempname() simply generates a string path. Therefore there is no point calling tempname() for every diff. Doing so only serves to generate more files in the temp directory than necessary. [1] dab840b15310f1b2bfb44d1db6150d7c38f9e27b --- autoload/gitgutter/diff.vim | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/autoload/gitgutter/diff.vim b/autoload/gitgutter/diff.vim index 0644a8e..22c26db 100644 --- a/autoload/gitgutter/diff.vim +++ b/autoload/gitgutter/diff.vim @@ -12,6 +12,8 @@ endfunction 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 " Returns a diff of the buffer against the index or the working tree. @@ -75,9 +77,6 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort throw 'gitgutter not tracked' endif - let temp_from = tempname() - let temp_buffer = tempname() - " Wrap compound commands in parentheses to make Windows happy. " bash doesn't mind the parentheses. let cmd = '(' @@ -90,7 +89,7 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort " 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 = temp_buffer.'.'.a:bufnr + let buff_file = s:temp_buffer.'.'.a:bufnr " 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. @@ -110,7 +109,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 " between the second process writing it (with git-show) and the first " reading it (with git-diff). - let from_file = temp_from.'.'.a:bufnr + let from_file = s:temp_from.'.'.a:bufnr " Add a counter to avoid a similar race with two quick writes of the same buffer. let from_file .= '.'.s:counter