From 456b4372adde2e2edc01143190008e36f1333b7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sindre=20T=2E=20Str=C3=B8m?= Date: Sun, 20 Nov 2022 13:46:09 +0100 Subject: [PATCH 1/2] feat(file-history): Add git-pickaxe options. --- lua/diffview/config.lua | 4 ++++ lua/diffview/vcs/adapters/git/init.lua | 26 +++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/lua/diffview/config.lua b/lua/diffview/config.lua index be7a8c64..f840e18c 100644 --- a/lua/diffview/config.lua +++ b/lua/diffview/config.lua @@ -208,6 +208,8 @@ M._config = M.defaults ---@field L string[] ---@field author string ---@field grep string +---@field G string +---@field S string ---@field diff_merges string ---@field rev_range string ---@field base string @@ -230,6 +232,8 @@ M.log_option_defaults = { diff_merges = nil, author = nil, grep = nil, + G = nil, + S = nil, path_args = {}, } diff --git a/lua/diffview/vcs/adapters/git/init.lua b/lua/diffview/vcs/adapters/git/init.lua index 6245cee7..f181263f 100644 --- a/lua/diffview/vcs/adapters/git/init.lua +++ b/lua/diffview/vcs/adapters/git/init.lua @@ -28,22 +28,22 @@ local GitAdapter = oop.create_class("GitAdapter", VCSAdapter) GitAdapter.Rev = GitRev ---@return string, string -local function pathspec_split(pathspec) +function M.pathspec_split(pathspec) local magic = pathspec:match("^:[/!^]*:?") or pathspec:match("^:%b()") or "" local pattern = pathspec:sub(1 + #magic, -1) return magic or "", pattern or "" end -local function pathspec_expand(toplevel, cwd, pathspec) - local magic, pattern = pathspec_split(pathspec) +function M.pathspec_expand(toplevel, cwd, pathspec) + local magic, pattern = M.pathspec_split(pathspec) if not utils.path:is_abs(pattern) then pattern = utils.path:join(utils.path:relative(cwd, toplevel), pattern) end return magic .. utils.path:convert(pattern) end -local function pathspec_modify(pathspec, mods) - local magic, pattern = pathspec_split(pathspec) +function M.pathspec_modify(pathspec, mods) + local magic, pattern = M.pathspec_split(pathspec) return magic .. utils.path:vim_fnamemodify(pattern, mods) end @@ -57,7 +57,7 @@ function M.get_repo_paths(path_args, cpath) for _, path_arg in ipairs(path_args) do for _, path in ipairs(pl:vim_expand(path_arg, false, true)) do - local magic, pattern = pathspec_split(path) + local magic, pattern = M.pathspec_split(path) pattern = pl:readlink(pattern) or pattern table.insert(paths, magic .. pattern) end @@ -67,7 +67,7 @@ function M.get_repo_paths(path_args, cpath) cfile = pl:readlink(cfile) or cfile for _, path in ipairs(paths) do - if pathspec_split(path) == "" then + if M.pathspec_split(path) == "" then table.insert(top_indicators, pl:absolute(path, cpath)) break end @@ -158,7 +158,7 @@ function GitAdapter:init(opt) toplevel = opt.toplevel, dir = self:get_dir(opt.toplevel), path_args = vim.tbl_map(function(pathspec) - return pathspec_expand(opt.toplevel, cwd, pathspec) + return M.pathspec_expand(opt.toplevel, cwd, pathspec) end, opt.path_args or {}) --[[@as string[] ]] } @@ -304,7 +304,9 @@ local function prepare_fh_options(adapter, log_options, single_file) o.max_count and { "-n" .. o.max_count } or nil, o.diff_merges and { "--diff-merges=" .. o.diff_merges } or nil, o.author and { "-E", "--author=" .. o.author } or nil, - o.grep and { "-E", "--grep=" .. o.grep } or nil + o.grep and { "-E", "--grep=" .. o.grep } or nil, + o.G and { "-E", "-G" .. o.G } or nil, + o.S and { "-S" .. o.S, "--pickaxe-regex" } or nil ) } end @@ -659,6 +661,8 @@ function GitAdapter:file_history_options(range, paths, args) { "author" }, { "grep" }, { "base" }, + { "G" }, + { "S" }, } ---@type LogOptions @@ -1462,6 +1466,8 @@ GitAdapter.flags = { }, { "=a", "--author=", "List only commits from a given author", prompt_label = "(Extended regular expression)" }, { "=g", "--grep=", "Filter commit messages", prompt_label = "(Extended regular expression)" }, + { "=G", "-G", "Search changes", prompt_label = "(Extended regular expression)" }, + { "=S", "-S", "Search occurrences", prompt_label = "(Extended regular expression)" }, { "--", "--", "Limit to files", key = "path_args", @@ -1672,6 +1678,8 @@ function GitAdapter:init_completion() }) self.comp.file_history:put({ "--author" }, {}) self.comp.file_history:put({ "--grep" }, {}) + self.comp.file_history:put({ "-G" }, {}) + self.comp.file_history:put({ "-S" }, {}) end M.GitAdapter = GitAdapter From fb066da8951b4ec0a96a72d8ec36668be208c3a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sindre=20T=2E=20Str=C3=B8m?= Date: Sun, 20 Nov 2022 13:54:51 +0100 Subject: [PATCH 2/2] docs: Amend docs. --- doc/diffview.txt | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/doc/diffview.txt b/doc/diffview.txt index 42b79c54..a066f0d6 100644 --- a/doc/diffview.txt +++ b/doc/diffview.txt @@ -226,12 +226,20 @@ COMMANDS *diffview-commands* --author={pattern} Limit the commits output to ones with author/committer - header lines that match the specified pattern (regular - expression). + 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). + matches the specified {pattern} (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. *:DiffviewClose* :DiffviewClose Close the active Diffview. @@ -1348,5 +1356,15 @@ LogOptions *diffview.git.LogOptions* Limit the commits output to ones with log message that matches the specified pattern (regular expression). + {G} (string) + Look for differences whose patch text contains added/removed + lines that match the specified pattern (extended regular + expression). + + {S} (string) + Look for differences that change the number of occurences of + the specified pattern (extended regular expression) in a + file. + vim:tw=78:ts=8:ft=help:norl: