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
@@ -214,25 +215,61 @@ local function build_hunks(lines)
214
215
return hunks
215
216
end
216
217
218
+ --- @param diff_header string[]
219
+ --- @param lines string[]
220
+ --- @param hunks Hunk[]
221
+ --- @return string[][]
222
+ local function build_pager_contents (diff_header , lines , hunks )
223
+ local res = {}
224
+ local jobs = {}
225
+ vim .iter (hunks ):each (function (hunk )
226
+ local header = lines [hunk .diff_from ]
227
+ local content = vim .list_slice (lines , hunk .diff_from + 1 , hunk .diff_to )
228
+ if config .values .log_pager == nil then
229
+ insert (res , content )
230
+ return
231
+ end
232
+
233
+ local job = vim .system (config .values .log_pager , { stdin = true })
234
+ for _ , part in ipairs { diff_header , { header }, content } do
235
+ for _ , line in ipairs (part ) do
236
+ job :write (line .. " \n " )
237
+ end
238
+ end
239
+ job :write ()
240
+ insert (jobs , job )
241
+ end )
242
+
243
+ if config .values .log_pager ~= nil then
244
+ vim .iter (jobs ):each (function (job )
245
+ local content = vim .split (job :wait ().stdout , " \n " )
246
+ insert (res , content )
247
+ end )
248
+ end
249
+
250
+ return res
251
+ end
252
+
217
253
--- @param raw_diff string[]
218
254
--- @param raw_stats string[]
219
255
--- @return Diff
220
256
local function parse_diff (raw_diff , raw_stats )
221
257
local header , start_idx = build_diff_header (raw_diff )
222
258
local lines = build_lines (raw_diff , start_idx )
223
259
local hunks = build_hunks (lines )
260
+ local pager_contents = build_pager_contents (header , lines , hunks )
224
261
local kind , info = build_kind (header )
225
262
local file = build_file (header , kind )
226
263
local stats = parse_diff_stats (raw_stats or {})
227
264
228
265
return { --- @type Diff
229
- header = header ,
230
266
kind = kind ,
231
267
lines = lines ,
232
268
file = file ,
233
269
info = info ,
234
270
stats = stats ,
235
271
hunks = hunks ,
272
+ pager_contents = pager_contents ,
236
273
}
237
274
end
238
275
0 commit comments