@@ -7,15 +7,12 @@ use std::{borrow::Cow, process, time::Instant};
77
88use clap:: Parser ;
99use eyre:: Context ;
10- use gix:: ThreadSafeRepository ;
11- use indicatif:: ProgressBar ;
12- use label_logger:: { OutputLabel , console:: style, error, info, label_theme, log, success} ;
13- use pariter:: IteratorExt ;
10+ use label_logger:: { error, success} ;
1411
1512use crate :: {
1613 config:: { Args , Config } ,
1714 crawl:: crawl_repositories,
18- diagnostic:: Diagnostic ,
15+ diagnostic:: print_diagnostics ,
1916} ;
2017
2118mod config;
@@ -51,6 +48,7 @@ fn main() -> eyre::Result<()> {
5148
5249 // Find git repositories in the specified directory
5350 let mut repos = crawl_repositories ( & search_directory, & args) ;
51+
5452 repos. sort ( ) ;
5553
5654 // Exit if no git repositories were found
@@ -67,88 +65,7 @@ fn main() -> eyre::Result<()> {
6765 begin_search_time. elapsed( ) . as_secs( )
6866 ) ;
6967
70- let diag_bar = ProgressBar :: new ( repos. len ( ) . try_into ( ) . unwrap ( ) )
71- . with_style ( label_theme ( OutputLabel :: Info ( "Checking" ) ) ) ;
72- let diag_bar_parallel = diag_bar. clone ( ) ;
73-
74- let diagnostics = repos
75- . into_iter ( )
76- . parallel_map ( move |path| {
77- diag_bar_parallel. inc ( 1 ) ;
78-
79- let Ok ( repo) = ThreadSafeRepository :: open ( path) else {
80- error ! ( "could not open repository" ) ;
81- return None ;
82- } ;
83-
84- let Ok ( diag) = Diagnostic :: analyze ( & repo. to_thread_local ( ) , & config) else {
85- error ! ( "could not open diagnostic" ) ;
86- return None ;
87- } ;
88-
89- if !diag. useful ( ) {
90- return None ;
91- }
92-
93- Some ( ( repo, diag) )
94- } )
95- . flatten ( )
96- . collect :: < Vec < _ > > ( ) ;
97-
98- diag_bar. finish_and_clear ( ) ;
99-
100- for ( repo, diag) in diagnostics {
101- let path = repo
102- . path ( )
103- . parent ( )
104- . expect ( "repository .git folder always has a parent" ) ;
105-
106- let project_name = path. file_name ( ) . unwrap ( ) . to_string_lossy ( ) ;
107- let directory = path. parent ( ) . unwrap ( ) . to_string_lossy ( ) ;
108- // Make path relative to root search directory
109- let directory = directory. replacen ( search_directory. to_string_lossy ( ) . as_ref ( ) , "." , 1 ) ;
110-
111- let path = format ! (
112- "{}{}{}" ,
113- style( directory) . dim( ) ,
114- style( std:: path:: MAIN_SEPARATOR ) . dim( ) ,
115- project_name,
116- ) ;
117-
118- let dirty_info = if diag. is_dirty {
119- style ( " is dirty" ) . yellow ( )
120- } else {
121- style ( "" )
122- } ;
123-
124- info ! ( label: "Repo" , "{path}{dirty_info}" ) ;
125-
126- let ahead_branches = diag
127- . ahead_branches
128- . iter ( )
129- . map ( |name| style ( name) . yellow ( ) . to_string ( ) )
130- . collect :: < Vec < _ > > ( ) ;
131- if !ahead_branches. is_empty ( ) {
132- log ! (
133- label: OutputLabel :: Custom ( style( "└" ) ) ,
134- "has ahead branches: {}" ,
135- ahead_branches. join( ", " )
136- ) ;
137- }
138-
139- let branches_no_upstream = diag
140- . no_upstream_branches
141- . iter ( )
142- . map ( |name| style ( name) . yellow ( ) . to_string ( ) )
143- . collect :: < Vec < _ > > ( ) ;
144- if !branches_no_upstream. is_empty ( ) {
145- log ! (
146- label: OutputLabel :: Custom ( style( "└" ) ) ,
147- "has branches with no upstream: {}" ,
148- branches_no_upstream. join( ", " )
149- ) ;
150- }
151- }
68+ print_diagnostics ( repos, config, & search_directory) ?;
15269
15370 Ok ( ( ) )
15471}
0 commit comments