Skip to content
Merged
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
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,17 @@ require("diffview").setup({
},
file_history_panel = {
log_options = { -- See ':h diffview-config-log_options'
single_file = {
diff_merges = "combined",
git = {
single_file = {
diff_merges = "combined",
},
multi_file = {
diff_merges = "first-parent",
},
},
multi_file = {
diff_merges = "first-parent",
hg = {
single_file = {},
multi_file = {},
},
},
win_config = { -- See ':h diffview-config-win_config'
Expand Down
47 changes: 47 additions & 0 deletions doc/diffview_changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,53 @@ CHANGELOG

NOTE: This changelog only encompasses breaking changes.

*diffview.changelog-271*

PR: https://github.com/sindrets/diffview.nvim/pull/271

The config for log options has changed. In preparation of adding support of
other VCS, the table is now divided into sub-tables per VCS type. This allows
you to define different default log options for different VCS tools. To update
your config, just move all your current log options into the new table key
`git`:

Before: ~
>
require("diffview").setup({
-- ...
file_history_panel = {
log_options = {
single_file = {
max_count = 512,
follow = true,
},
multi_file = {
max_count = 128,
},
},
},
})
<

After: ~
>
require("diffview").setup({
-- ...
file_history_panel = {
log_options = {
git = {
single_file = {
max_count = 512,
follow = true,
},
multi_file = {
max_count = 128,
},
},
},
},
})
<
*diffview.changelog-190*

PR: https://github.com/sindrets/diffview.nvim/pull/190
Expand Down
14 changes: 10 additions & 4 deletions doc/diffview_defaults.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,17 @@ require("diffview").setup({
},
file_history_panel = {
log_options = { -- See |diffview-config-log_options|
single_file = {
diff_merges = "combined",
git = {
single_file = {
diff_merges = "combined",
},
multi_file = {
diff_merges = "first-parent",
},
},
multi_file = {
diff_merges = "first-parent",
hg = {
single_file = {},
multi_file = {},
},
},
win_config = { -- See |diffview-config-win_config|
Expand Down
107 changes: 68 additions & 39 deletions lua/diffview/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,20 @@ M.defaults = {
},
},
file_history_panel = {
---@type ConfigLogOptions
log_options = {
single_file = {
diff_merges = "combined",
---@type ConfigLogOptions
git = {
single_file = {
diff_merges = "combined",
},
multi_file = {
diff_merges = "first-parent",
},
},
multi_file = {
diff_merges = "first-parent",
---@type ConfigLogOptions
hg = {
single_file = {},
multi_file = {},
},
},
win_config = {
Expand Down Expand Up @@ -216,7 +223,7 @@ M.defaults = {
M.user_emitter = EventEmitter()
M._config = M.defaults

---@class LogOptions
---@class GitLogOptions
---@field follow boolean
---@field first_parent boolean
---@field show_pulls boolean
Expand All @@ -236,26 +243,34 @@ M._config = M.defaults
---@field base string
---@field path_args string[]

---@type LogOptions
---@class HgLogOptions

---@alias LogOptions GitLogOptions|HgLogOptions

M.log_option_defaults = {
follow = false,
first_parent = false,
show_pulls = false,
reflog = false,
all = false,
merges = false,
no_merges = false,
reverse = false,
rev_range = nil,
base = nil,
max_count = 256,
L = {},
diff_merges = nil,
author = nil,
grep = nil,
G = nil,
S = nil,
path_args = {},
---@type GitLogOptions
git = {
follow = false,
first_parent = false,
show_pulls = false,
reflog = false,
all = false,
merges = false,
no_merges = false,
reverse = false,
rev_range = nil,
base = nil,
max_count = 256,
L = {},
diff_merges = nil,
author = nil,
grep = nil,
G = nil,
S = nil,
path_args = {},
},
---@type HgLogOptions
hg = {},
}

---@return DiffviewConfig
Expand All @@ -268,15 +283,16 @@ function M.get_config()
end

---@param single_file boolean
---@param t LogOptions
---@return LogOptions
function M.get_log_options(single_file, t)
---@param t GitLogOptions|HgLogOptions
---@param vcs "git"|"hg"
---@return GitLogOptions|HgLogOptions
function M.get_log_options(single_file, t, vcs)
local log_options

if single_file then
log_options = M._config.file_history_panel.log_options.single_file
log_options = M._config.file_history_panel.log_options[vcs].single_file
else
log_options = M._config.file_history_panel.log_options.multi_file
log_options = M._config.file_history_panel.log_options[vcs].multi_file
end

if t then
Expand Down Expand Up @@ -452,6 +468,17 @@ function M.setup(user_config)

local user_log_options = utils.tbl_access(user_config, "file_history_panel.log_options")
if user_log_options then
local top_options = {
"single_file",
"multi_file",
}
for _, name in ipairs(top_options) do
if user_log_options[name] ~= nil then
utils.warn("Global config of 'file_panel.log_options' has been deprecated. See ':h diffview.changelog-271'.")
end
break
end

local option_names = {
"max_count",
"follow",
Expand Down Expand Up @@ -508,15 +535,17 @@ function M.setup(user_config)
end

for _, name in ipairs({ "single_file", "multi_file" }) do
local t = M._config.file_history_panel.log_options
t[name] = vim.tbl_extend(
"force",
M.log_option_defaults,
t[name]
)
for k, _ in pairs(t[name]) do
if t[name][k] == "" then
t[name][k] = nil
for _, vcs in ipairs({ "git", "hg" }) do
local t = M._config.file_history_panel.log_options[vcs]
t[name] = vim.tbl_extend(
"force",
M.log_option_defaults[vcs],
t[name]
)
for k, _ in pairs(t[name]) do
if t[name][k] == "" then
t[name][k] = nil
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lua/diffview/scene/views/file_history/file_history_panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ function FileHistoryPanel:init(opt)
self.log_options = {
single_file = vim.tbl_extend(
"force",
conf.file_history_panel.log_options.single_file,
conf.file_history_panel.log_options[self.adapter.config_key].single_file,
opt.log_options
),
multi_file = vim.tbl_extend(
"force",
conf.file_history_panel.log_options.multi_file,
conf.file_history_panel.log_options[self.adapter.config_key].multi_file,
opt.log_options
),
}
Expand Down
58 changes: 30 additions & 28 deletions lua/diffview/vcs/adapter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ local M = {}
local VCSAdapter = oop.create_class("VCSAdapter")

VCSAdapter.Rev = Rev
VCSAdapter.config_key = nil

---@class vcs.adapter.VCSAdapter.Opt
---@field cpath string? # CWD path
Expand Down Expand Up @@ -165,9 +166,10 @@ end

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

---@param args string[]
---@return string[]? args to show commit content
function VCSAdapter:get_show_args(args)
---@param path string
---@param rev Rev?
---@return string[] args to show commit content
function VCSAdapter:get_show_args(path, rev)
oop.abstract_stub()
end

Expand Down Expand Up @@ -226,27 +228,6 @@ function VCSAdapter:rev_to_args(left, right)
oop.abstract_stub()
end

---Arguments to show name and status of files
---@param args string[]? Extra args
---@return string[]
function VCSAdapter:get_namestat_args(args)
oop.abstract_stub()
end

---Arguments to show number of changes to files
---@param args string[]? Extra args
---@return string[]
function VCSAdapter:get_numstat_args(args)
oop.abstract_stub()
end

---Arguments to list all files
---@param args string[]? Extra args
---@return string[]
function VCSAdapter:get_files_args(args)
oop.abstract_stub()
end

---Restore a file to the requested state
---@param path string # file to restore
---@param kind '"staged"'|'"working"'
Expand Down Expand Up @@ -299,15 +280,36 @@ function VCSAdapter:stage_index_file(file)
oop.abstract_stub()
end

---@param self VCSAdapter
---@param left Rev
---@param right Rev
---@param args string[]
---@param kind vcs.FileKind
---@param opt vcs.adapter.LayoutOpt
---@param callback function
VCSAdapter.tracked_files = async.wrap(function(self, left, right, args, kind, opt, callback)
oop.abstract_stub()
end, 7)

---@param self VCSAdapter
---@param left Rev
---@param right Rev
---@param opt vcs.adapter.LayoutOpt
---@param callback function
VCSAdapter.untracked_files = async.wrap(function(self, left, right, opt, callback)
oop.abstract_stub()
end, 5)

---@diagnostic enable: unused-local, missing-return

---@param self VCSAdapter
---@param args string[]
---@param path string
---@param rev? Rev
---@param callback fun(stderr: string[]?, stdout: string[]?)
VCSAdapter.show = async.wrap(function(self, args, callback)
VCSAdapter.show = async.wrap(function(self, path, rev, callback)
local job = Job:new({
command = self:bin(),
args = self:get_show_args(args),
args = self:get_show_args(path, rev),
cwd = self.ctx.toplevel,
---@type Job
on_exit = async.void(function(j)
Expand Down Expand Up @@ -342,7 +344,7 @@ VCSAdapter.show = async.wrap(function(self, args, callback)
-- silently.
-- Solution: queue them and run them one after another.
vcs_utils.queue_sync_job(job)
end, 3)
end, 4)

---Convert revs to string representation.
---@param left Rev
Expand Down
9 changes: 9 additions & 0 deletions lua/diffview/vcs/adapters/git/commit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ local GitCommit = oop.create_class("GitCommit", Commit.__get())

function GitCommit:init(opt)
GitCommit:super().init(self, opt)

if opt.time_offset then
self.time_offset = Commit.parse_time_offset(opt.time_offset)
self.time = self.time - self.time_offset
else
self.time_offset = 0
end

self.iso_date = Commit.time_to_iso(self.time, self.time_offset)
end

---@param rev_arg string
Expand Down
Loading