@@ -3,10 +3,10 @@ local lazy = require("diffview.lazy")
33local DiffView = lazy .access (" diffview.scene.views.diff.diff_view" , " DiffView" ) --- @type DiffView | LazyModule
44local FileEntry = lazy .access (" diffview.scene.file_entry" , " FileEntry" ) --- @type FileEntry | LazyModule
55local FilePanel = lazy .access (" diffview.scene.views.diff.file_panel" , " FilePanel" ) --- @type FilePanel | LazyModule
6- local Rev = lazy .access (" diffview.git.rev" , " Rev " ) --- @type Rev | LazyModule
7- local RevType = lazy .access (" diffview.git .rev" , " RevType" ) --- @type RevType | LazyModule
6+ local Rev = lazy .access (" diffview.vcs.adapters. git.rev" , " GitRev " ) --- @type GitRev | LazyModule
7+ local RevType = lazy .access (" diffview.vcs .rev" , " RevType" ) --- @type RevType | LazyModule
88local async = lazy .require (" plenary.async" ) --- @module " plenary.async"
9- local git = lazy .require (" diffview.git.utils " ) --- @module " diffview.git.utils "
9+ local vcs = lazy .require (" diffview.vcs " ) --- @module " diffview.vcs "
1010local logger = lazy .require (" diffview.logger" ) --- @module " diffview.logger"
1111local oop = lazy .require (" diffview.oop" ) --- @module " diffview.oop"
1212local utils = lazy .require (" diffview.utils" ) --- @module " diffview.utils"
@@ -33,16 +33,19 @@ local CDiffView = oop.create_class("CDiffView", DiffView.__get())
3333function CDiffView :init (opt )
3434 logger .info (" [api] Creating a new Custom DiffView." )
3535 self .valid = false
36- local git_dir = git .git_dir (opt .git_root )
3736
38- if not git_dir then
37+ local err , adapter = vcs .get_adapter ({ top_indicators = { opt .git_root } })
38+
39+ if err then
3940 utils .err (
40- (" Failed to find the git dir for the repository: %s" )
41+ (" Failed to create an adapter for the repository: %s" )
4142 :format (utils .str_quote (opt .git_root ))
4243 )
4344 return
4445 end
4546
47+ --- @cast adapter -?
48+
4649 -- Fix malformed revs
4750 for _ , v in ipairs ({ " left" , " right" }) do
4851 local rev = opt [v ]
@@ -54,18 +57,13 @@ function CDiffView:init(opt)
5457 self .fetch_files = opt .update_files
5558 self .get_file_data = opt .get_file_data
5659
57- local git_ctx = {
58- toplevel = opt .git_root ,
59- dir = git_dir ,
60- }
61-
6260 CDiffView :super ().init (self , vim .tbl_extend (" force" , opt , {
63- git_ctx = git_ctx ,
61+ adapter = adapter ,
6462 panel = FilePanel (
65- git_ctx ,
63+ adapter ,
6664 self .files ,
6765 self .path_args ,
68- self .rev_arg or git . rev_to_pretty_string (opt .left , opt .right )
66+ self .rev_arg or adapter : rev_to_pretty_string (opt .left , opt .right )
6967 ),
7068 }))
7169
@@ -128,7 +126,7 @@ function CDiffView:create_file_entries(files)
128126 {
129127 kind = " staged" ,
130128 files = files .staged or {},
131- left = git . head_rev (self . git_ctx . toplevel ),
129+ left = self . adapter : head_rev (),
132130 right = Rev (RevType .STAGE , 0 ),
133131 },
134132 }
@@ -139,7 +137,7 @@ function CDiffView:create_file_entries(files)
139137 for _ , file_data in ipairs (v .files ) do
140138 if v .kind == " conflicting" then
141139 table.insert (entries [v .kind ], FileEntry .with_layout (CDiffView .get_default_merge_layout (), {
142- git_ctx = self .git_ctx ,
140+ adapter = self .adapter ,
143141 path = file_data .path ,
144142 oldpath = file_data .oldpath ,
145143 status = " U" ,
@@ -148,11 +146,10 @@ function CDiffView:create_file_entries(files)
148146 rev_main = Rev (RevType .LOCAL ),
149147 rev_theirs = Rev (RevType .STAGE , 3 ),
150148 rev_base = Rev (RevType .STAGE , 1 ),
151- get_data = self .get_file_data ,
152149 }))
153150 else
154151 table.insert (entries [v .kind ], FileEntry .for_d2 (CDiffView .get_default_diff2 (), {
155- git_ctx = self .git_ctx ,
152+ adapter = self .adapter ,
156153 path = file_data .path ,
157154 oldpath = file_data .oldpath ,
158155 status = file_data .status ,
0 commit comments