Skip to content

Commit

Permalink
fix(#395): fix race condition around buffer attachment (#399)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanvirtin authored Feb 6, 2025
1 parent 390e912 commit aba23f3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lua/vgit/git/GitBuffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ function GitBuffer:exists()
loop.free_textlock()
if not self:is_valid() then return false end

loop.free_textlock()
if self:get_option('buftype') ~= '' then return false end

loop.free_textlock()
if not self:is_inside_git_dir() then return false end

Expand Down
9 changes: 8 additions & 1 deletion lua/vgit/git/git_buffer_store.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local loop = require('vgit.core.loop')
local event = require('vgit.core.event')
local utils = require('vgit.core.utils')
local console = require('vgit.core.console')
local git_repo = require('vgit.git.git_repo')
local GitBuffer = require('vgit.git.GitBuffer')
local assertion = require('vgit.core.assertion')
Expand Down Expand Up @@ -135,7 +136,13 @@ git_buffer_store.collect = function()
local git_buffer = GitBuffer(0)
git_buffer:sync()

if not git_buffer:exists() then return git_buffer_store.remove(git_buffer) end
local ok, result = pcall(git_buffer.exists, git_buffer)
if not ok then
git_buffer_store.remove(git_buffer)
console.debug.error(result)
return
end
if ok and not result then return git_buffer_store.remove(git_buffer) end

if git_buffer_store.contains(git_buffer) then
local existing_git_buffer = git_buffer_store.get(git_buffer)
Expand Down
2 changes: 1 addition & 1 deletion lua/vgit/git/git_hunks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function git_hunks.live(reponame, original_lines, current_lines)

live_hunks[#live_hunks + 1] = hunk
end,
algorithm = 'myers',
algorithm = git_hunks.algorithm,
})

return live_hunks
Expand Down

0 comments on commit aba23f3

Please sign in to comment.