1- local oop = require (' diffview.oop' )
2- local utils = require (' diffview.utils' )
3- local logger = require (' diffview.logger' )
4- local arg_parser = require (' diffview.arg_parser' )
5- local RevType = require (" diffview.vcs.rev" ).RevType
6- local Rev = require (" diffview.vcs.rev" ).Rev
1+ local Job = require (" plenary.job" )
2+ local async = require (" plenary.async" )
3+ local lazy = require (" diffview.lazy" )
4+ local oop = require (" diffview.oop" )
5+
6+ local JobStatus = lazy .access (" diffview.vcs.utils" , " JobStatus" ) --- @type JobStatus | LazyModule
7+ local Rev = lazy .access (" diffview.vcs.rev" , " Rev" ) --- @type Rev | LazyModule
8+ local RevType = lazy .access (" diffview.vcs.rev" , " RevType" ) --- @type RevType | LazyModule
9+ local arg_parser = lazy .require (" diffview.arg_parser" ) --- @module " diffview.arg_parser"
10+ local logger = lazy .require (" diffview.logger" ) --- @module " diffview.logger"
11+ local utils = lazy .require (" diffview.utils" ) --- @module " diffview.utils"
12+ local vcs_utils = lazy .require (" diffview.vcs.utils" ) --- @module " diffview.vcs.utils"
713
814local M = {}
915
1016--- @class vcs.adapter.LayoutOpt
1117--- @field default_layout Diff2
1218--- @field merge_layout Layout
1319
14-
1520--- @class vcs.adapter.VCSAdapter.Bootstrap
1621--- @field done boolean # Did the bootstrapping
1722--- @field ok boolean # Bootstrapping was successful
@@ -33,7 +38,7 @@ local M = {}
3338--- @field bootstrap vcs.adapter.VCSAdapter.Bootstrap
3439--- @field ctx vcs.adapter.VCSAdapter.Ctx
3540--- @field flags vcs.adapter.VCSAdapter.Flags
36- local VCSAdapter = oop .create_class (' VCSAdapter' )
41+ local VCSAdapter = oop .create_class (" VCSAdapter" )
3742
3843VCSAdapter .Rev = Rev
3944
@@ -271,15 +276,59 @@ end
271276
272277--- Restore file
273278--- @param path string
274- --- @param kind ' "staged" ' | ' "working" '
279+ --- @param kind vcs.FileKind
275280--- @param commit string ?
276- --- @return boolean # Restore was successful
281+ --- @return boolean success
282+ --- @return string ? undo # If the adapter supports it: a command that will undo the restoration.
277283function VCSAdapter :file_restore (path , kind , commit )
278284 oop .abstract_stub ()
279285end
280286
281287--- @diagnostic enable : unused-local , missing-return
282288
289+ --- @param self VCSAdapter
290+ --- @param args string[]
291+ --- @param callback fun ( stderr : string[] ?, stdout : string[] ?)
292+ VCSAdapter .show = async .wrap (function (self , args , callback )
293+ local job = Job :new ({
294+ command = self :bin (),
295+ args = self :get_show_args (args ),
296+ cwd = self .ctx .toplevel ,
297+ --- @type Job
298+ on_exit = async .void (function (j )
299+ local context = " vcs.utils.show()"
300+ utils .handle_job (j , {
301+ fail_on_empty = true ,
302+ context = context ,
303+ debug_opt = { no_stdout = true , context = context },
304+ })
305+
306+ if j .code ~= 0 then
307+ callback (j :stderr_result () or {}, nil )
308+ return
309+ end
310+
311+ local out_status
312+
313+ if # j :result () == 0 then
314+ async .util .scheduler ()
315+ out_status = vcs_utils .ensure_output (2 , { j }, context )
316+ end
317+
318+ if out_status == JobStatus .ERROR then
319+ callback (j :stderr_result () or {}, nil )
320+ return
321+ end
322+
323+ callback (nil , j :result ())
324+ end ),
325+ })
326+ -- Problem: Running multiple 'show' jobs simultaneously may cause them to fail
327+ -- silently.
328+ -- Solution: queue them and run them one after another.
329+ vcs_utils .queue_sync_job (job )
330+ end , 3 )
331+
283332--- Convert revs to string representation.
284333--- @param left Rev
285334--- @param right Rev
0 commit comments