8
8
} ;
9
9
10
10
pub struct Info {
11
- git_version : String ,
12
11
git_username : String ,
13
- project_name : String ,
12
+ git_version : String ,
13
+ repo_name : String ,
14
+ number_of_tags : usize ,
15
+ number_of_branches : usize ,
14
16
head_refs : CommitInfo ,
17
+ pending_changes : String ,
15
18
version : String ,
16
19
creation_date : String ,
17
- pub dominant_language : Language ,
18
20
languages : Vec < ( Language , f64 ) > ,
19
21
dependencies : String ,
20
22
authors : Vec < ( String , usize , usize ) > ,
21
23
last_change : String ,
22
24
repo_url : String ,
23
- commits : String ,
24
- pending : String ,
25
- repo_size : String ,
25
+ number_of_commits : String ,
26
26
lines_of_code : usize ,
27
- number_of_tags : usize ,
28
- number_of_branches : usize ,
27
+ repo_size : String ,
29
28
license : String ,
29
+ pub dominant_language : Language ,
30
30
pub ascii_colors : Vec < Color > ,
31
31
pub text_colors : TextColor ,
32
32
pub config : Cli ,
@@ -59,7 +59,7 @@ impl std::fmt::Display for Info {
59
59
f,
60
60
"{}{} {}" ,
61
61
project_str,
62
- self . project_name . color( self . text_colors. info) ,
62
+ self . repo_name . color( self . text_colors. info) ,
63
63
branches_tags_str. color( self . text_colors. info)
64
64
) ?;
65
65
}
@@ -73,12 +73,12 @@ impl std::fmt::Display for Info {
73
73
) ?;
74
74
}
75
75
76
- if !self . config . disabled_fields . pending && !self . pending . is_empty ( ) {
76
+ if !self . config . disabled_fields . pending && !self . pending_changes . is_empty ( ) {
77
77
writeln ! (
78
78
f,
79
79
"{}{}" ,
80
80
& self . get_formatted_subtitle_label( "Pending" ) ,
81
- & self . pending . color( self . text_colors. info) ,
81
+ & self . pending_changes . color( self . text_colors. info) ,
82
82
) ?;
83
83
}
84
84
@@ -158,7 +158,7 @@ impl std::fmt::Display for Info {
158
158
f,
159
159
"{}{}" ,
160
160
& self . get_formatted_subtitle_label( "Commits" ) ,
161
- & self . commits . color( self . text_colors. info) ,
161
+ & self . number_of_commits . color( self . text_colors. info) ,
162
162
) ?;
163
163
}
164
164
@@ -212,26 +212,26 @@ impl Info {
212
212
pub fn new ( config : Cli ) -> Result < Info > {
213
213
let repo = Repo :: new ( & config. repo_path ) ?;
214
214
let workdir = repo. get_work_dir ( ) ?;
215
- let ( repository_name , repository_url ) = repo. get_name_and_url ( ) ?;
215
+ let ( repo_name , repo_url ) = repo. get_name_and_url ( ) ?;
216
216
let head_refs = repo. get_head_refs ( ) ?;
217
- let pending = repo. get_pending_changes ( ) ;
217
+ let pending_changes = repo. get_pending_changes ( ) ? ;
218
218
let version = repo. get_version ( ) ?;
219
219
let git_username = repo. get_git_username ( ) ?;
220
220
let number_of_tags = repo. get_number_of_tags ( ) ?;
221
221
let number_of_branches = repo. get_number_of_branches ( ) ?;
222
222
let git_history = Info :: get_git_history ( & workdir, config. no_merges ) ;
223
- let creation_date = Info :: get_creation_date ( & git_history) ;
223
+ let creation_date = Info :: get_creation_date ( & git_history) ? ;
224
224
let number_of_commits = Info :: get_number_of_commits ( & git_history) ;
225
225
let authors = Info :: get_authors ( & git_history, config. number_of_authors ) ;
226
- let last_change = Info :: get_date_of_last_commit ( & git_history) ;
226
+ let last_change = Info :: get_date_of_last_commit ( & git_history) ? ;
227
227
let git_version = Info :: get_git_version ( ) ?;
228
- let repo_size = Info :: get_packed_size ( & workdir) ;
229
- let project_license = Detector :: new ( ) ?. get_project_license ( & workdir) ;
228
+ let repo_size = Info :: get_packed_size ( & workdir) ? ;
229
+ let license = Detector :: new ( ) ?. get_license ( & workdir) ? ;
230
230
let dependencies = deps:: DependencyDetector :: new ( ) . get_dependencies ( & workdir) ?;
231
- let ( languages_stats , lines_of_code) =
231
+ let ( languages , lines_of_code) =
232
232
Language :: get_language_statistics ( & workdir, & config. excluded ) ?;
233
- let dominant_language = Language :: get_dominant_language ( & languages_stats ) ;
234
- let ascii_colors = Info :: get_ascii_colors (
233
+ let dominant_language = Language :: get_dominant_language ( & languages ) ;
234
+ let ascii_colors = Language :: get_ascii_colors (
235
235
& config. ascii_language ,
236
236
& dominant_language,
237
237
& config. ascii_colors ,
@@ -240,25 +240,25 @@ impl Info {
240
240
let text_colors = TextColor :: get_text_colors ( & config. text_colors , & ascii_colors) ;
241
241
242
242
Ok ( Info {
243
- git_version,
244
243
git_username,
245
- project_name : repository_name,
244
+ git_version,
245
+ repo_name,
246
+ number_of_tags,
247
+ number_of_branches,
246
248
head_refs,
249
+ pending_changes,
247
250
version,
248
- creation_date : creation_date?,
249
- dominant_language,
250
- languages : languages_stats,
251
+ creation_date,
252
+ languages,
251
253
dependencies,
252
254
authors,
253
- last_change : last_change?,
254
- repo_url : repository_url,
255
- commits : number_of_commits,
256
- pending : pending?,
257
- repo_size : repo_size?,
255
+ last_change,
256
+ repo_url,
257
+ number_of_commits,
258
258
lines_of_code,
259
- number_of_tags ,
260
- number_of_branches ,
261
- license : project_license? ,
259
+ repo_size ,
260
+ license ,
261
+ dominant_language ,
262
262
ascii_colors,
263
263
text_colors,
264
264
config,
@@ -311,16 +311,38 @@ impl Info {
311
311
authors
312
312
}
313
313
314
- fn get_git_version ( ) -> Result < String > {
315
- let version = Command :: new ( "git" ) . arg ( "--version" ) . output ( ) ?;
316
- Ok ( String :: from_utf8_lossy ( & version. stdout ) . replace ( '\n' , "" ) )
314
+ fn get_date_of_last_commit ( git_history : & [ String ] ) -> Result < String > {
315
+ let last_commit = git_history. first ( ) ;
316
+
317
+ let output = match last_commit {
318
+ Some ( date) => date. split ( '\t' ) . collect :: < Vec < _ > > ( ) [ 0 ] . to_string ( ) ,
319
+ None => "??" . into ( ) ,
320
+ } ;
321
+
322
+ Ok ( output)
323
+ }
324
+
325
+ fn get_creation_date ( git_history : & [ String ] ) -> Result < String > {
326
+ let first_commit = git_history. last ( ) ;
327
+
328
+ let output = match first_commit {
329
+ Some ( creation_time) => creation_time. split ( '\t' ) . collect :: < Vec < _ > > ( ) [ 0 ] . to_string ( ) ,
330
+ None => "??" . into ( ) ,
331
+ } ;
332
+
333
+ Ok ( output)
317
334
}
318
335
319
336
fn get_number_of_commits ( git_history : & [ String ] ) -> String {
320
337
let number_of_commits = git_history. len ( ) ;
321
338
number_of_commits. to_string ( )
322
339
}
323
340
341
+ fn get_git_version ( ) -> Result < String > {
342
+ let version = Command :: new ( "git" ) . arg ( "--version" ) . output ( ) ?;
343
+ Ok ( String :: from_utf8_lossy ( & version. stdout ) . replace ( '\n' , "" ) )
344
+ }
345
+
324
346
fn get_packed_size ( dir : & str ) -> Result < String > {
325
347
let output = Command :: new ( "git" )
326
348
. arg ( "-C" )
@@ -366,80 +388,6 @@ impl Info {
366
388
}
367
389
}
368
390
369
- fn get_date_of_last_commit ( git_history : & [ String ] ) -> Result < String > {
370
- let last_commit = git_history. first ( ) ;
371
-
372
- let output = match last_commit {
373
- Some ( date) => date. split ( '\t' ) . collect :: < Vec < _ > > ( ) [ 0 ] . to_string ( ) ,
374
- None => "??" . into ( ) ,
375
- } ;
376
-
377
- Ok ( output)
378
- }
379
-
380
- fn get_creation_date ( git_history : & [ String ] ) -> Result < String > {
381
- let first_commit = git_history. last ( ) ;
382
-
383
- let output = match first_commit {
384
- Some ( creation_time) => creation_time. split ( '\t' ) . collect :: < Vec < _ > > ( ) [ 0 ] . to_string ( ) ,
385
- None => "??" . into ( ) ,
386
- } ;
387
-
388
- Ok ( output)
389
- }
390
-
391
- fn get_ascii_colors (
392
- ascii_language : & Option < Language > ,
393
- dominant_language : & Language ,
394
- ascii_colors : & [ String ] ,
395
- true_color : bool ,
396
- ) -> Vec < Color > {
397
- let language = if let Some ( ascii_language) = ascii_language {
398
- ascii_language
399
- } else {
400
- & dominant_language
401
- } ;
402
-
403
- let colors = language. get_colors ( true_color) ;
404
-
405
- let colors: Vec < Color > = colors
406
- . iter ( )
407
- . enumerate ( )
408
- . map ( |( index, default_color) | {
409
- if let Some ( color_num) = ascii_colors. get ( index) {
410
- if let Some ( color) = Info :: num_to_color ( color_num) {
411
- return color;
412
- }
413
- }
414
- * default_color
415
- } )
416
- . collect ( ) ;
417
- colors
418
- }
419
-
420
- pub fn num_to_color ( num : & str ) -> Option < Color > {
421
- let color = match num {
422
- "0" => Color :: Black ,
423
- "1" => Color :: Red ,
424
- "2" => Color :: Green ,
425
- "3" => Color :: Yellow ,
426
- "4" => Color :: Blue ,
427
- "5" => Color :: Magenta ,
428
- "6" => Color :: Cyan ,
429
- "7" => Color :: White ,
430
- "8" => Color :: BrightBlack ,
431
- "9" => Color :: BrightRed ,
432
- "10" => Color :: BrightGreen ,
433
- "11" => Color :: BrightYellow ,
434
- "12" => Color :: BrightBlue ,
435
- "13" => Color :: BrightMagenta ,
436
- "14" => Color :: BrightCyan ,
437
- "15" => Color :: BrightWhite ,
438
- _ => return None ,
439
- } ;
440
- Some ( color)
441
- }
442
-
443
391
fn get_formatted_subtitle_label ( & self , label : & str ) -> ColoredString {
444
392
let formatted_label = format ! (
445
393
"{}{} " ,
0 commit comments