Skip to content

Commit

Permalink
fix(git_status): use -z over --porcelain
Browse files Browse the repository at this point in the history
`-z` is more machine parse-able than `--porcelain`.
But this requires splitting NUL delimited entries. Adds support for this
in `async_oneshot_finder`/`LinesPipe`
  • Loading branch information
jamestrew committed Sep 22, 2024
1 parent b5fd7f7 commit 20d3ced
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
13 changes: 6 additions & 7 deletions lua/telescope/_.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,9 @@ function LinesPipe:read()
return read_rx()
end

function LinesPipe:iter(schedule)
if schedule == nil then
schedule = true
end
function LinesPipe:iter(schedule, opts)
schedule = vim.F.if_nil(schedule, true)
local split_char = vim.F.if_nil(opts.split_char, "\n")

local text = nil
local index = nil
Expand All @@ -167,8 +166,7 @@ function LinesPipe:iter(schedule)
return (previous or "") .. read
end

local next_value = nil
next_value = function()
local function next_value()
if schedule then
async.util.scheduler()
end
Expand All @@ -178,7 +176,7 @@ function LinesPipe:iter(schedule)
end

local start = index
index = string.find(text, "\n", index, true)
index = string.find(text, split_char, index, true)

if index == nil then
text = get_next_text(string.sub(text, start or 1))
Expand Down Expand Up @@ -267,6 +265,7 @@ end

M.NullPipe = NullPipe
M.LinesPipe = LinesPipe
M.NulLinesPipe = NulLinesPipe
M.ChunkPipe = ChunkPipe
M.ErrorPipe = ErrorPipe

Expand Down
3 changes: 2 additions & 1 deletion lua/telescope/builtin/__git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,15 @@ git.status = function(opts)
return
end

local args = { "status", "--porcelain=v1", "--", "." }
local args = { "status", "-z", "--", "." }

local gen_new_finder = function()
if vim.F.if_nil(opts.expand_dir, true) then
table.insert(args, #args - 1, "-uall")
end
local git_cmd = git_command(args, opts)
opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_status(opts))
opts.split_char = "\0"
return finders.new_oneshot_job(git_cmd, opts)
end

Expand Down
1 change: 1 addition & 0 deletions lua/telescope/finders.lua
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ finders.new_oneshot_job = function(command_list, opts)

cwd = opts.cwd,
maximum_results = opts.maximum_results,
split_char = opts.split_char,

fn_command = function()
return {
Expand Down
2 changes: 1 addition & 1 deletion lua/telescope/finders/async_oneshot_finder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ return function(opts)
process_result(v)
end
end
for line in stdout:iter(false) do
for line in stdout:iter(false, { split_char = opts.split_char }) do
num_results = num_results + 1

if num_results % await_count then
Expand Down

0 comments on commit 20d3ced

Please sign in to comment.