8000 File watcher wip by CKolkey · Pull Request #614 · NeogitOrg/neogit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

File watcher wip #614

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

Closed
wants to merge 99 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
b0da10c
Add filewatcher based on gitsigns implementation. This should set up a
CKolkey Jun 25, 2023
2ba5e57
Add debounce_trailing to utils
CKolkey Jun 25, 2023
9502ef7
Fix bug where setup is run twice, and initialize file watcher in setup.
CKolkey Jun 25, 2023
491cae3
Since the watcher now is only run in an async context, some of the repo
CKolkey Jun 25, 2023
f4c641a
Because the repo is now refreshed in async context, just refresh the
CKolkey Jun 25, 2023
c72bdf7
Remove autocmd - this is a poorer implementation of the filewatcher
CKolkey Jun 25, 2023
fc594aa
remove scheduler from all actions - remove manual status updates
CKolkey Jun 25, 2023
3114284
fix filepaths
CKolkey Jun 25, 2023
5c96a55
Mostly working
CKolkey Jun 26, 2023
547fae5
Add debug command to print repo state
CKolkey Jun 26, 2023
05f907f
Cleanup
CKolkey Jun 26, 2023
6a802b4
Ensure state is always updated, even if we bail early
CKolkey Jun 26, 2023
f4c23f3
bugfix: get envs properly
CKolkey Jun 26, 2023
7a869d2
notes
CKolkey Jun 26, 2023
68e1ad8
Use client.wrap for commit
CKolkey Jun 26, 2023
154cb23
Add source to repo refresh
CKolkey Jun 26, 2023
638bc35
Make watcher fn async
CKolkey Jun 26, 2023
5b1c6c5
Add cwd/git_root to the initializer in repo
CKolkey Jun 26, 2023
886b077
Rewrite repo refresh to use semaphore to prevent multiple refreshes
CKolkey Jun 26, 2023
e80ba09
Allow console highlights
CKolkey Jun 26, 2023 8000
fbbba45
Use internal state and improve logging
CKolkey Jun 26, 2023
9f8faa5
Add NeogitMessages user command
CKolkey Jun 26, 2023
45f08f1
Don't expose _refresh publicly
CKolkey Jun 26, 2023
c8d665a
hide git-path details
CKolkey Jun 26, 2023
8cab98c
This needs items for rendering
CKolkey Jun 27, 2023
58f0041
Bugfix: Include count (current) and discard blank lines
CKolkey Jun 27, 2023
7a61015
Add logging to builder
CKolkey Jun 27, 2023
f6ba27f
Use git root for watcher path
CKolkey Jun 27, 2023
afb98b7
Organize
CKolkey Jun 27, 2023
fc2f6c6
Formatting
CKolkey Jun 28, 2023
91967ef
Reformat to be more friendly to lsp's goto definition
CKolkey Jul 1, 2023
368cc4e
Add notes
CKolkey Jul 1, 2023
b7d9a73
Make filewatcher slightly less aggressive
CKolkey Jul 1, 2023
ecf55e2
Add status.update() function that will refresh repo state then redraw
CKolkey Jul 1, 2023
b4c32c8
Alphabetize git barrel imports
CKolkey Jul 1, 2023
aa7bbdf
pull this function into a new git lib, "index"
CKolkey Jul 1, 2023
ee74024
Increase watcher debounce from 100ms to 300ms
CKolkey Jul 1, 2023
3d8a32c
Tune up logging
CKolkey Jul 1, 2023
b3dcf90
Don't print debug info for invalidating diffs that don't exist
CKolkey Jul 1, 2023
0f114fa
Add back mechanism for invalidating only specific diffs
CKolkey Jul 1, 2023
568fbda
Formatting
CKolkey Jul 1, 2023
c3f58eb
Add index updating visitor to track the git index. Without this the
CKolkey Jul 1, 2023
9433fcf
test
CKolkey Jul 1, 2023
20bd319
test empty
CKolkey Jul 1, 2023
78bea0e
Add logging for diff metatable
CKolkey Jul 2, 2023
869c6b8
Fix logging
CKolkey Jul 2, 2023
10d13fe
formatting
CKolkey Jul 3, 2023
d764411
It's a hash-like table so this needs to be called manually
CKolkey Jul 3, 2023
ae49278
Test out a more limited watcher
CKolkey Jul 3, 2023
95cea90
revert this: not picking up enough external events
CKolkey Jul 4, 2023
bccb548
refactor: extract git functions from status buffer into git lib
CKolkey Jul 4, 2023
4e72b92
extract util function
CKolkey Jul 4, 2023
8b54890
Revert
CKolkey Jul 4, 2023
84776f6
formatting
CKolkey Jul 4, 2023
8456dca
Clean up status
CKolkey Jul 4, 2023
524e7d3
Add notes on vim.system
CKolkey Jul 5, 2023
3e0071b
Use lua instead of c
CKolkey Jul 5, 2023
ad26f44
Run all update functions async, with a callback after they're done. Much
CKolkey Jul 5, 2023
cac1dcc
cleanup
CKolkey Jul 5, 2023
c375ae4
Reorder lock
CKolkey Jul 5, 2023
1f25512
Log and only update status once
CKolkey Jul 5, 2023
27971af
lint: unused variables
CKolkey Jul 10, 2023
4c8ae4e
fix/lint 8000
CKolkey Jul 10, 2023
c11e444
Standardize option
CKolkey Jul 11, 2023
389ba29
Confirm modifying a commit if it has already been published upstream
CKolkey Jul 11, 2023
4d68bef
Allow for rebasing onto pushremote, and add 'b' action to rebase onto
CKolkey Jul 11, 2023
38dc48d
Remove duplicate and add highlight to base branch name
CKolkey Jul 12, 2023
e81232f
If remote.defaultPush is set, use that instead of blank
CKolkey Jul 12, 2023
dcce729
Merge remote-tracking branch 'org/master' into file-watcher-wip
CKolkey Jul 18, 2023
2b285c3
Merge branch 'master' into file-watcher-wip
CKolkey Jul 22, 2023
95a4f9f
revert sequential change
CKolkey Jul 22, 2023
917b450
Move filewatcher to status setup
CKolkey Jul 22, 2023
2c0b0fd
Rewrite repo to be locked to CWD
CKolkey Jul 23, 2023
15fa202
Merge branch 'master' into file-watcher-wip
CKolkey Jul 30, 2023
83a559b
Clean up after merging master
CKolkey Aug 1, 2023
17786b9
Properly async-wrap action functions so we don't need to change the repo
CKolkey Aug 1, 2023
838422e
clean
CKolkey Aug 1, 2023
5137cd0
Ensure repo state is built before rendering status buffer
CKolkey Aug 1, 2023
2573b33
Cleanup: Don't shield function, and respect config
CKolkey Aug 1, 2023
ddb7e08
revert: use fn
CKolkey Aug 1, 2023
0e56101
Bugfix: use lib function instead of state
CKolkey Aug 1, 2023
418cabf
Wrap in operation fn to clean up
CKolkey Aug 1, 2023
f8f491d
Extract refresh as it's own function
CKolkey Aug 1, 2023
d5ec1ab
Fix missed string formatting
CKolkey Aug 1, 2023
2185056
Rewrite how status.current_operation works - all actions that need to be
CKolkey Aug 1, 2023
a3b4bbc
Disable watcher for testing
CKolkey Aug 1, 2023
113884c
Don't block on this function - it's now self-blocking, in that it will
CKolkey Aug 1, 2023
305e3a1
Merge branch 'master' into file-watcher-wip
CKolkey Aug 1, 2023
fa79f49
Cleanup
CKolkey Aug 1, 2023
7dca40a
Ignore direnv config
CKolkey Aug 1, 2023
f9bc120
Patch up diffview integration
CKolkey Aug 1, 2023
f73af2f
Notes
CKolkey Aug 1, 2023
b4666a3
Move invalidate() to diff lib since it only deals with diffs
CKolkey Aug 1, 2023
3d70cf8
Remove mechanism for preventing watcher from double-triggering refresh.
CKolkey Aug 1, 2023
99464ba
No need to double wrap this in async functions.
CKolkey Aug 1, 2023
43eed6f
Format
CKolkey Aug 1, 2023
9b5ad56
Cleanup
CKolkey Aug 2, 2023
22af74d
It's impossible for this to return anything because it's async.void
CKolkey Aug 2, 2023
e655c55
Pass popup instead of varargs
CKolkey Aug 2, 2023
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ tmp/

# Generated files
doc/tags

# direnv config
.envrc
4 changes: 2 additions & 2 deletions lua/neogit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ local setup = function(opts)

hl.setup()
signs.setup()
state.setup()

require("neogit.autocmds").setup()
end

Expand Down Expand Up @@ -66,6 +64,8 @@ local open = function(opts)
end
end

state.setup()

if opts[1] ~= nil then
local popup_name = opts[1]
local has_pop, popup = pcall(require, "neogit.popups." .. popup_name)
Expand Down
26 changes: 0 additions & 26 deletions lua/neogit/autocmds.lua
Original file line number Diff line number Diff line change
@@ -1,39 +1,13 @@
local M = {}

local api = vim.api
local a = require("plenary.async")
local status = require("neogit.status")
local fs = require("neogit.lib.fs")
local group = require("neogit").autocmd_group

function M.setup()
api.nvim_create_autocmd({ "ColorScheme" }, {
callback = require("neogit.lib.hl").setup,
group = group,
})

api.nvim_create_autocmd({ "BufWritePost", "ShellCmdPost", "VimResume" }, {
callback = function(o)
-- Skip update if the buffer is not open
if not status.status_buffer then
return
end

-- Do not trigger on neogit buffers such as commit
if api.nvim_buf_get_option(o.buf, "filetype"):find("Neogit") then
return
end

a.run(function()
local path = fs.relpath_from_repository(o.file)
if not path then
return
end
status.refresh({ status = true, diffs = { "*:" .. path } }, string.format("%s:%s", o.event, o.file))
end, function() end)
end,
group = group,
})
end

return M
3 changes: 0 additions & 3 deletions lua/neogit/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ function M.wrap(cmd, opts)
else
notif.create(opts.msg.fail)
end

a.util.scheduler()
require("neogit.status").refresh(true, opts.refresh)
end

return M
3 changes: 1 addition & 2 deletions lua/neogit/integrations/diffview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ local dv_lib = require("diffview.lib")
local dv_utils = require("diffview.utils")

local neogit = require("neogit")
local status = require("neogit.status")
local a = require("plenary.async")

local old_config
Expand Down Expand Up @@ -132,7 +131,7 @@ local function get_local_diff_view(selected_file_name)
}

view:on_files_staged(a.void(function(_)
status.refresh({ status = true, diffs = true }, "on_files_staged")
require("neogit.status").update()
view:update_files()
end))

Expand Down
30 changes: 15 additions & 15 deletions lua/neogit/lib/git.lua
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
return {
repo = require("neogit.lib.git.repository"),
branch = require("neogit.lib.git.branch"),
cherry_pick = require("neogit.lib.git.cherry_pick"),
cli = require("neogit.lib.git.cli"),
init = require("neogit.lib.git.init"),
status = require("neogit.lib.git.status"),
stash = require("neogit.lib.git.stash"),
files = require("neogit.lib.git.files"),
config = require("neogit.lib.git.config"),
diff = require("neogit.lib.git.diff"),
fetch = require("neogit.lib.git.fetch"),
files = require("neogit.lib.git.files"),
index = require("neogit.lib.git.index"),
init = require("neogit.lib.git.init"),
log = require("neogit.lib.git.log"),
reflog = require("neogit.lib.git.reflog"),
branch = require("neogit.lib.git.branch"),
diff = require("neogit.lib.git.diff"),
rebase = require("neogit.lib.git.rebase"),
merge = require("neogit.lib.git.merge"),
cherry_pick = require("neogit.lib.git.cherry_pick"),
pull = require("neogit.lib.git.pull"),
push = require("neogit.lib.git.push"),
rebase = require("neogit.lib.git.rebase"),
reflog = require("neogit.lib.git.reflog"),
remote = require("neogit.lib.git.remote"),
repo = require("neogit.lib.git.repository"),
reset = require("neogit.lib.git.reset"),
revert = require("neogit.lib.git.revert"),
remote = require("neogit.lib.git.remote"),
config = require("neogit.lib.git.config"),
sequencer = require("neogit.lib.git.sequencer"),
pull = require("neogit.lib.git.pull"),
push = require("neogit.lib.git.push"),
index = require("neogit.lib.git.index"),
stash = require("neogit.lib.git.stash"),
status = require("neogit.lib.git.status"),
}
74 changes: 47 additions & 27 deletions lua/neogit/lib/git/diff.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ local ItemFilter = require("neogit.lib.item_filter")
local insert = table.insert
local sha256 = vim.fn.sha256

local M = {}

local function parse_diff_stats(raw)
if type(raw) == "string" then
raw = vim.split(raw, ", ")
Expand Down Expand Up @@ -155,7 +157,7 @@ local function build_hunks(lines)
return hunks
end

local function parse_diff(raw_diff, raw_stats)
function M.parse(raw_diff, raw_stats)
local header, start_idx = build_diff_header(raw_diff)
local lines = build_lines(raw_diff, start_idx)
local hunks = build_hunks(lines)
Expand All @@ -179,14 +181,15 @@ local function build_metatable(f, raw_output_fn)
if method == "diff" then
self.diff = a.util.block_on(function()
logger.debug("[DIFF] Loading diff for: " .. f.name)
return parse_diff(raw_output_fn())
return M.parse(raw_output_fn())
end)

return self.diff
end
end,
})

logger.trace("[DIFF] Adding metatable for: " .. f.name)
f.has_diff = true
end

Expand Down Expand Up @@ -215,40 +218,57 @@ local function raw_staged(name)
end
end

-- When there is _no_ filter, invalidate all diffs
-- When there _is_ a filter, only invalidate matching items
-- And, of course, don't worry about items that haven't loaded diffs
local function invalidate_diff(filter, section, item)
if not rawget(item, "diff") then
return
end

if not filter or filter:accepts(section, item.name) then
logger.debug("[DIFF] Invalidating cached diff for: " .. item.name)
logger.debug(string.format("[DIFF] Invalidating diff for: %s", item.name))
item.diff = nil
end
end

return {
parse = parse_diff,
register = function(meta)
meta.update_diffs = function(repo, filter)
filter = filter or false
if filter and type(filter) == "table" then
filter = ItemFilter.create(filter)
end
M.invalid = {}

for _, f in ipairs(repo.untracked.items) do
invalidate_diff(filter, "untracked", f)
build_metatable(f, raw_untracked(f.name))
end
-- Invalidates a cached diff for a file
function M.invalidate(...)
local files = { ... }
for _, path in ipairs(files) do
table.insert(M.invalid, string.format("*:%s", path))
end
end

for _, f in ipairs(repo.unstaged.items) do
if f.mode ~= "F" then
invalidate_diff(filter, "unstaged", f)
build_metatable(f, raw_unstaged(f.name))
end
function M.register(meta)
meta.update_diffs = function(repo)
local filter
if #M.invalid > 0 then
filter = ItemFilter.create(M.invalid)
M.invalid = {}
end

for _, f in ipairs(repo.untracked.items) do
invalidate_diff(filter, "untracked", f)
build_metatable(f, raw_untracked(f.name))
end

for _, f in ipairs(repo.unstaged.items) do
if f.mode ~= "F" then
invalidate_diff(filter, "unstaged", f)
build_metatable(f, raw_unstaged(f.name))
end
end

for _, f in ipairs(repo.staged.items) do
if f.mode ~= "F" then
invalidate_diff(filter, "staged", f)
build_metatable(f, raw_staged(f.name))
end
for _, f in ipairs(repo.staged.items) do
if f.mode ~= "F" then
invalidate_diff(filter, "staged", f)
build_metatable(f, raw_staged(f.name))
end
end
end,
}
end
end

return M
3 changes: 1 addition & 2 deletions lua/neogit/lib/git/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ M.init_repo = function()
vim.cmd(string.format("cd %s", directory))

M.create(directory)

status.refresh(true, "InitRepo")
status.refresh()
end

return M
3 changes: 0 additions & 3 deletions lua/neogit/lib/git/rebase.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ function M.rebase_interactive(commit, args)
else
notif.create("Rebased successfully", vim.log.levels.INFO)
end
a.util.scheduler()
local status = require("neogit.status")
status.refresh(true, "rebase_interactive")
end

function M.rebase_onto(branch, args)
Expand Down
Loading
0