Skip to content

Commit addf4e3

Browse files
committed
feat: skip loading large files in diffs, which cause hangs
1 parent 4c0e75e commit addf4e3

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ neogit.setup {
100100
log_date_format = nil,
101101
-- When set, used to format the diff. Requires *baleia* to colorize text with ANSI escape sequences. An example for `Delta` is `{ 'delta', '--width', '117' }`. For `Delta`, hyperlinks must be disabled in its git config section, for text to be colorized properly. It's recommended to set `disable_context_highlighting = true`, otherwise when the cursor is in the hunk, we lose background highlighting
102102
log_pager = nil,
103+
-- Max file size for a diff to be shown
104+
diff_max_file_size = 200000,
103105
-- Show message with spinning animation when a git command is running.
104106
process_spinner = false,
105107
-- Used to generate URL's for branch popup action "pull request", "open commit" and "open tree"

doc/neogit.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ to Neovim users.
118118
-- for text to be colorized properly. It's recommended to set `disable_context_highlighting = true`, otherwise when
119119
-- the cursor is in the hunk, we lose background highlighting
120120
log_pager = nil,
121+
-- Max file size for a diff to be shown
122+
diff_max_file_size = 200000,
121123
-- Used to generate URL's for branch popup action "pull request" or opening a commit.
122124
git_services = {
123125
["github.com"] = {

lua/neogit/config.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ end
346346
---@field commit_date_format? string Commit date format
347347
---@field log_date_format? string Log date format
348348
---@field log_pager? [string] Log pager
349+
---@field diff_max_file_size? [number] Max file size for a diff to be shown
349350
---@field disable_hint? boolean Remove the top hint in the Status buffer
350351
---@field disable_context_highlighting? boolean Disable context highlights based on cursor position
351352
---@field disable_signs? boolean Special signs to draw for sections etc. in Neogit
@@ -403,6 +404,7 @@ function M.get_default_values()
403404
commit_date_format = nil,
404405
log_date_format = nil,
405406
log_pager = nil,
407+
diff_max_file_size = 200000,
406408
process_spinner = false,
407409
filewatcher = {
408410
enabled = true,

lua/neogit/lib/git/diff.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,19 @@ local function build_metatable(f, raw_output_fn)
285285
__index = function(self, method)
286286
if method == "diff" then
287287
self.diff = a.util.block_on(function()
288+
local stat = vim.uv.fs_stat(f.absolute_path)
289+
if stat == nil or stat.size > config.values.diff_max_file_size then
290+
logger.debug("[DIFF] Skipped loading diff as file too large: " .. f.name)
291+
return {
292+
kind = nil,
293+
lines = {},
294+
file = f.name,
295+
info = {},
296+
stats = {},
297+
hunks = {},
298+
pager_contents = {},
299+
}
300+
end
288301
logger.debug("[DIFF] Loading diff for: " .. f.name)
289302
return parse_diff(unpack(raw_output_fn()))
290303
end)

0 commit comments

Comments
 (0)