Skip to content

Commit aba23f3

Browse files
authored
fix(#395): fix race condition around buffer attachment (#399)
1 parent 390e912 commit aba23f3

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

lua/vgit/git/GitBuffer.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ function GitBuffer:exists()
230230
loop.free_textlock()
231231
if not self:is_valid() then return false end
232232

233+
loop.free_textlock()
234+
if self:get_option('buftype') ~= '' then return false end
235+
233236
loop.free_textlock()
234237
if not self:is_inside_git_dir() then return false end
235238

lua/vgit/git/git_buffer_store.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local loop = require('vgit.core.loop')
22
local event = require('vgit.core.event')
33
local utils = require('vgit.core.utils')
4+
local console = require('vgit.core.console')
45
local git_repo = require('vgit.git.git_repo')
56
local GitBuffer = require('vgit.git.GitBuffer')
67
local assertion = require('vgit.core.assertion')
@@ -135,7 +136,13 @@ git_buffer_store.collect = function()
135136
local git_buffer = GitBuffer(0)
136137
git_buffer:sync()
137138

138-
if not git_buffer:exists() then return git_buffer_store.remove(git_buffer) end
139+
local ok, result = pcall(git_buffer.exists, git_buffer)
140+
if not ok then
141+
git_buffer_store.remove(git_buffer)
142+
console.debug.error(result)
143+
return
144+
end
145+
if ok and not result then return git_buffer_store.remove(git_buffer) end
139146

140147
if git_buffer_store.contains(git_buffer) then
141148
local existing_git_buffer = git_buffer_store.get(git_buffer)

lua/vgit/git/git_hunks.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function git_hunks.live(reponame, original_lines, current_lines)
5757

5858
live_hunks[#live_hunks + 1] = hunk
5959
end,
60-
algorithm = 'myers',
60+
algorithm = git_hunks.algorithm,
6161
})
6262

6363
return live_hunks

0 commit comments

Comments
 (0)