@@ -22,10 +22,9 @@ use gix::{
22
22
objs:: tree:: EntryRef ,
23
23
prelude:: TreeEntryRefExt ,
24
24
traverse:: tree:: visit:: Action ,
25
- ObjectId ,
25
+ ObjectId , ThreadSafeRepository ,
26
26
} ;
27
27
use moka:: future:: Cache ;
28
- use parking_lot:: Mutex ;
29
28
use syntect:: {
30
29
parsing:: { BasicScopeStackOp , ParseState , Scope , ScopeStack , SyntaxSet , SCOPE_REPO } ,
31
30
util:: LinesWithEndings ,
@@ -71,9 +70,13 @@ impl Git {
71
70
repo_path : PathBuf ,
72
71
branch : Option < Arc < str > > ,
73
72
) -> Result < Arc < OpenRepository > > {
74
- let mut repo = tokio:: task:: spawn_blocking ( {
73
+ let repo = tokio:: task:: spawn_blocking ( {
75
74
let repo_path = repo_path. clone ( ) ;
76
- move || gix:: open ( repo_path)
75
+ move || {
76
+ gix:: open:: Options :: isolated ( )
77
+ . open_path_as_is ( true )
78
+ . open ( & repo_path)
79
+ }
77
80
} )
78
81
. await
79
82
. context ( "Failed to join Tokio task" ) ?
@@ -82,12 +85,10 @@ impl Git {
82
85
anyhow ! ( "Failed to open repository" )
83
86
} ) ?;
84
87
85
- repo. object_cache_size ( 10 * 1024 * 1024 ) ;
86
-
87
88
Ok ( Arc :: new ( OpenRepository {
88
89
git : self ,
89
90
cache_key : repo_path,
90
- repo : Mutex :: new ( repo ) ,
91
+ repo,
91
92
branch,
92
93
} ) )
93
94
}
@@ -96,7 +97,7 @@ impl Git {
96
97
pub struct OpenRepository {
97
98
git : Arc < Git > ,
98
99
cache_key : PathBuf ,
99
- repo : Mutex < gix :: Repository > ,
100
+ repo : ThreadSafeRepository ,
100
101
branch : Option < Arc < str > > ,
101
102
}
102
103
@@ -113,7 +114,7 @@ impl OpenRepository {
113
114
. context ( "Failed to parse tree hash" ) ?;
114
115
115
116
tokio:: task:: spawn_blocking ( move || {
116
- let repo = self . repo . lock ( ) ;
117
+ let repo = self . repo . to_thread_local ( ) ;
117
118
118
119
let mut tree = if let Some ( tree_id) = tree_id {
119
120
repo. find_tree ( tree_id)
@@ -213,7 +214,7 @@ impl OpenRepository {
213
214
pub async fn tag_info ( self : Arc < Self > ) -> Result < DetailedTag > {
214
215
tokio:: task:: spawn_blocking ( move || {
215
216
let tag_name = self . branch . clone ( ) . context ( "no tag given" ) ?;
216
- let repo = self . repo . lock ( ) ;
217
+ let repo = self . repo . to_thread_local ( ) ;
217
218
218
219
let tag = repo
219
220
. find_reference ( & format ! ( "refs/tags/{tag_name}" ) )
@@ -255,7 +256,7 @@ impl OpenRepository {
255
256
git. readme_cache
256
257
. try_get_with ( ( self . cache_key . clone ( ) , self . branch . clone ( ) ) , async move {
257
258
tokio:: task:: spawn_blocking ( move || {
258
- let repo = self . repo . lock ( ) ;
259
+ let repo = self . repo . to_thread_local ( ) ;
259
260
260
261
let mut head = if let Some ( reference) = & self . branch {
261
262
repo. find_reference ( reference. as_ref ( ) ) ?
@@ -306,7 +307,7 @@ impl OpenRepository {
306
307
307
308
pub async fn default_branch ( self : Arc < Self > ) -> Result < Option < String > > {
308
309
tokio:: task:: spawn_blocking ( move || {
309
- let repo = self . repo . lock ( ) ;
310
+ let repo = self . repo . to_thread_local ( ) ;
310
311
let head = repo. head ( ) . context ( "Couldn't find HEAD of repository" ) ?;
311
312
Ok ( head. referent_name ( ) . map ( |v| v. shorten ( ) . to_string ( ) ) )
312
313
} )
@@ -317,7 +318,7 @@ impl OpenRepository {
317
318
#[ instrument( skip( self ) ) ]
318
319
pub async fn latest_commit ( self : Arc < Self > , highlighted : bool ) -> Result < Commit > {
319
320
tokio:: task:: spawn_blocking ( move || {
320
- let repo = self . repo . lock ( ) ;
321
+ let repo = self . repo . to_thread_local ( ) ;
321
322
322
323
let mut head = if let Some ( reference) = & self . branch {
323
324
repo. find_reference ( reference. as_ref ( ) ) ?
@@ -354,7 +355,7 @@ impl OpenRepository {
354
355
. context ( "failed to build oid" ) ?;
355
356
356
357
tokio:: task:: spawn_blocking ( move || {
357
- let repo = self . repo . lock ( ) ;
358
+ let repo = self . repo . to_thread_local ( ) ;
358
359
359
360
let tree = if let Some ( commit) = commit {
360
361
repo. find_commit ( commit) ?. tree ( ) ?
@@ -411,7 +412,7 @@ impl OpenRepository {
411
412
git. commits
412
413
. try_get_with ( ( commit, highlighted) , async move {
413
414
tokio:: task:: spawn_blocking ( move || {
414
- let repo = self . repo . lock ( ) ;
415
+ let repo = self . repo . to_thread_local ( ) ;
415
416
416
417
let commit = repo. find_commit ( commit) ?;
417
418
0 commit comments