Skip to content

Commit

Permalink
fix(diff_screen): issue where a diff would appear even if no changes …
Browse files Browse the repository at this point in the history
…were found
  • Loading branch information
tanvirtin committed Jul 9, 2024
1 parent faa5eec commit 54d0d4c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 58 deletions.
28 changes: 3 additions & 25 deletions lua/vgit/core/fs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,9 @@ function fs.filetype(buffer)
end

function fs.read_file(filepath)
local fd = vim.loop.fs_open(filepath, 'r', 438)
if fd == nil then return nil, { 'File not found' } end

local stat = vim.loop.fs_fstat(fd)
if stat.type ~= 'file' then return nil, { 'File not found' } end

local data = vim.loop.fs_read(fd, stat.size, 0)
if not vim.loop.fs_close(fd) then return nil, { 'Failed to close file' } end

local split_data = {}
local line = ''

for i = 1, #data do
local word = data:sub(i, i)
if word == '\n' or word == '\r' then
split_data[#split_data + 1] = line
line = ''
else
line = line .. word
end
end

if not line == '' then split_data[#split_data + 1] = line end

return split_data
local lines = vim.fn.readfile(filepath)
if not lines then return nil, { 'file not found' } end
return lines
end

function fs.write_file(filepath, lines)
Expand Down
2 changes: 2 additions & 0 deletions lua/vgit/features/screens/DiffScreen/Store.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local fs = require('vgit.core.fs')
local loop = require('vgit.core.loop')
local Diff = require('vgit.core.Diff')
local Object = require('vgit.core.Object')
local GitObject = require('vgit.git.GitObject')
Expand Down Expand Up @@ -30,6 +31,7 @@ function Store:get_lines(filename, status, opts)
return self.git_object:lines(log.commit_hash)
end

loop.free_textlock()
return fs.read_file(filename)
end

Expand Down
1 change: 1 addition & 0 deletions lua/vgit/features/screens/ProjectDiffScreen/Store.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ function Store:get_lines(status, type)
if status:has('D ') then return git_show.lines(reponame, filename, 'HEAD') end
if type == 'staged' or status:has(' D') then return git_show.lines(reponame, filename) end

loop.free_textlock()
return fs.read_file(filename)
end

Expand Down
33 changes: 0 additions & 33 deletions lua/vgit/git/GitBuffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,39 +180,6 @@ function GitBuffer:blames()
return self.git_object:blames()
end

function GitBuffer:fetch_signs()
local lines = self:get_lines()
local hunks, err = self.git_object:live_hunks(lines)

if err then return nil, err end

local sign_types = signs_setting:get('usage').main
local sign_priority = signs_setting:get('priority')
local sign_definitions = signs_setting:get('definitions')

self.signs = {}
for i = 1, #hunks do
local hunk = hunks[i]

for j = hunk.top, hunk.bot do
local sign_type = sign_types[hunk.type]
local sign_definition = sign_definitions[sign_type]
local sign_text = sign_definition.text
local lnum = (hunk.type == 'remove' and j == 0) and 1 or j

self.signs[lnum] = {
id = lnum,
lnum = lnum,
text = sign_text,
hl_group = sign_type,
priority = sign_priority,
}
end
end

return self.signs
end

function GitBuffer:live_hunks()
local lines = self:get_lines()
local hunks, err = self.git_object:live_hunks(lines)
Expand Down

0 comments on commit 54d0d4c

Please sign in to comment.