@@ -1058,59 +1058,64 @@ static VALUE rb_git_repo_expand_oids(int argc, VALUE *argv, VALUE self)
1058
1058
{
1059
1059
VALUE rb_result , rb_oids , rb_expected_type ;
1060
1060
1061
- git_otype expected_type = GIT_OBJ_ANY ;
1062
-
1063
1061
git_repository * repo ;
1064
- git_oid oid ;
1065
1062
git_odb * odb ;
1066
- int i , error ;
1063
+ git_odb_expand_id * expand ;
1064
+ long i , expand_count ;
1065
+ int error ;
1067
1066
1068
1067
Data_Get_Struct (self , git_repository , repo );
1069
-
1070
1068
rb_scan_args (argc , argv , "11" , & rb_oids , & rb_expected_type );
1071
1069
1072
1070
Check_Type (rb_oids , T_ARRAY );
1073
- expected_type = rugged_otype_get (rb_expected_type );
1071
+ expand_count = RARRAY_LEN (rb_oids );
1072
+ expand = alloca (expand_count * sizeof (git_odb_expand_id ));
1074
1073
1075
- error = git_repository_odb (& odb , repo );
1076
- rugged_exception_check (error );
1074
+ for (i = 0 ; i < expand_count ; ++ i ) {
1075
+ VALUE rb_hex = rb_ary_entry (rb_oids , i );
1076
+ Check_Type (rb_hex , T_STRING );
1077
1077
1078
- rb_result = rb_hash_new ();
1078
+ rugged_exception_check (
1079
+ git_oid_fromstrn (& expand [i ].id , RSTRING_PTR (rb_hex ), RSTRING_LEN (rb_hex ))
1080
+ );
1081
+ expand [i ].length = RSTRING_LEN (rb_hex );
1082
+ }
1079
1083
1080
- for (i = 0 ; i < RARRAY_LEN (rb_oids ); ++ i ) {
1081
- VALUE hex_oid = rb_ary_entry (rb_oids , i );
1082
- git_oid found_oid ;
1084
+ if (TYPE (rb_expected_type ) == T_ARRAY ) {
1085
+ if (RARRAY_LEN (rb_expected_type ) != expand_count )
1086
+ rb_raise (rb_eRuntimeError ,
1087
+ "the `object_type` array must be the same length as the `oids` array" );
1083
1088
1084
- if ( TYPE ( hex_oid ) != T_STRING ) {
1085
- git_odb_free ( odb );
1086
- rb_raise ( rb_eTypeError , "Expected a SHA1 OID" );
1089
+ for ( i = 0 ; i < expand_count ; ++ i ) {
1090
+ VALUE rb_type = rb_ary_entry ( rb_expected_type , i );
1091
+ expand [ i ]. type = rugged_otype_get ( rb_type );
1087
1092
}
1093
+ } else {
1094
+ git_otype expected_type = GIT_OBJ_ANY ;
1088
1095
1089
- error = git_oid_fromstrn (& oid , RSTRING_PTR (hex_oid ), RSTRING_LEN (hex_oid ));
1090
- if (error < 0 ) {
1091
- git_odb_free (odb );
1092
- rugged_exception_check (error );
1093
- }
1096
+ if (!NIL_P (rb_expected_type ))
1097
+ expected_type = rugged_otype_get (rb_expected_type );
1094
1098
1095
- error = git_odb_exists_prefix (& found_oid , odb , & oid , RSTRING_LEN (hex_oid ));
1099
+ for (i = 0 ; i < expand_count ; ++ i )
1100
+ expand [i ].type = expected_type ;
1101
+ }
1096
1102
1097
- if (!error ) {
1098
- if (expected_type != GIT_OBJ_ANY ) {
1099
- size_t found_size ;
1100
- git_otype found_type ;
1103
+ error = git_repository_odb (& odb , repo );
1104
+ rugged_exception_check (error );
1101
1105
1102
- if (git_odb_read_header (& found_size , & found_type , odb , & found_oid ) < 0 )
1103
- continue ;
1106
+ error = git_odb_expand_ids (odb , expand , (size_t )expand_count );
1107
+ git_odb_free (odb );
1108
+ rugged_exception_check (error );
1104
1109
1105
- if (found_type != expected_type )
1106
- continue ;
1107
- }
1110
+ rb_result = rb_hash_new ();
1108
1111
1109
- rb_hash_aset (rb_result , hex_oid , rugged_create_oid (& found_oid ));
1112
+ for (i = 0 ; i < expand_count ; ++ i ) {
1113
+ if (expand [i ].length ) {
1114
+ rb_hash_aset (rb_result ,
1115
+ rb_ary_entry (rb_oids , i ), rugged_create_oid (& expand [i ].id ));
1110
1116
}
1111
1117
}
1112
1118
1113
- git_odb_free (odb );
1114
1119
return rb_result ;
1115
1120
}
1116
1121
0 commit comments