Skip to content

Commit d90f9ad

Browse files
committed
fix: #96 improve startup time
For those who do not use the git branching feature, this may improve their Neovim startup time significantly
1 parent 5b5ec1c commit d90f9ad

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

lua/persisted/init.lua

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,26 @@ end
4141
---Get the current Git branch
4242
---@return string
4343
function M.get_branch()
44-
vim.fn.system([[git rev-parse 2> /dev/null]])
45-
local git_enabled = (vim.v.shell_error == 0)
46-
47-
if config.options.use_git_branch and git_enabled then
48-
local branch = vim.fn.systemlist([[git rev-parse --abbrev-ref HEAD 2>/dev/null]])
49-
if vim.v.shell_error == 0 then
50-
branch = config.options.branch_separator .. branch[1]:gsub("/", "%%")
51-
local branch_session = config.options.save_dir
52-
.. vim.fn.getcwd():gsub(utils.get_dir_pattern(), "%%")
53-
.. branch
54-
.. ".vim"
55-
56-
-- Try to load the session for the current branch and if not, use the value of default_branch
57-
if vim.fn.filereadable(branch_session) ~= 0 then
58-
return branch
59-
else
60-
vim.g.persisted_branch_session = branch_session
61-
return config.options.branch_separator .. default_branch
44+
if config.options.use_git_branch then
45+
vim.fn.system([[git rev-parse 2> /dev/null]])
46+
local git_enabled = (vim.v.shell_error == 0)
47+
48+
if git_enabled then
49+
local branch = vim.fn.systemlist([[git rev-parse --abbrev-ref HEAD 2>/dev/null]])
50+
if vim.v.shell_error == 0 then
51+
branch = config.options.branch_separator .. branch[1]:gsub("/", "%%")
52+
local branch_session = config.options.save_dir
53+
.. vim.fn.getcwd():gsub(utils.get_dir_pattern(), "%%")
54+
.. branch
55+
.. ".vim"
56+
57+
-- Try to load the session for the current branch and if not, use the value of default_branch
58+
if vim.fn.filereadable(branch_session) ~= 0 then
59+
return branch
60+
else
61+
vim.g.persisted_branch_session = branch_session
62+
return config.options.branch_separator .. default_branch
63+
end
6264
end
6365
end
6466
end

0 commit comments

Comments
 (0)