Merge pull request #2621 from chehrlic/clink_git_speedup

Speed up git status / conflict status by calling git only once.
This commit is contained in:
Dax T Games 2021-11-10 05:55:04 -05:00 committed by GitHub
commit ad6979d25f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

37
vendor/clink.lua vendored
View File

@ -339,32 +339,27 @@ local function get_svn_branch(svn_dir)
end end
--- ---
-- Get the status of working dir -- Get the status and conflict status of working dir
-- @return {bool} -- @return {bool <status>, bool <is_conflict>}
--- ---
local function get_git_status() local function get_git_status()
local file = io_popenyield("git --no-optional-locks status --porcelain 2>nul") local file = io_popenyield("git --no-optional-locks status --porcelain 2>nul")
local conflict_found = false
local is_status = true
for line in file:lines() do for line in file:lines() do
file:close() local code = line:sub(1, 2)
return false -- print (string.format("code: %s, line: %s", code, line))
if code == "DD" or code == "AU" or code == "UD" or code == "UA" or code == "DU" or code == "AA" or code == "UU" then
is_status = false
conflict_found = true
break
-- unversioned files are ignored, comment out 'code ~= "!!"' to unignore them
elseif code ~= "!!" and code ~= "??" then
is_status = false
end
end end
file:close() file:close()
return { status = is_status, conflict = conflict_found }
return true
end
---
-- Gets the conflict status
-- @return {bool} indicating true for conflict, false for no conflicts
---
function get_git_conflict()
local file = io_popenyield("git diff --name-only --diff-filter=U 2>nul")
for line in file:lines() do
file:close()
return true;
end
file:close()
return false
end end
@ -404,7 +399,7 @@ end
--- ---
local function get_git_info_table() local function get_git_info_table()
local info = clink_promptcoroutine(function () local info = clink_promptcoroutine(function ()
return { status=get_git_status(), conflict=get_git_conflict() } return get_git_status()
end) end)
if not info then if not info then
info = cached_info.git_info or {} info = cached_info.git_info or {}