Skip to content

Commit d2d9b18

Browse files
authored
feat(file-history): Add git-pickaxe options. (#254)
1 parent fee19c5 commit d2d9b18

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

doc/diffview.txt

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,20 @@ COMMANDS *diffview-commands*
226226

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

232232
--grep={pattern}
233233
Limit the commits output to ones with log message that
234-
matches the specified pattern (regular expression).
234+
matches the specified {pattern} (regular expression).
235+
236+
-G{pattern} Look for differences whose patch text contains
237+
added/removed lines that match {pattern} (extended
238+
regular expression).
239+
240+
-S{pattern} Look for differences that change the number of
241+
occurences of the specified {pattern} (extended
242+
regular expression) in a file.
235243

236244
*:DiffviewClose*
237245
:DiffviewClose Close the active Diffview.
@@ -1348,5 +1356,15 @@ LogOptions *diffview.git.LogOptions*
13481356
Limit the commits output to ones with log message that matches
13491357
the specified pattern (regular expression).
13501358

1359+
{G} (string)
1360+
Look for differences whose patch text contains added/removed
1361+
lines that match the specified pattern (extended regular
1362+
expression).
1363+
1364+
{S} (string)
1365+
Look for differences that change the number of occurences of
1366+
the specified pattern (extended regular expression) in a
1367+
file.
1368+
13511369

13521370
vim:tw=78:ts=8:ft=help:norl:

lua/diffview/config.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ M._config = M.defaults
208208
---@field L string[]
209209
---@field author string
210210
---@field grep string
211+
---@field G string
212+
---@field S string
211213
---@field diff_merges string
212214
---@field rev_range string
213215
---@field base string
@@ -230,6 +232,8 @@ M.log_option_defaults = {
230232
diff_merges = nil,
231233
author = nil,
232234
grep = nil,
235+
G = nil,
236+
S = nil,
233237
path_args = {},
234238
}
235239

lua/diffview/vcs/adapters/git/init.lua

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,22 @@ local GitAdapter = oop.create_class("GitAdapter", VCSAdapter)
2828
GitAdapter.Rev = GitRev
2929

3030
---@return string, string
31-
local function pathspec_split(pathspec)
31+
function M.pathspec_split(pathspec)
3232
local magic = pathspec:match("^:[/!^]*:?") or pathspec:match("^:%b()") or ""
3333
local pattern = pathspec:sub(1 + #magic, -1)
3434
return magic or "", pattern or ""
3535
end
3636

37-
local function pathspec_expand(toplevel, cwd, pathspec)
38-
local magic, pattern = pathspec_split(pathspec)
37+
function M.pathspec_expand(toplevel, cwd, pathspec)
38+
local magic, pattern = M.pathspec_split(pathspec)
3939
if not utils.path:is_abs(pattern) then
4040
pattern = utils.path:join(utils.path:relative(cwd, toplevel), pattern)
4141
end
4242
return magic .. utils.path:convert(pattern)
4343
end
4444

45-
local function pathspec_modify(pathspec, mods)
46-
local magic, pattern = pathspec_split(pathspec)
45+
function M.pathspec_modify(pathspec, mods)
46+
local magic, pattern = M.pathspec_split(pathspec)
4747
return magic .. utils.path:vim_fnamemodify(pattern, mods)
4848
end
4949

@@ -57,7 +57,7 @@ function M.get_repo_paths(path_args, cpath)
5757

5858
for _, path_arg in ipairs(path_args) do
5959
for _, path in ipairs(pl:vim_expand(path_arg, false, true)) do
60-
local magic, pattern = pathspec_split(path)
60+
local magic, pattern = M.pathspec_split(path)
6161
pattern = pl:readlink(pattern) or pattern
6262
table.insert(paths, magic .. pattern)
6363
end
@@ -67,7 +67,7 @@ function M.get_repo_paths(path_args, cpath)
6767
cfile = pl:readlink(cfile) or cfile
6868

6969
for _, path in ipairs(paths) do
70-
if pathspec_split(path) == "" then
70+
if M.pathspec_split(path) == "" then
7171
table.insert(top_indicators, pl:absolute(path, cpath))
7272
break
7373
end
@@ -158,7 +158,7 @@ function GitAdapter:init(opt)
158158
toplevel = opt.toplevel,
159159
dir = self:get_dir(opt.toplevel),
160160
path_args = vim.tbl_map(function(pathspec)
161-
return pathspec_expand(opt.toplevel, cwd, pathspec)
161+
return M.pathspec_expand(opt.toplevel, cwd, pathspec)
162162
end, opt.path_args or {}) --[[@as string[] ]]
163163
}
164164

@@ -304,7 +304,9 @@ local function prepare_fh_options(adapter, log_options, single_file)
304304
o.max_count and { "-n" .. o.max_count } or nil,
305305
o.diff_merges and { "--diff-merges=" .. o.diff_merges } or nil,
306306
o.author and { "-E", "--author=" .. o.author } or nil,
307-
o.grep and { "-E", "--grep=" .. o.grep } or nil
307+
o.grep and { "-E", "--grep=" .. o.grep } or nil,
308+
o.G and { "-E", "-G" .. o.G } or nil,
309+
o.S and { "-S" .. o.S, "--pickaxe-regex" } or nil
308310
)
309311
}
310312
end
@@ -659,6 +661,8 @@ function GitAdapter:file_history_options(range, paths, args)
659661
{ "author" },
660662
{ "grep" },
661663
{ "base" },
664+
{ "G" },
665+
{ "S" },
662666
}
663667

664668
---@type LogOptions
@@ -1462,6 +1466,8 @@ GitAdapter.flags = {
14621466
},
14631467
{ "=a", "--author=", "List only commits from a given author", prompt_label = "(Extended regular expression)" },
14641468
{ "=g", "--grep=", "Filter commit messages", prompt_label = "(Extended regular expression)" },
1469+
{ "=G", "-G", "Search changes", prompt_label = "(Extended regular expression)" },
1470+
{ "=S", "-S", "Search occurrences", prompt_label = "(Extended regular expression)" },
14651471
{
14661472
"--", "--", "Limit to files",
14671473
key = "path_args",
@@ -1672,6 +1678,8 @@ function GitAdapter:init_completion()
16721678
})
16731679
self.comp.file_history:put({ "--author" }, {})
16741680
self.comp.file_history:put({ "--grep" }, {})
1681+
self.comp.file_history:put({ "-G" }, {})
1682+
self.comp.file_history:put({ "-S" }, {})
16751683
end
16761684

16771685
M.GitAdapter = GitAdapter

0 commit comments

Comments
 (0)