Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c005e5d
feat: implement FileHistory for hg
zegervdv Nov 1, 2022
89c9556
feat: implement diffview for hg
zegervdv Nov 19, 2022
3410b70
fix: handle no tracked files changed
zegervdv Dec 21, 2022
71f0518
fix: handle null base rev
zegervdv Dec 21, 2022
5850136
WIP: Amend docs
sindrets Dec 21, 2022
b5c8a0d
fix: correct order of flag options
zegervdv Dec 21, 2022
463f60a
fix: only set oldname when a file is renamed
zegervdv Dec 21, 2022
264929e
fix: only walk the mergestate data once
zegervdv Dec 21, 2022
0ed37cb
feat: add log args for hg
zegervdv Dec 21, 2022
6ee4efa
feat: add to_range for hg revs
zegervdv Jan 4, 2023
eec216e
fixup! feat: add log args for hg
zegervdv Jan 17, 2023
bbca98d
feat: add get_merge_context for hg
zegervdv Jan 17, 2023
7298a7f
doc: list hg options and refer to documentation where possible
zegervdv Jan 17, 2023
5175646
feat: add file_restore for hg
zegervdv Jan 17, 2023
4a5b609
fix review comments
zegervdv Jan 25, 2023
b267549
fix: update flags
zegervdv Jan 25, 2023
9c6c81d
fix: return first ancestorlinknode as merge-base
zegervdv Jan 27, 2023
dafbf1a
fix: use direct arguments to indicate range (WIP)
zegervdv Jan 27, 2023
c0e80ed
fixup! fix: use direct arguments to indicate range (WIP)
zegervdv Feb 2, 2023
20f9698
fixup! fix: use direct arguments to indicate range (WIP)
zegervdv Feb 2, 2023
e3db8f4
fixup! fix: use direct arguments to indicate range (WIP)
zegervdv Feb 2, 2023
868090e
fix: handle empty files
zegervdv Feb 8, 2023
e84d44f
fixup! fix: use direct arguments to indicate range (WIP)
zegervdv Feb 14, 2023
f03052e
feat: add rev completion
zegervdv Feb 14, 2023
0cd8fb8
fix: match file names from numstat output correctly
zegervdv Feb 15, 2023
673b58f
fix: return error message from HgAdapter.create
zegervdv Feb 16, 2023
660ec69
fix: address review comments
zegervdv Feb 19, 2023
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
143 changes: 99 additions & 44 deletions doc/diffview.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,75 +179,120 @@ COMMANDS *diffview-commands*
:'<,'>DiffviewFileHistory
<

Options: ~
What options are available will be determined by what type of repository
you're targeting. You will find the available options for the supported
VCS tools below. The command completion will do it's best to suggest the
appropriate options.

Git Options: ~
--base={git-rev}
Specify a base git rev from which the right side of
the diff will be created. Use the special value
`LOCAL` to use the local version of the file.
Specify a base git rev from which the right side of the diff
will be created. Use the special value `LOCAL` to use the
local version of the file.

--range={git-rev}
Show only commits in the specified revision range.
Show only commits in the specified revision range.

-C{path} Run as if git was started in {path} instead of the
current working directory.
-C{path}
Run as if git was started in {path} instead of the current
working directory.

NOTE: All following options are described in far more detail in the
man page for git-log. See `:Man git-log(1)` for more information.

--follow Follow renames (only for single file).
--follow
Follow renames (only for single file).

--first-parent Follow only the first parent upon seeing a merge
commit.
--first-parent
Follow only the first parent upon seeing a merge commit.

--show-pulls Show merge commits that are not TREESAME to its first
parent, but are to a later parent.
--show-pulls
Show merge commits that are not TREESAME to its first parent,
but are to a later parent.

--reflog Include all reachable objects mentioned by reflogs.
--reflog
Include all reachable objects mentioned by reflogs.

--all Include all refs.
--all Include all refs.

--merges List only merge commits.
--merges
List only merge commits.

--no-merges List no merge commits.
--no-merges
List no merge commits.

--reverse List commits in reverse order.
--reverse
List commits in reverse order.

-n{n}, --max-count={n}
Limit the number of commits.
Limit the number of commits.

-L{start},{end}:{file}, -L:{funcname}:{file}
Trace the evolution of the line range given by
{start},{end}, or by the function name regex
{funcname}, within the {file}. You can specify this
option more than once.
Trace the evolution of the line range given by {start},{end},
or by the function name regex {funcname}, within the {file}.
You can specify this option more than once.

--diff-merges={value}
Determines how merge commits are treated. {value} can
be one of:
• `off`
• `on`
• `first-parent`
• `separate`
• `combined`
• `dense-combined`
• `remerge`
Determines how merge commits are treated. {value} can
be one of:
• `off`
• `on`
• `first-parent`
• `separate`
• `combined`
• `dense-combined`
• `remerge`

--author={pattern}
Limit the commits output to ones with author/committer
header lines that match the specified {pattern}
(regular expression).
Limit the commits output to ones with author/committer header
lines that match the specified {pattern} (regular expression).

--grep={pattern}
Limit the commits output to ones with log message that
matches the specified {pattern} (regular expression).
Limit the commits output to ones with log message that matches
the specified {pattern} (regular expression).

-G{pattern} Look for differences whose patch text contains
added/removed lines that match {pattern} (extended
regular expression).
-G{pattern}
Look for differences whose patch text contains added/removed
lines that match {pattern} (extended regular expression).

-S{pattern} Look for differences that change the number of
occurences of the specified {pattern} (extended
regular expression) in a file.
-S{pattern}
Look for differences that change the number of occurences of
the specified {pattern} (extended regular expression) in a
file.

Mercurial Options: ~

--rev={rev}
Show only commits for the specified revset {rev}.
See `hg help revsets` for the full list of keywords and
constructs.

-f, --follow
Follow renames (only for single file).

-l{n}, --limit={n}
Limit the number of commits.

-M, --no-merges
Do not list merge commits.

--user={text}
Limit the commits to ones with user as specified.

--keyword={text}
Limit commits to ones matching the {text} in the log message.

--branch={text}
Limit commits to a specified branch.

--bookmark={text}
Limit commits to a specified bookmark

--include={pattern}
Include commits touching files as specified in the {pattern}.

--exclude={pattern}
Exclude commits touching files as specified in the {pattern}.

*:DiffviewClose*
:DiffviewClose Close the active Diffview.
Expand Down Expand Up @@ -285,10 +330,20 @@ enhanced_diff_hl *diffview-config-enhanced_diff_h
git_cmd *diffview-config-git_cmd*
Type: `string[]`, Default: `{ "git" }`

This table forms the first part of all git commands used internally in
the plugin. The first element should be the git binary. The subsequent
This table forms the first part of all Git commands used internally in
the plugin. The first element should be the Git binary. The subsequent
elements are passed as arguments.

hg_cmd *diffview-config-hg_cmd*
Type: `string[]`, Default: `{ "hg" }`

This table forms the first part of all Mercurial commands used
internally in the plugin. The first element should be the Mercurial
binary. The subsequent elements are passed as arguments.

If your Mercurial install bundles the `chg` binary, this can be
configured here to have a significant performance boost.

view.x.layout *diffview-config-view.x.layout*
Type: >
"diff1_plain"
Expand Down
18 changes: 17 additions & 1 deletion lua/diffview/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ M.defaults = {
diff_binaries = false,
enhanced_diff_hl = false,
git_cmd = { "git" },
hg_cmd = { "hg" },
use_icons = true,
show_help_hints = true,
watch_index = true,
Expand Down Expand Up @@ -247,6 +248,13 @@ M._config = M.defaults
---@field path_args string[]

---@class HgLogOptions
---@field limit integer
---@field user string
---@field no_merges boolean
---@field rev string
---@field keyword string
---@field include string
---@field exclude string

---@alias LogOptions GitLogOptions|HgLogOptions

Expand All @@ -273,7 +281,15 @@ M.log_option_defaults = {
path_args = {},
},
---@type HgLogOptions
hg = {},
hg = {
limit = 256,
user = nil,
no_merges = false,
rev = nil,
keyword = nil,
include = nil,
exclude = nil,
},
}

---@return DiffviewConfig
Expand Down
3 changes: 2 additions & 1 deletion lua/diffview/scene/views/diff/diff_view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ local debounce = lazy.require("diffview.debounce") ---@module "diffview.debounce
local logger = lazy.require("diffview.logger") ---@module "diffview.logger"
local utils = lazy.require("diffview.utils") ---@module "diffview.utils"
local vcs_utils = lazy.require("diffview.vcs.utils") ---@module "diffview.vcs.utils"
local GitAdapter = lazy.access("diffview.vcs.adapters.git", "GitAdapter") ---@type GitAdapter|LazyModule

local api = vim.api
local M = {}
Expand Down Expand Up @@ -125,7 +126,7 @@ function DiffView:post_open()
name = ("diffview://%s/log/%d/%s"):format(self.adapter.ctx.dir, self.tabpage, "commit_log"),
})

if config.get_config().watch_index then
if config.get_config().watch_index and self.adapter:instanceof(GitAdapter.__get()) then
self.watcher = vim.loop.new_fs_poll()
---@diagnostic disable-next-line: unused-local
self.watcher:start(self.adapter.ctx.dir .. "/index", 1000, function(err, prev, cur)
Expand Down
2 changes: 1 addition & 1 deletion lua/diffview/scene/views/file_history/listeners.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ return function(view)
local log_options = view.panel:get_log_options()
local cur = view.panel:cur_file()

if log_options.L[1] and bufnr == cur.layout:get_main_win().file.bufnr then
if log_options.L and log_options.L[1] and bufnr == cur.layout:get_main_win().file.bufnr then
for _, value in ipairs(log_options.L) do
local l1, lpath = value:match("^(%d+),.*:(.*)")

Expand Down
2 changes: 1 addition & 1 deletion lua/diffview/vcs/adapter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ VCSAdapter.show = async.wrap(function(self, path, rev, callback)
cwd = self.ctx.toplevel,
---@type Job
on_exit = async.void(function(j)
local context = "vcs.utils.show()"
local context = "VCSAdapter.show()"
utils.handle_job(j, {
fail_on_empty = true,
context = context,
Expand Down
42 changes: 42 additions & 0 deletions lua/diffview/vcs/adapters/hg/commit.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
local lazy = require("diffview.lazy")
local oop = require('diffview.oop')
local utils = require("diffview.utils")
local Commit = require('diffview.vcs.commit').Commit

local M = {}

---@class HgCommit : Commit
local HgCommit = oop.create_class('HgCommit', Commit)

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

if opt.time_offset then
self.time_offset = HgCommit.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 iso_date string?
function HgCommit.parse_time_offset(iso_date)
if not iso_date or iso_date == "" then
return 0
end

local sign, offset = vim.trim(iso_date):match("([+-])(%d+)")

offset = tonumber(offset)

if sign == "-" then
offset = -offset
end

return offset
end

M.HgCommit = HgCommit
return M
Loading