@@ -32,16 +32,8 @@ struct ProductConfig {
32
32
33
33
#[ derive( Deserialize , Serialize ) ]
34
34
struct ProductVersionConfig {
35
- upstream : Option < String > ,
36
35
#[ serde( with = "utils::oid_serde" ) ]
37
36
base : Oid ,
38
- mirror : Option < String > ,
39
- }
40
-
41
- struct MergedProductVersionConfig {
42
- upstream : String ,
43
- base : Oid ,
44
- mirror : Option < String > ,
45
37
}
46
38
47
39
struct ProductVersionContext {
@@ -50,47 +42,30 @@ struct ProductVersionContext {
50
42
}
51
43
52
44
impl ProductVersionContext {
53
- fn load_product_config ( & self ) -> Result < ProductConfig > {
54
- let product_config_path = & self . product_config_path ( ) ;
55
-
45
+ fn load_config < T : for < ' de > Deserialize < ' de > > ( & self , path : & PathBuf ) -> Result < T > {
56
46
tracing:: info!(
57
- config. path = ?product_config_path ,
58
- "loading product-level config"
47
+ config. path = ?path ,
48
+ "loading config"
59
49
) ;
60
50
61
- toml:: from_str :: < ProductConfig > ( & std:: fs:: read_to_string ( product_config_path ) . context (
51
+ toml:: from_str :: < T > ( & std:: fs:: read_to_string ( path ) . context (
62
52
LoadConfigSnafu {
63
- path : product_config_path ,
53
+ path,
64
54
} ,
65
55
) ?)
66
56
. context ( ParseConfigSnafu {
67
- path : product_config_path ,
57
+ path,
68
58
} )
69
59
}
70
60
71
- fn load_version_config ( & self ) -> Result < MergedProductVersionConfig > {
72
- // Load product-level config (required)
73
- let product_config = self . load_product_config ( ) ?;
61
+ fn load_product_config ( & self ) -> Result < ProductConfig > {
62
+ let path = self . product_config_path ( ) ;
63
+ self . load_config ( & path)
64
+ }
74
65
75
- // Load version-level config (optional)
76
- let version_config_path = & self . version_config_path ( ) ;
77
- let loaded_version_config = toml:: from_str :: < ProductVersionConfig > (
78
- & std:: fs:: read_to_string ( version_config_path) . context ( LoadConfigSnafu {
79
- path : version_config_path,
80
- } ) ?,
81
- )
82
- . context ( ParseConfigSnafu {
83
- path : version_config_path,
84
- } ) ?;
85
-
86
- // Inherit `upstream` and `mirror` from product-level config if not set in loaded version-level config
87
- Ok ( MergedProductVersionConfig {
88
- upstream : loaded_version_config
89
- . upstream
90
- . unwrap_or ( product_config. upstream ) ,
91
- base : loaded_version_config. base ,
92
- mirror : loaded_version_config. mirror . or ( product_config. mirror ) ,
93
- } )
66
+ fn load_version_config ( & self ) -> Result < ProductVersionConfig > {
67
+ let path = self . version_config_path ( ) ;
68
+ self . load_config ( & path)
94
69
}
95
70
96
71
/// The root directory for files related to the product (across all versions).
@@ -334,18 +309,19 @@ fn main() -> Result<()> {
334
309
pv,
335
310
images_repo_root,
336
311
} ;
337
- let config = ctx. load_version_config ( ) ?;
312
+ let product_config = ctx. load_product_config ( ) ?;
313
+ let version_config = ctx. load_version_config ( ) ?;
338
314
let product_repo_root = ctx. product_repo ( ) ;
339
315
let product_repo = repo:: ensure_bare_repo ( & product_repo_root)
340
316
. context ( OpenProductRepoForCheckoutSnafu ) ?;
341
317
342
318
let base_commit = repo:: resolve_and_fetch_commitish (
343
319
& product_repo,
344
- & config . base . to_string ( ) ,
345
- config
320
+ & version_config . base . to_string ( ) ,
321
+ product_config
346
322
. mirror
347
323
. as_deref ( )
348
- . unwrap_or ( & config . upstream ) ,
324
+ . unwrap_or ( & product_config . upstream ) ,
349
325
)
350
326
. context ( FetchBaseCommitSnafu ) ?;
351
327
let base_branch = ctx. base_branch ( ) ;
@@ -532,8 +508,6 @@ fn main() -> Result<()> {
532
508
533
509
tracing:: info!( "saving version-level configuration" ) ;
534
510
let config = ProductVersionConfig {
535
- upstream : None ,
536
- mirror : None ,
537
511
base : base_commit,
538
512
} ;
539
513
let config_path = ctx. version_config_path ( ) ;
0 commit comments