1- use bencher_fingerprint :: Fingerprint ;
1+ use bencher_json :: { Fingerprint , GitHash } ;
22use gix:: Repository ;
33
4- use crate :: bencher :: sub :: project :: run :: branch:: find_repo;
4+ use super :: branch:: find_repo;
55
66const ROOT : & str = "root" ;
77
@@ -13,8 +13,12 @@ pub fn local_project() {
1313 }
1414
1515 if let Some ( repo) = repo {
16+ if let Some ( branch) = current_branch_name ( & repo) {
17+ println ! ( "{branch:?}" ) ;
18+ }
19+
1620 if let Some ( root_commit) = find_default_branch_and_root_commit ( & repo) {
17- println ! ( "Root commit hash: {root_commit}" ) ;
21+ println ! ( "Root commit hash: {root_commit:? }" ) ;
1822 }
1923 }
2024
@@ -33,12 +37,21 @@ fn repo_name(repo: Option<&Repository>) -> Option<String> {
3337 file_name. to_str ( ) . map ( ToOwned :: to_owned)
3438}
3539
36- fn find_default_branch_and_root_commit ( repo : & Repository ) -> Option < String > {
37- let head_id = repo. head_id ( ) . ok ( ) ?;
38-
39- let mut _rev_walk = repo. rev_walk ( [ head_id] ) ;
40-
41- // let root_commit = rev_walk.all().into_iter().last()?.id().to_string();
40+ fn current_branch_name ( repo : & Repository ) -> Option < ( String , String ) > {
41+ repo. head ( ) . ok ( ) ?. referent_name ( ) . map ( |name| {
42+ (
43+ String :: from_utf8_lossy ( name. as_bstr ( ) ) . to_string ( ) ,
44+ String :: from_utf8_lossy ( name. shorten ( ) ) . to_string ( ) ,
45+ )
46+ } )
47+ }
4248
43- None
49+ fn find_default_branch_and_root_commit ( repo : & Repository ) -> Option < GitHash > {
50+ let head_id = repo. head_id ( ) . ok ( ) ?;
51+ let rev_walk = repo. rev_walk ( [ head_id] ) . all ( ) . ok ( ) ?;
52+ if let Some ( Ok ( commit) ) = rev_walk. last ( ) {
53+ Some ( commit. id ( ) . object ( ) . ok ( ) ?. id . into ( ) )
54+ } else {
55+ None
56+ }
4457}
0 commit comments