Skip to content

Commit a3fc4ae

Browse files
zegervdvsindrets
andauthored
feat!: Split log_options config to allow for other VCS types (#271)
Co-authored-by: Sindre T. Strøm <sindrets@gmail.com>
1 parent c6a3d3f commit a3fc4ae

File tree

11 files changed

+366
-293
lines changed

11 files changed

+366
-293
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,17 @@ require("diffview").setup({
212212
},
213213
file_history_panel = {
214214
log_options = { -- See ':h diffview-config-log_options'
215-
single_file = {
216-
diff_merges = "combined",
215+
git = {
216+
single_file = {
217+
diff_merges = "combined",
218+
},
219+
multi_file = {
220+
diff_merges = "first-parent",
221+
},
217222
},
218-
multi_file = {
219-
diff_merges = "first-parent",
223+
hg = {
224+
single_file = {},
225+
multi_file = {},
220226
},
221227
},
222228
win_config = { -- See ':h diffview-config-win_config'

doc/diffview_changelog.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,53 @@ CHANGELOG
55

66
NOTE: This changelog only encompasses breaking changes.
77

8+
*diffview.changelog-271*
9+
10+
PR: https://github.com/sindrets/diffview.nvim/pull/271
11+
12+
The config for log options has changed. In preparation of adding support of
13+
other VCS, the table is now divided into sub-tables per VCS type. This allows
14+
you to define different default log options for different VCS tools. To update
15+
your config, just move all your current log options into the new table key
16+
`git`:
17+
18+
Before: ~
19+
>
20+
require("diffview").setup({
21+
-- ...
22+
file_history_panel = {
23+
log_options = {
24+
single_file = {
25+
max_count = 512,
26+
follow = true,
27+
},
28+
multi_file = {
29+
max_count = 128,
30+
},
31+
},
32+
},
33+
})
34+
<
35+
36+
After: ~
37+
>
38+
require("diffview").setup({
39+
-- ...
40+
file_history_panel = {
41+
log_options = {
42+
git = {
43+
single_file = {
44+
max_count = 512,
45+
follow = true,
46+
},
47+
multi_file = {
48+
max_count = 128,
49+
},
50+
},
51+
},
52+
},
53+
})
54+
<
855
*diffview.changelog-190*
956

1057
PR: https://github.com/sindrets/diffview.nvim/pull/190

doc/diffview_defaults.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,17 @@ require("diffview").setup({
6060
},
6161
file_history_panel = {
6262
log_options = { -- See |diffview-config-log_options|
63-
single_file = {
64-
diff_merges = "combined",
63+
git = {
64+
single_file = {
65+
diff_merges = "combined",
66+
},
67+
multi_file = {
68+
diff_merges = "first-parent",
69+
},
6570
},
66-
multi_file = {
67-
diff_merges = "first-parent",
71+
hg = {
72+
single_file = {},
73+
multi_file = {},
6874
},
6975
},
7076
win_config = { -- See |diffview-config-win_config|

lua/diffview/config.lua

Lines changed: 68 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,20 @@ M.defaults = {
7575
},
7676
},
7777
file_history_panel = {
78-
---@type ConfigLogOptions
7978
log_options = {
80-
single_file = {
81-
diff_merges = "combined",
79+
---@type ConfigLogOptions
80+
git = {
81+
single_file = {
82+
diff_merges = "combined",
83+
},
84+
multi_file = {
85+
diff_merges = "first-parent",
86+
},
8287
},
83-
multi_file = {
84-
diff_merges = "first-parent",
88+
---@type ConfigLogOptions
89+
hg = {
90+
single_file = {},
91+
multi_file = {},
8592
},
8693
},
8794
win_config = {
@@ -216,7 +223,7 @@ M.defaults = {
216223
M.user_emitter = EventEmitter()
217224
M._config = M.defaults
218225

219-
---@class LogOptions
226+
---@class GitLogOptions
220227
---@field follow boolean
221228
---@field first_parent boolean
222229
---@field show_pulls boolean
@@ -236,26 +243,34 @@ M._config = M.defaults
236243
---@field base string
237244
---@field path_args string[]
238245

239-
---@type LogOptions
246+
---@class HgLogOptions
247+
248+
---@alias LogOptions GitLogOptions|HgLogOptions
249+
240250
M.log_option_defaults = {
241-
follow = false,
242-
first_parent = false,
243-
show_pulls = false,
244-
reflog = false,
245-
all = false,
246-
merges = false,
247-
no_merges = false,
248-
reverse = false,
249-
rev_range = nil,
250-
base = nil,
251-
max_count = 256,
252-
L = {},
253-
diff_merges = nil,
254-
author = nil,
255-
grep = nil,
256-
G = nil,
257-
S = nil,
258-
path_args = {},
251+
---@type GitLogOptions
252+
git = {
253+
follow = false,
254+
first_parent = false,
255+
show_pulls = false,
256+
reflog = false,
257+
all = false,
258+
merges = false,
259+
no_merges = false,
260+
reverse = false,
261+
rev_range = nil,
262+
base = nil,
263+
max_count = 256,
264+
L = {},
265+
diff_merges = nil,
266+
author = nil,
267+
grep = nil,
268+
G = nil,
269+
S = nil,
270+
path_args = {},
271+
},
272+
---@type HgLogOptions
273+
hg = {},
259274
}
260275

261276
---@return DiffviewConfig
@@ -268,15 +283,16 @@ function M.get_config()
268283
end
269284

270285
---@param single_file boolean
271-
---@param t LogOptions
272-
---@return LogOptions
273-
function M.get_log_options(single_file, t)
286+
---@param t GitLogOptions|HgLogOptions
287+
---@param vcs "git"|"hg"
288+
---@return GitLogOptions|HgLogOptions
289+
function M.get_log_options(single_file, t, vcs)
274290
local log_options
275291

276292
if single_file then
277-
log_options = M._config.file_history_panel.log_options.single_file
293+
log_options = M._config.file_history_panel.log_options[vcs].single_file
278294
else
279-
log_options = M._config.file_history_panel.log_options.multi_file
295+
log_options = M._config.file_history_panel.log_options[vcs].multi_file
280296
end
281297

282298
if t then
@@ -452,6 +468,17 @@ function M.setup(user_config)
452468

453469
local user_log_options = utils.tbl_access(user_config, "file_history_panel.log_options")
454470
if user_log_options then
471+
local top_options = {
472+
"single_file",
473+
"multi_file",
474+
}
475+
for _, name in ipairs(top_options) do
476+
if user_log_options[name] ~= nil then
477+
utils.warn("Global config of 'file_panel.log_options' has been deprecated. See ':h diffview.changelog-271'.")
478+
end
479+
break
480+
end
481+
455482
local option_names = {
456483
"max_count",
457484
"follow",
@@ -508,15 +535,17 @@ function M.setup(user_config)
508535
end
509536

510537
for _, name in ipairs({ "single_file", "multi_file" }) do
511-
local t = M._config.file_history_panel.log_options
512-
t[name] = vim.tbl_extend(
513-
"force",
514-
M.log_option_defaults,
515-
t[name]
516-
)
517-
for k, _ in pairs(t[name]) do
518-
if t[name][k] == "" then
519-
t[name][k] = nil
538+
for _, vcs in ipairs({ "git", "hg" }) do
539+
local t = M._config.file_history_panel.log_options[vcs]
540+
t[name] = vim.tbl_extend(
541+
"force",
542+
M.log_option_defaults[vcs],
543+
t[name]
544+
)
545+
for k, _ in pairs(t[name]) do
546+
if t[name][k] == "" then
547+
t[name][k] = nil
548+
end
520549
end
521550
end
522551
end

lua/diffview/scene/views/file_history/file_history_panel.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ function FileHistoryPanel:init(opt)
8181
self.log_options = {
8282
single_file = vim.tbl_extend(
8383
"force",
84-
conf.file_history_panel.log_options.single_file,
84+
conf.file_history_panel.log_options[self.adapter.config_key].single_file,
8585
opt.log_options
8686
),
8787
multi_file = vim.tbl_extend(
8888
"force",
89-
conf.file_history_panel.log_options.multi_file,
89+
conf.file_history_panel.log_options[self.adapter.config_key].multi_file,
9090
opt.log_options
9191
),
9292
}

lua/diffview/vcs/adapter.lua

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ local M = {}
4141
local VCSAdapter = oop.create_class("VCSAdapter")
4242

4343
VCSAdapter.Rev = Rev
44+
VCSAdapter.config_key = nil
4445

4546
---@class vcs.adapter.VCSAdapter.Opt
4647
---@field cpath string? # CWD path
@@ -165,9 +166,10 @@ end
165166

166167
---@diagnostic disable: unused-local, missing-return
167168

168-
---@param args string[]
169-
---@return string[]? args to show commit content
170-
function VCSAdapter:get_show_args(args)
169+
---@param path string
170+
---@param rev Rev?
171+
---@return string[] args to show commit content
172+
function VCSAdapter:get_show_args(path, rev)
171173
oop.abstract_stub()
172174
end
173175

@@ -226,27 +228,6 @@ function VCSAdapter:rev_to_args(left, right)
226228
oop.abstract_stub()
227229
end
228230

229-
---Arguments to show name and status of files
230-
---@param args string[]? Extra args
231-
---@return string[]
232-
function VCSAdapter:get_namestat_args(args)
233-
oop.abstract_stub()
234-
end
235-
236-
---Arguments to show number of changes to files
237-
---@param args string[]? Extra args
238-
---@return string[]
239-
function VCSAdapter:get_numstat_args(args)
240-
oop.abstract_stub()
241-
end
242-
243-
---Arguments to list all files
244-
---@param args string[]? Extra args
245-
---@return string[]
246-
function VCSAdapter:get_files_args(args)
247-
oop.abstract_stub()
248-
end
249-
250231
---Restore a file to the requested state
251232
---@param path string # file to restore
252233
---@param kind '"staged"'|'"working"'
@@ -299,15 +280,36 @@ function VCSAdapter:stage_index_file(file)
299280
oop.abstract_stub()
300281
end
301282

283+
---@param self VCSAdapter
284+
---@param left Rev
285+
---@param right Rev
286+
---@param args string[]
287+
---@param kind vcs.FileKind
288+
---@param opt vcs.adapter.LayoutOpt
289+
---@param callback function
290+
VCSAdapter.tracked_files = async.wrap(function(self, left, right, args, kind, opt, callback)
291+
oop.abstract_stub()
292+
end, 7)
293+
294+
---@param self VCSAdapter
295+
---@param left Rev
296+
---@param right Rev
297+
---@param opt vcs.adapter.LayoutOpt
298+
---@param callback function
299+
VCSAdapter.untracked_files = async.wrap(function(self, left, right, opt, callback)
300+
oop.abstract_stub()
301+
end, 5)
302+
302303
---@diagnostic enable: unused-local, missing-return
303304

304305
---@param self VCSAdapter
305-
---@param args string[]
306+
---@param path string
307+
---@param rev? Rev
306308
---@param callback fun(stderr: string[]?, stdout: string[]?)
307-
VCSAdapter.show = async.wrap(function(self, args, callback)
309+
VCSAdapter.show = async.wrap(function(self, path, rev, callback)
308310
local job = Job:new({
309311
command = self:bin(),
310-
args = self:get_show_args(args),
312+
args = self:get_show_args(path, rev),
311313
cwd = self.ctx.toplevel,
312314
---@type Job
313315
on_exit = async.void(function(j)
@@ -342,7 +344,7 @@ VCSAdapter.show = async.wrap(function(self, args, callback)
342344
-- silently.
343345
-- Solution: queue them and run them one after another.
344346
vcs_utils.queue_sync_job(job)
345-
end, 3)
347+
end, 4)
346348

347349
---Convert revs to string representation.
348350
---@param left Rev

lua/diffview/vcs/adapters/git/commit.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ local GitCommit = oop.create_class("GitCommit", Commit.__get())
2222

2323
function GitCommit:init(opt)
2424
GitCommit:super().init(self, opt)
25+
26+
if opt.time_offset then
27+
self.time_offset = Commit.parse_time_offset(opt.time_offset)
28+
self.time = self.time - self.time_offset
29+
else
30+
self.time_offset = 0
31+
end
32+
33+
self.iso_date = Commit.time_to_iso(self.time, self.time_offset)
2534
end
2635

2736
---@param rev_arg string

0 commit comments

Comments
 (0)