@@ -292,10 +292,10 @@ impl Info {
292
292
let workdir = repo. workdir ( ) . ok_or ( Error :: BareGitRepo ) ?;
293
293
let workdir_str = workdir. to_str ( ) . unwrap ( ) ;
294
294
295
+ let config = Info :: get_configuration ( & repo) ?;
296
+ let current_commit_info = Info :: get_current_commit_info ( & repo) ?;
295
297
let authors = Info :: get_authors ( workdir_str, no_merges, 3 ) ;
296
298
let ( git_v, git_user) = Info :: get_git_info ( workdir_str) ;
297
- let current_commit_info = Info :: get_current_commit_info ( & repo) ?;
298
- let config = Info :: get_configuration ( & repo) ?;
299
299
let version = Info :: get_version ( workdir_str) ?;
300
300
let commits = Info :: get_commits ( workdir_str, no_merges) ?;
301
301
let repo_size = Info :: get_packed_size ( workdir_str) ?;
@@ -329,6 +329,66 @@ impl Info {
329
329
} )
330
330
}
331
331
332
+ fn get_configuration ( repo : & Repository ) -> Result < Configuration > {
333
+ let config = repo. config ( ) . map_err ( |_| Error :: NoGitData ) ?;
334
+ let mut remote_url = String :: new ( ) ;
335
+ let mut repository_name = String :: new ( ) ;
336
+ let mut remote_upstream: Option < String > = None ;
337
+
338
+ for entry in & config. entries ( None ) . unwrap ( ) {
339
+ let entry = entry. unwrap ( ) ;
340
+ match entry. name ( ) . unwrap ( ) {
341
+ "remote.origin.url" => remote_url = entry. value ( ) . unwrap ( ) . to_string ( ) ,
342
+ "remote.upstream.url" => remote_upstream = Some ( entry. value ( ) . unwrap ( ) . to_string ( ) ) ,
343
+ _ => ( ) ,
344
+ }
345
+ }
346
+
347
+ if let Some ( url) = remote_upstream {
348
+ remote_url = url. clone ( ) ;
349
+ }
350
+
351
+ let url = remote_url. clone ( ) ;
352
+ let name_parts: Vec < & str > = url. split ( '/' ) . collect ( ) ;
353
+
354
+ if !name_parts. is_empty ( ) {
355
+ repository_name = name_parts[ name_parts. len ( ) - 1 ] . to_string ( ) ;
356
+ }
357
+
358
+ if repository_name. contains ( ".git" ) {
359
+ let repo_name = repository_name. clone ( ) ;
360
+ let parts: Vec < & str > = repo_name. split ( ".git" ) . collect ( ) ;
361
+ repository_name = parts[ 0 ] . to_string ( ) ;
362
+ }
363
+
364
+ Ok ( Configuration {
365
+ repository_name : repository_name. clone ( ) ,
366
+ repository_url : name_parts. join ( "/" ) ,
367
+ } )
368
+ }
369
+
370
+ fn get_current_commit_info ( repo : & Repository ) -> Result < CommitInfo > {
371
+ let head = repo. head ( ) . map_err ( |_| Error :: ReferenceInfoError ) ?;
372
+ let head_oid = head. target ( ) . ok_or ( Error :: ReferenceInfoError ) ?;
373
+ let refs = repo. references ( ) . map_err ( |_| Error :: ReferenceInfoError ) ?;
374
+ let refs_info = refs
375
+ . filter_map ( |reference| match reference {
376
+ Ok ( reference) => match ( reference. target ( ) , reference. shorthand ( ) ) {
377
+ ( Some ( oid) , Some ( shorthand) ) if oid == head_oid => {
378
+ Some ( if reference. is_tag ( ) {
379
+ String :: from ( "tags/" ) + shorthand
380
+ } else {
381
+ String :: from ( shorthand)
382
+ } )
383
+ }
384
+ _ => None ,
385
+ } ,
386
+ Err ( _) => None ,
387
+ } )
388
+ . collect :: < Vec < String > > ( ) ;
389
+ Ok ( CommitInfo :: new ( head_oid, refs_info) )
390
+ }
391
+
332
392
// Return first n most active commiters as authors within this project.
333
393
fn get_authors ( dir : & str , no_merges : bool , n : usize ) -> Vec < ( String , usize , usize ) > {
334
394
let mut args = vec ! [ "-C" , dir, "log" , "--format='%aN'" ] ;
@@ -394,66 +454,6 @@ impl Info {
394
454
( version, username)
395
455
}
396
456
397
- fn get_current_commit_info ( repo : & Repository ) -> Result < CommitInfo > {
398
- let head = repo. head ( ) . map_err ( |_| Error :: ReferenceInfoError ) ?;
399
- let head_oid = head. target ( ) . ok_or ( Error :: ReferenceInfoError ) ?;
400
- let refs = repo. references ( ) . map_err ( |_| Error :: ReferenceInfoError ) ?;
401
- let refs_info = refs
402
- . filter_map ( |reference| match reference {
403
- Ok ( reference) => match ( reference. target ( ) , reference. shorthand ( ) ) {
404
- ( Some ( oid) , Some ( shorthand) ) if oid == head_oid => {
405
- Some ( if reference. is_tag ( ) {
406
- String :: from ( "tags/" ) + shorthand
407
- } else {
408
- String :: from ( shorthand)
409
- } )
410
- }
411
- _ => None ,
412
- } ,
413
- Err ( _) => None ,
414
- } )
415
- . collect :: < Vec < String > > ( ) ;
416
- Ok ( CommitInfo :: new ( head_oid, refs_info) )
417
- }
418
-
419
- fn get_configuration ( repo : & Repository ) -> Result < Configuration > {
420
- let config = repo. config ( ) . map_err ( |_| Error :: NoGitData ) ?;
421
- let mut remote_url = String :: new ( ) ;
422
- let mut repository_name = String :: new ( ) ;
423
- let mut remote_upstream: Option < String > = None ;
424
-
425
- for entry in & config. entries ( None ) . unwrap ( ) {
426
- let entry = entry. unwrap ( ) ;
427
- match entry. name ( ) . unwrap ( ) {
428
- "remote.origin.url" => remote_url = entry. value ( ) . unwrap ( ) . to_string ( ) ,
429
- "remote.upstream.url" => remote_upstream = Some ( entry. value ( ) . unwrap ( ) . to_string ( ) ) ,
430
- _ => ( ) ,
431
- }
432
- }
433
-
434
- if let Some ( url) = remote_upstream {
435
- remote_url = url. clone ( ) ;
436
- }
437
-
438
- let url = remote_url. clone ( ) ;
439
- let name_parts: Vec < & str > = url. split ( '/' ) . collect ( ) ;
440
-
441
- if !name_parts. is_empty ( ) {
442
- repository_name = name_parts[ name_parts. len ( ) - 1 ] . to_string ( ) ;
443
- }
444
-
445
- if repository_name. contains ( ".git" ) {
446
- let repo_name = repository_name. clone ( ) ;
447
- let parts: Vec < & str > = repo_name. split ( ".git" ) . collect ( ) ;
448
- repository_name = parts[ 0 ] . to_string ( ) ;
449
- }
450
-
451
- Ok ( Configuration {
452
- repository_name : repository_name. clone ( ) ,
453
- repository_url : name_parts. join ( "/" ) ,
454
- } )
455
- }
456
-
457
457
fn get_version ( dir : & str ) -> Result < String > {
458
458
let output = Command :: new ( "git" )
459
459
. arg ( "-C" )
0 commit comments