1
1
local a = require (" plenary.async" )
2
2
local git = require (" neogit.lib.git" )
3
3
local util = require (" neogit.lib.util" )
4
+ local config = require (" neogit.config" )
4
5
local logger = require (" neogit.logger" )
5
6
6
7
local insert = table.insert
@@ -12,13 +13,13 @@ local sha256 = vim.fn.sha256
12
13
--- @field staged_stats fun (): DiffStagedStats
13
14
---
14
15
--- @class Diff
15
- --- @field header string[]
16
16
--- @field kind string
17
17
--- @field lines string[]
18
18
--- @field file string
19
19
--- @field info table
20
20
--- @field stats table
21
21
--- @field hunks Hunk
22
+ --- @field pager_contents string[]
22
23
---
23
24
--- @class DiffStats
24
25
--- @field additions number
@@ -216,13 +217,49 @@ local function build_hunks(lines)
216
217
return hunks
217
218
end
218
219
220
+ --- @param diff_header string[]
221
+ --- @param lines string[]
222
+ --- @param hunks Hunk[]
223
+ --- @return string[][]
224
+ local function build_pager_contents (diff_header , lines , hunks )
225
+ local res = {}
226
+ local jobs = {}
227
+ vim .iter (hunks ):each (function (hunk )
228
+ local header = lines [hunk .diff_from ]
229
+ local content = vim .list_slice (lines , hunk .diff_from + 1 , hunk .diff_to )
230
+ if config .values .log_pager == nil then
231
+ insert (res , content )
232
+ return
233
+ end
234
+
235
+ local job = vim .system (config .values .log_pager , { stdin = true })
236
+ for _ , part in ipairs { diff_header , { header }, content } do
237
+ for _ , line in ipairs (part ) do
238
+ job :write (line .. " \n " )
239
+ end
240
+ end
241
+ job :write ()
242
+ insert (jobs , job )
243
+ end )
244
+
245
+ if config .values .log_pager ~= nil then
246
+ vim .iter (jobs ):each (function (job )
247
+ local content = vim .split (job :wait ().stdout , " \n " )
248
+ insert (res , content )
249
+ end )
250
+ end
251
+
252
+ return res
253
+ end
254
+
219
255
--- @param raw_diff string[]
220
256
--- @param raw_stats string[]
221
257
--- @return Diff
222
258
local function parse_diff (raw_diff , raw_stats )
223
259
local header , start_idx = build_diff_header (raw_diff )
224
260
local lines = build_lines (raw_diff , start_idx )
225
261
local hunks = build_hunks (lines )
262
+ local pager_contents = build_pager_contents (header , lines , hunks )
226
263
local kind , info = build_kind (header )
227
264
local file = build_file (header , kind )
228
265
local stats = parse_diff_stats (raw_stats or {})
@@ -233,13 +270,13 @@ local function parse_diff(raw_diff, raw_stats)
233
270
end )
234
271
235
272
return { --- @type Diff
236
- header = header ,
237
273
kind = kind ,
238
274
lines = lines ,
239
275
file = file ,
240
276
info = info ,
241
277
stats = stats ,
242
278
hunks = hunks ,
279
+ pager_contents = pager_contents ,
243
280
}
244
281
end
245
282
0 commit comments