···3030 group = group,
3131 buffer = bufnr,
3232 callback = function()
3333- if not vim.b[bufnr].vcsigns_detecting then
3333+ if not state.get(bufnr).vcs.detecting then
3434 updates.deep_update(bufnr)
3535 end
3636 end,
···4848 group = group,
4949 buffer = bufnr,
5050 callback = function()
5151- if not vim.b[bufnr].vcsigns_detecting then
5151+ if not state.get(bufnr).vcs.detecting then
5252 updates.shallow_update(bufnr)
5353 end
5454 end,
···6060---@param bufnr integer The buffer number.
6161function M.start(bufnr)
6262 -- Clear existing state.
6363- vim.b[bufnr].vcsigns_detecting = nil
6464- vim.b[bufnr].vcsigns_vcs = nil
6363+ local s = state.get(bufnr)
6464+ s.vcs.detecting = nil
6565+ s.vcs.vcs = nil
65666667 local vcs = repo.detect_vcs(bufnr)
6767- vim.b[bufnr].vcsigns_detecting = false
6868+ s.vcs.detecting = false
6869 if not vcs then
6970 util.verbose "No VCS detected"
7071 return
7172 end
7273 util.verbose("Detected VCS " .. vcs.name)
7373- vim.b[bufnr].vcsigns_vcs = vcs
7474+ s.vcs.vcs = vcs
74757576 _set_buflocal_autocmds(bufnr)
7677end
···7879--- Start VCSigns for the given buffer, but skip if detection was already done.
7980---@param bufnr integer The buffer number.
8081function M.start_if_needed(bufnr)
8181- if vim.b[bufnr].vcsigns_vcs == nil then
8282+ if state.get(bufnr).vcs.vcs == nil then
8283 M.start(bufnr)
8384 end
8485end
···94959596 -- Clear state.
9697 state.clear(bufnr)
9797-9898- -- Clear buffer-local variables.
9999- vim.b[bufnr].vcsigns_detecting = nil
100100- vim.b[bufnr].vcsigns_vcs = nil
10198end
10299103100local last_target_notification = nil
···148145 return
149146 end
150147 local lnum = vim.fn.line "."
151151- local hunks = state.get(bufnr).hunks
148148+ local hunks = state.get(bufnr).diff.hunks
152149 local hunk = forward and hunkops.next_hunk(lnum, hunks, count)
153150 or hunkops.prev_hunk(lnum, hunks, count)
154151 if hunk then
···173170---@param range integer[] The range of lines to consider for the hunks.
174171---@return Hunk[] Hunks in the specified range.
175172local function _hunks_in_range(bufnr, range)
176176- local hunks = state.get(bufnr).hunks
173173+ local hunks = state.get(bufnr).diff.hunks
177174 ---@type Hunk[]
178175 local hunks_in_range = {}
179176 for _, hunk in ipairs(hunks) do
+1-1
lua/vcsigns/fold.lua
···88---@param lnum integer
99function M.fold_expression(lnum)
1010 local bufnr = vim.api.nvim_get_current_buf()
1111- local hunks = state.get(bufnr).hunks
1111+ local hunks = state.get(bufnr).diff.hunks
1212 if hunks == nil then
1313 return 0
1414 end
+5-2
lua/vcsigns/info.lua
···11local M = {}
2233+local state = require "vcsigns.state"
44+35function M.lualine_module()
46 return {
57 "diff",
···79 return vim.b.vcsigns_stats
810 end,
911 on_click = function()
1212+ local bufnr = vim.api.nvim_get_current_buf()
1013 local lines = {}
1111- lines[#lines + 1] = vim.b.vcsigns_vcs and vim.b.vcsigns_vcs.name
1212- or "No vcs detected"
1414+ local vcs = state.get(bufnr).vcs.vcs
1515+ lines[#lines + 1] = vcs and vcs.name or "No vcs detected"
1316 if vim.b.vcsigns_resolved_rename then
1417 lines[#lines + 1] = "File rename detected:"
1518 lines[#lines + 1] = string.format(
···5566function M.select_hunk(bufnr)
77 local lnum = vim.fn.line "."
88- local hunks = state.get(bufnr).hunks
88+ local hunks = state.get(bufnr).diff.hunks
99 local hunk = hunkops.cur_hunk(lnum, hunks)
1010 if not hunk then
1111 vim.notify(
+9-8
lua/vcsigns/updates.lua
···1414 local buffer_lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
1515 local new_contents = table.concat(buffer_lines, "\n") .. "\n"
1616 local s = state.get(bufnr)
1717- local old_contents = s.old_contents
1717+ local old_contents = s.diff.old_contents
18181919 if not old_contents then
2020 util.verbose "No old contents available, skipping diff."
···4040 end
41414242 local hunks = diff.compute_diff(old_contents, new_contents)
4343- s.hunks = hunks
4343+ s.diff.hunks = hunks
4444 sign.add_signs(bufnr, hunks)
45454646 if vim.b[bufnr].vcsigns_show_hunk_diffs then
···6262 return
6363 end
6464 local s = state.get(bufnr)
6565- local last = s.last_update
6565+ local last = s.diff.last_update
6666 if start_time <= last then
6767 util.verbose "Skipping updating old file, we already have a newer update."
6868 return
6969 end
7070- s.old_contents = old_contents
7171- s.last_update = start_time
7272- s.hunks_changedtick = vim.b[bufnr].changedtick
7070+ s.diff.old_contents = old_contents
7171+ s.diff.last_update = start_time
7272+ s.diff.hunks_changedtick = vim.b[bufnr].changedtick
7373 cb(bufnr)
7474 end)
7575end
···7777---@param bufnr integer The buffer number.
7878---@return Vcs|nil The VCS object if ready, nil otherwise.
7979local function _get_vcs_if_ready(bufnr)
8080- local detecting = vim.b[bufnr].vcsigns_detecting
8080+ local vcs_state = state.get(bufnr).vcs
8181+ local detecting = vcs_state.detecting
8182 if detecting == nil then
8283 util.verbose "Buffer not initialized yet."
8384 end
···8586 util.verbose "Busy detecting, skipping."
8687 return
8788 end
8888- return vim.b[bufnr].vcsigns_vcs
8989+ return vcs_state.vcs
8990end
90919192--- Expensive update including vcs querying for file contents.