Skip to content

Commit 3f5d62e

Browse files
committed
Simplify commit comparison logic in show_selected by removing unnecessary checks. Update tests accordingly.
1 parent 62027ff commit 3f5d62e

2 files changed

Lines changed: 5 additions & 27 deletions

File tree

lua/gitlogdiff/actions.lua

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,16 @@ local function diffview_open(args)
44
vim.cmd("DiffviewOpen " .. table.concat(args, " "))
55
end
66

7-
local function diffview_history(args)
8-
vim.cmd("DiffviewFileHistory " .. table.concat(args, " "))
9-
end
10-
11-
function M.show_selected(hashes, indices)
7+
function M.show_selected(hashes, _)
128
if #hashes == 0 then
139
vim.notify("No commits selected", vim.log.levels.INFO)
1410
return
1511
end
1612

17-
local is_consecutive = true
18-
if #indices > 1 then
19-
for i = 2, #indices do
20-
if indices[i] ~= indices[i - 1] + 1 then
21-
is_consecutive = false
22-
break
23-
end
24-
end
25-
end
26-
27-
if is_consecutive then
28-
if #hashes == 1 then
29-
diffview_open({ hashes[1] .. "^.." .. hashes[1] })
30-
else
31-
diffview_open({ hashes[#hashes] .. "^.." .. hashes[1] })
32-
end
13+
if #hashes == 1 then
14+
diffview_open({ hashes[1] .. "^.." .. hashes[1] })
3315
else
34-
local args = { "--no-walk" }
35-
for _, h in ipairs(hashes) do
36-
table.insert(args, h)
37-
end
38-
diffview_history(args)
16+
diffview_open({ hashes[#hashes] .. "^.." .. hashes[1] })
3917
end
4018
end
4119

tests/test_init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ T["actions"]["show_selected() handles non-consecutive commits correctly"] = func
4646
end
4747

4848
actions.show_selected({ "newer123", "older789" }, { 1, 3 })
49-
MiniTest.expect.equality(cmds[1], "DiffviewFileHistory --no-walk newer123 older789")
49+
MiniTest.expect.equality(cmds[1], "DiffviewOpen older789^..newer123")
5050
end
5151

5252
T["log"] = MiniTest.new_set()

0 commit comments

Comments
 (0)