@@ -9,11 +9,11 @@ use tracing_subscriber::FmtSubscriber;
99
1010use sbuild_meta:: {
1111 hash:: { compute_recipe_hash, compute_recipe_hash_excluding_version} ,
12- recipe:: { scan_recipes, filter_by_arch, filter_enabled, SBuildRecipe } ,
13- registry:: RegistryClient ,
1412 manifest:: OciManifest ,
1513 metadata:: PackageMetadata ,
16- Result , Error ,
14+ recipe:: { filter_by_arch, filter_enabled, scan_recipes, SBuildRecipe } ,
15+ registry:: RegistryClient ,
16+ Error , Result ,
1717} ;
1818
1919#[ derive( Parser ) ]
@@ -22,7 +22,7 @@ use sbuild_meta::{
2222#[ command( version) ]
2323struct Cli {
2424 /// Log level (error, warn, info, debug, trace)
25- #[ arg( long, default_value = "info " ) ]
25+ #[ arg( long, default_value = "trace " ) ]
2626 log_level : String ,
2727
2828 #[ command( subcommand) ]
@@ -150,8 +150,7 @@ fn setup_logging(level: &str) {
150150 . compact ( )
151151 . finish ( ) ;
152152
153- tracing:: subscriber:: set_global_default ( subscriber)
154- . expect ( "Failed to set tracing subscriber" ) ;
153+ tracing:: subscriber:: set_global_default ( subscriber) . expect ( "Failed to set tracing subscriber" ) ;
155154}
156155
157156#[ tokio:: main]
@@ -170,42 +169,44 @@ async fn main() -> Result<()> {
170169 github_token,
171170 ghcr_owner,
172171 } => {
173- cmd_generate ( arch, recipes, output, cache_type, cache, parallel, github_token, ghcr_owner) . await
172+ cmd_generate (
173+ arch,
174+ recipes,
175+ output,
176+ cache_type,
177+ cache,
178+ parallel,
179+ github_token,
180+ ghcr_owner,
181+ )
182+ . await
174183 }
175184
176185 Commands :: ShouldRebuild {
177186 recipe,
178187 cache,
179188 force,
180- } => {
181- cmd_should_rebuild ( recipe, cache, force) . await
182- }
189+ } => cmd_should_rebuild ( recipe, cache, force) . await ,
183190
184191 Commands :: CheckUpdates {
185192 recipes,
186193 cache,
187194 output,
188195 parallel,
189196 timeout,
190- } => {
191- cmd_check_updates ( recipes, cache, output, parallel, timeout) . await
192- }
197+ } => cmd_check_updates ( recipes, cache, output, parallel, timeout) . await ,
193198
194199 Commands :: Hash {
195200 recipe,
196201 exclude_version,
197- } => {
198- cmd_hash ( recipe, exclude_version)
199- }
202+ } => cmd_hash ( recipe, exclude_version) ,
200203
201204 Commands :: FetchManifest {
202205 repository,
203206 tag,
204207 arch,
205208 github_token,
206- } => {
207- cmd_fetch_manifest ( repository, tag, arch, github_token) . await
208- }
209+ } => cmd_fetch_manifest ( repository, tag, arch, github_token) . await ,
209210 }
210211}
211212
@@ -219,7 +220,10 @@ async fn cmd_generate(
219220 github_token : Option < String > ,
220221 ghcr_owner : String ,
221222) -> Result < ( ) > {
222- info ! ( "Generating metadata for {} (cache: {})" , arch, cache_type_filter) ;
223+ info ! (
224+ "Generating metadata for {} (cache: {})" ,
225+ arch, cache_type_filter
226+ ) ;
223227
224228 // Create registry client (uses anonymous auth)
225229 let _ = github_token; // Token not used for public registry access
@@ -258,7 +262,10 @@ async fn cmd_generate(
258262 continue ;
259263 }
260264
261- info ! ( "Processing: {} -> {} ({:?})" , recipe. pkg, ghcr_info. pkg_name, path) ;
265+ info ! (
266+ "Processing: {} -> {} ({:?})" ,
267+ recipe. pkg, ghcr_info. pkg_name, path
268+ ) ;
262269
263270 // Start with recipe-based metadata
264271 let mut metadata = PackageMetadata :: from_recipe ( & recipe) ;
@@ -290,11 +297,18 @@ async fn cmd_generate(
290297 match client. fetch_manifest ( & ghcr_info. ghcr_path , tag) . await {
291298 Ok ( manifest_str) => {
292299 if let Ok ( manifest) = OciManifest :: from_json ( & manifest_str) {
293- metadata. enrich_from_manifest ( & manifest, & ghcr_info. ghcr_path , tag) ;
300+ metadata. enrich_from_manifest (
301+ & manifest,
302+ & ghcr_info. ghcr_path ,
303+ tag,
304+ ) ;
294305 }
295306 }
296307 Err ( e) => {
297- warn ! ( "Failed to fetch manifest for {}: {}" , ghcr_info. ghcr_path, e) ;
308+ warn ! (
309+ "Failed to fetch manifest for {}: {}" ,
310+ ghcr_info. ghcr_path, e
311+ ) ;
298312 }
299313 }
300314 } else {
@@ -308,13 +322,6 @@ async fn cmd_generate(
308322
309323 metadata. parse_note_flags ( ) ;
310324
311- // Fetch download count from GitHub API (optional)
312- if let Ok ( count) = client. fetch_download_count ( & ghcr_info. ghcr_path ) . await {
313- if count > 0 {
314- metadata. download_count = Some ( count) ;
315- }
316- }
317-
318325 // Only add packages that have valid metadata (requires download_url from GHCR)
319326 if metadata. is_valid ( ) {
320327 if ghcr_info. cache_type == "bincache" {
@@ -323,48 +330,42 @@ async fn cmd_generate(
323330 pkgcache_metadata. push ( metadata) ;
324331 }
325332 } else {
326- debug ! ( "Skipping {}: not in GHCR or invalid metadata" , ghcr_info. ghcr_path) ;
333+ debug ! (
334+ "Skipping {}: not in GHCR or invalid metadata" ,
335+ ghcr_info. ghcr_path
336+ ) ;
327337 }
328338 }
329339 }
330340
331341 // Process and write output for each cache type
332- let write_cache_metadata = |cache_type : & str , mut metadata_list : Vec < PackageMetadata > | -> Result < ( ) > {
333- if metadata_list. is_empty ( ) {
334- info ! ( "No {} packages to write" , cache_type) ;
335- return Ok ( ( ) ) ;
336- }
337-
338- // Sort by download count (descending), then by package name (ascending) for ties
339- metadata_list. sort_by ( |a, b| {
340- match ( b. download_count , a. download_count ) {
341- ( Some ( b_count) , Some ( a_count) ) => {
342- // Sort by download count descending
343- b_count. cmp ( & a_count) . then_with ( || a. pkg . cmp ( & b. pkg ) )
344- }
345- ( Some ( _) , None ) => std:: cmp:: Ordering :: Less , // packages with counts come first
346- ( None , Some ( _) ) => std:: cmp:: Ordering :: Greater ,
347- ( None , None ) => a. pkg . cmp ( & b. pkg ) , // fallback to alphabetical
342+ let write_cache_metadata =
343+ |cache_type : & str , mut metadata_list : Vec < PackageMetadata > | -> Result < ( ) > {
344+ if metadata_list. is_empty ( ) {
345+ info ! ( "No {} packages to write" , cache_type) ;
346+ return Ok ( ( ) ) ;
348347 }
349- } ) ;
350348
351- // Calculate ranks based on sorted position
352- for ( idx, metadata) in metadata_list. iter_mut ( ) . enumerate ( ) {
353- metadata. rank = Some ( ( idx + 1 ) as u64 ) ;
354- }
355-
356- // Create output directory if needed
357- let cache_dir = output_dir. join ( cache_type) ;
358- std:: fs:: create_dir_all ( & cache_dir) ?;
359-
360- // Write output file
361- let output_file = cache_dir. join ( format ! ( "{}.json" , arch) ) ;
362- let json = serde_json:: to_string_pretty ( & metadata_list) ?;
363- std:: fs:: write ( & output_file, json) ?;
364-
365- info ! ( "Generated {} metadata for {} packages -> {:?}" , cache_type, metadata_list. len( ) , output_file) ;
366- Ok ( ( ) )
367- } ;
349+ // Sort alphabetically by package name
350+ metadata_list. sort_by ( |a, b| a. pkg . cmp ( & b. pkg ) ) ;
351+
352+ // Create output directory if needed
353+ let cache_dir = output_dir. join ( cache_type) ;
354+ std:: fs:: create_dir_all ( & cache_dir) ?;
355+
356+ // Write output file
357+ let output_file = cache_dir. join ( format ! ( "{}.json" , arch) ) ;
358+ let json = serde_json:: to_string_pretty ( & metadata_list) ?;
359+ std:: fs:: write ( & output_file, json) ?;
360+
361+ info ! (
362+ "Generated {} metadata for {} packages -> {:?}" ,
363+ cache_type,
364+ metadata_list. len( ) ,
365+ output_file
366+ ) ;
367+ Ok ( ( ) )
368+ } ;
368369
369370 // Write outputs based on filter
370371 if cache_type_filter == "all" || cache_type_filter == "bincache" {
@@ -499,19 +500,17 @@ async fn execute_pkgver(script: &str, timeout_secs: u64) -> Result<String> {
499500
500501 let result = timeout (
501502 Duration :: from_secs ( timeout_secs) ,
502- Command :: new ( "bash" )
503- . arg ( "-c" )
504- . arg ( script)
505- . output ( )
506- ) . await ;
503+ Command :: new ( "bash" ) . arg ( "-c" ) . arg ( script) . output ( ) ,
504+ )
505+ . await ;
507506
508507 match result {
509508 Ok ( Ok ( output) ) => {
510509 if output. status . success ( ) {
511510 Ok ( String :: from_utf8_lossy ( & output. stdout ) . to_string ( ) )
512511 } else {
513512 Err ( Error :: PkgverFailed (
514- String :: from_utf8_lossy ( & output. stderr ) . to_string ( )
513+ String :: from_utf8_lossy ( & output. stderr ) . to_string ( ) ,
515514 ) )
516515 }
517516 }
0 commit comments