Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lua/diffview/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ end
M.defaults = {
diff_binaries = false,
enhanced_diff_hl = false,
gerrit_style_filesort = false,
git_cmd = { "git" },
hg_cmd = { "hg" },
use_icons = true,
Expand Down
10 changes: 10 additions & 0 deletions lua/diffview/ui/models/file_tree/node.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local config = require("diffview.config")
local oop = require("diffview.oop")
local utils = require("diffview.utils")
local M = {}
Expand Down Expand Up @@ -52,6 +53,15 @@ end
---@return boolean true if node a comes before node b
function Node.comparator(a, b)
if a:has_children() == b:has_children() then
if config.get_config().gerrit_style_filesort and not a:has_children() then
cpp_header_suffixes = {".h", ".hh", ".hxx", ".hpp"}
a_name, a_ext = a.name:match("(.+)(%..+)$")
b_name, b_ext = b.name:match("(.+)(%..+)$")
if a_name == b_name then
if vim.tbl_contains(cpp_header_suffixes, a_ext) then return true end
if vim.tbl_contains(cpp_header_suffixes, b_ext) then return false end
end
end
return string.lower(a.name) < string.lower(b.name)
else
return a:has_children()
Expand Down