@@ -9,7 +9,7 @@ use std::collections::BTreeSet;
9
9
impl Overlay {
10
10
/// Serve the given `refs` from memory, as if they would exist.
11
11
/// This is true only, however, if a real reference doesn't exist.
12
- pub fn with_references_non_overriding (
12
+ pub fn with_references_if_new (
13
13
mut self ,
14
14
refs : impl IntoIterator < Item = gix:: refs:: Reference > ,
15
15
) -> Self {
@@ -19,13 +19,23 @@ impl Overlay {
19
19
20
20
/// Serve the given `branches` metadata from memory, as if they would exist,
21
21
/// possibly overriding metadata of a ref that already exists.
22
- pub fn with_branch_metadata_overriding (
22
+ pub fn with_branch_metadata_override (
23
23
mut self ,
24
24
refs : impl IntoIterator < Item = ( gix:: refs:: FullName , ref_metadata:: Branch ) > ,
25
25
) -> Self {
26
26
self . meta_branches = refs. into_iter ( ) . collect ( ) ;
27
27
self
28
28
}
29
+
30
+ /// Serve the given workspace `metadata` from memory, as if they would exist,
31
+ /// possibly overriding metadata of a workspace at that place
32
+ pub fn with_workspace_metadata_override (
33
+ mut self ,
34
+ metadata : Option < ( gix:: refs:: FullName , ref_metadata:: Workspace ) > ,
35
+ ) -> Self {
36
+ self . workspace = metadata;
37
+ self
38
+ }
29
39
}
30
40
31
41
impl Overlay {
@@ -40,6 +50,7 @@ impl Overlay {
40
50
let Overlay {
41
51
nonoverriding_references,
42
52
meta_branches,
53
+ workspace,
43
54
} = self ;
44
55
(
45
56
OverlayRepo {
@@ -49,6 +60,7 @@ impl Overlay {
49
60
OverlayMetadata {
50
61
inner : meta,
51
62
meta_branches,
63
+ workspace,
52
64
} ,
53
65
)
54
66
}
@@ -209,6 +221,7 @@ impl<'repo> OverlayRepo<'repo> {
209
221
pub ( crate ) struct OverlayMetadata < ' meta , T > {
210
222
inner : & ' meta T ,
211
223
meta_branches : Vec < ( gix:: refs:: FullName , ref_metadata:: Branch ) > ,
224
+ workspace : Option < ( gix:: refs:: FullName , ref_metadata:: Workspace ) > ,
212
225
}
213
226
214
227
impl < T > OverlayMetadata < ' _ , T >
@@ -226,13 +239,30 @@ where
226
239
. ok ( )
227
240
. map ( |ws| ( ref_name, ws) )
228
241
} )
229
- . map ( |( ref_name, ws) | ( ref_name, ( * ws) . clone ( ) ) )
242
+ . map ( |( ref_name, ws) | {
243
+ if let Some ( ( _ws_ref, ws_override) ) = self
244
+ . workspace
245
+ . as_ref ( )
246
+ . filter ( |( ws_ref, _ws_data) | * ws_ref == ref_name)
247
+ {
248
+ ( ref_name, ws_override. clone ( ) )
249
+ } else {
250
+ ( ref_name, ( * ws) . clone ( ) )
251
+ }
252
+ } )
230
253
}
231
254
232
255
pub fn workspace_opt (
233
256
& self ,
234
257
ref_name : & gix:: refs:: FullNameRef ,
235
258
) -> anyhow:: Result < Option < ref_metadata:: Workspace > > {
259
+ if let Some ( ( _ws_ref, ws_meta) ) = self
260
+ . workspace
261
+ . as_ref ( )
262
+ . filter ( |( ws_ref, _ws_meta) | ws_ref. as_ref ( ) == ref_name)
263
+ {
264
+ return Ok ( Some ( ws_meta. clone ( ) ) ) ;
265
+ }
236
266
let opt = self . inner . workspace_opt ( ref_name) ?;
237
267
Ok ( opt. map ( |ws_data| ws_data. clone ( ) ) )
238
268
}
0 commit comments