Skip to content
Open
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
31 changes: 18 additions & 13 deletions lua/gitblame/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ function M.check_is_ignored(callback)
return true
end

utils.start_job("git check-ignore " .. vim.fn.shellescape(filepath), {
on_exit = function(code)
callback(code ~= 1)
end,
})
return true

-- utils.start_job("git check-ignore " .. vim.fn.shellescape(filepath), {
-- on_exit = function(code)
-- callback(code ~= 1)
-- end,
-- })
end

---@param sha string
Expand Down Expand Up @@ -139,7 +141,7 @@ local function get_current_branch(callback)
if not utils.get_filepath() then
return
end
local command = utils.make_local_command("git branch --show-current")
local command = utils.make_local_command([[jj --config ui.color=never log -r 'latest(ancestors(@) & bookmarks())' --no-graph -T 'self.local_bookmarks().join("\n")']])

utils.start_job(command, {
on_stdout = function(url)
Expand Down Expand Up @@ -217,15 +219,18 @@ function M.get_remote_url(callback)
if not utils.get_filepath() then
return
end
local remote_url_command = utils.make_local_command("git config --get remote.origin.url")
local remote_url_command = utils.make_local_command("jj git remote list")

utils.start_job(remote_url_command, {
on_stdout = function(url)
if url and url[1] then
callback(url[1])
else
callback("")
on_stdout = function(lines)
for _, line in ipairs(lines) do
if line:match("^origin ") then
local url = line:gsub("^origin ", "")
callback(url)
return
end
end
callback("")
end,
})
end
Expand All @@ -235,7 +240,7 @@ function M.get_repo_root(callback)
if not utils.get_filepath() then
return
end
local command = utils.make_local_command("git rev-parse --show-toplevel")
local command = utils.make_local_command("jj root")

utils.start_job(command, {
on_stdout = function(data)
Expand Down
39 changes: 18 additions & 21 deletions lua/gitblame/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -172,25 +172,19 @@ local function load_blames(callback)

files_data_loading[filepath] = true

git.get_repo_root(function(git_root)
local command = "git --no-pager -C "
.. vim.fn.shellescape(git_root)
.. " blame -b -p -w --date relative --contents - "
.. vim.fn.shellescape(filepath)

start_job(command, {
input = table.concat(lines, "\n") .. "\n",
on_stdout = function(data)
process_blame_output(blames, filepath, data)
if callback then
callback()
end
end,
on_exit = function()
files_data_loading[filepath] = nil
end,
})
end)
local command = [[jj --config ui.color=never file annotate --config templates.file_annotate='"separate(\"\n\", separate(\" \", commit.commit_id(), 99999, line_number, 1), \"author \" ++ commit.author().name(), \"author-time \" ++ commit.author().timestamp().format(\"%s\"), \"committer \" ++ commit.committer().name(), \"committer-time \" ++ commit.committer().timestamp().format(\"%s\"), \"summary \" ++ commit.description().first_line(), \"\t\" ++ content)++ \"\n\""' ]] .. vim.fn.shellescape(filepath)

start_job(command, {
on_stdout = function(data)
process_blame_output(blames, filepath, data)
if callback then
callback()
end
end,
on_exit = function()
files_data_loading[filepath] = nil
end,
})
end

---Checks if the date format contains a relative time placeholder.
Expand Down Expand Up @@ -289,6 +283,9 @@ local function format_blame_text(info, template)
text = text:gsub("<date>", format_date(info.date))

local summary_escaped = info.summary and info.summary:gsub("%%", "%%%%") or ""
if info.summary == "" then
summary_escaped = "(empty)"
end
text = text:gsub("<summary>", utils.truncate_description(summary_escaped, vim.g.gitblame_max_commit_summary_length))

text = text:gsub("<sha>", info.sha and string.sub(info.sha, 1, 7) or "")
Expand Down Expand Up @@ -462,7 +459,7 @@ end

---@param callback fun(current_author: string)
local function find_current_author(callback)
start_job("git config --get user.name", {
start_job("jj config get user.name", {
---@param data string[]
on_stdout = function(data)
current_author = data[1]
Expand Down Expand Up @@ -517,7 +514,7 @@ end
---Returns SHA for the latest commit to the current branch.
---@param callback fun(sha: string)
local function get_latest_sha(callback)
start_job("git rev-parse HEAD", {
start_job("jj log -T 'commit_id' --no-graph -r @-", {
on_stdout = function(data)
callback(data[1])
end,
Expand Down