Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform scm updates only on certain events #7

Merged
merged 1 commit into from
Sep 4, 2024
Merged
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
95 changes: 93 additions & 2 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ local util = require "plugins.scm.util"
local changes = require "plugins.scm.changes"
local Doc = require "core.doc"
local DocView = require "core.docview"
local DirWatch = require "core.dirwatch"
local StatusView = require "core.statusview"
local ReadDocView = require "plugins.scm.readdocview"
local Git = require "plugins.scm.backend.git"
Expand Down Expand Up @@ -765,16 +766,106 @@ function scm.update()
end
end

---Update current branch of all open projects.
function scm.update_branch()
for project_dir, project_backend in pairs(PROJECTS) do
local project_open = false
for _, project in ipairs(core.projects) do
if project.path == project_dir then
project_open = true
break
end
end
if not project_open then
return
else
project_backend:get_branch(project_dir, function(branch, cached)
if not cached then
BRANCHES[project_dir] = branch
project_backend:yield()
end
end)
end
end
end

--------------------------------------------------------------------------------
-- Keep the project branch, changes and stats updated
--------------------------------------------------------------------------------
local perform_update_count = 0
local function perform_update()
if perform_update_count == 0 then
perform_update_count = 1
core.add_thread(function()
coroutine.yield()
while perform_update_count > 0 do
scm.update()
coroutine.yield(1)
perform_update_count = perform_update_count - 1
end
end)
else
perform_update_count = perform_update_count + 1
end
end

perform_update() -- perform update on startup

core.add_thread(function()
while true do
scm.update()
coroutine.yield(1)
scm.update_branch()
coroutine.yield(3)
end
end)

local dirwatch_check = DirWatch.check
function DirWatch:check(...)
local has_change = dirwatch_check(self, ...)
if has_change then perform_update() end
return has_change
end

local dirwatch_watch = DirWatch.watch
function DirWatch:watch(...)
local retval = dirwatch_watch(self, ...)
perform_update()
return retval
end

local dirwatch_unwatch = DirWatch.unwatch
function DirWatch:unwatch(...)
local retval = dirwatch_unwatch(self, ...)
perform_update()
return retval
end

local core_add_project = core.add_project
function core.add_project(project)
project = core_add_project(project)
perform_update()
return project
end

local core_remove_project = core.remove_project
function core.remove_project(project, force)
project = core_remove_project(project, force)
perform_update()
return project
end

local core_set_project = core.set_project
function core.set_project(project)
project = core_set_project(project)
perform_update()
return project
end

local core_open_project = core.open_project
function core.open_project(project)
core_open_project(project)
perform_update()
end

--------------------------------------------------------------------------------
-- Override Doc to register diff changes and blame history
--------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": "scm",
"name": "Source Control Management",
"description": "Extensible source control management plugin with git and fossil backends.",
"version": "0.4.6",
"version": "0.4.7",
"mod_version": "3.1",
"dependencies": {
"language_diff": { "version": ">=0.1" }
Expand Down