Method: Rugged::Repository#expand_oids
- Defined in:
- ext/rugged/rugged_repo.c
#expand_oids([oid..], object_type = :any) ⇒ Hash #expand_oids([oid..], object_type = [type..]) ⇒ Hash
Expand a list of short oids to their full value, assuming they exist in the repository. If ‘object_type` is passed and is an array, it must be the same length as the OIDs array. If it’s a single type name, all OIDs will be expected to resolve to that object type. OIDs that don’t match the expected object types will not be expanded.
Returns a hash of ‘{ short_oid => full_oid }` for the short OIDs which exist in the repository and match the expected object type. Missing OIDs will not appear in the resulting hash.
1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 |
# File 'ext/rugged/rugged_repo.c', line 1226
static VALUE rb_git_repo_expand_oids(int argc, VALUE *argv, VALUE self)
{
VALUE rb_result, rb_oids, rb_expected_type;
git_repository *repo;
git_odb *odb;
git_odb_expand_id *expand;
long i, expand_count;
int error;
Data_Get_Struct(self, git_repository, repo);
rb_scan_args(argc, argv, "11", &rb_oids, &rb_expected_type);
Check_Type(rb_oids, T_ARRAY);
expand_count = RARRAY_LEN(rb_oids);
expand = alloca(expand_count * sizeof(git_odb_expand_id));
for (i = 0; i < expand_count; ++i) {
VALUE rb_hex = rb_ary_entry(rb_oids, i);
Check_Type(rb_hex, T_STRING);
rugged_exception_check(
git_oid_fromstrn(&expand[i].id, RSTRING_PTR(rb_hex), RSTRING_LEN(rb_hex))
);
expand[i].length = RSTRING_LEN(rb_hex);
}
if (TYPE(rb_expected_type) == T_ARRAY) {
if (RARRAY_LEN(rb_expected_type) != expand_count)
rb_raise(rb_eRuntimeError,
"the `object_type` array must be the same length as the `oids` array");
for (i = 0; i < expand_count; ++i) {
VALUE rb_type = rb_ary_entry(rb_expected_type, i);
expand[i].type = rugged_otype_get(rb_type);
}
} else {
git_otype expected_type = GIT_OBJ_ANY;
if (!NIL_P(rb_expected_type))
expected_type = rugged_otype_get(rb_expected_type);
for (i = 0; i < expand_count; ++i)
expand[i].type = expected_type;
}
error = git_repository_odb(&odb, repo);
rugged_exception_check(error);
error = git_odb_expand_ids(odb, expand, (size_t)expand_count);
git_odb_free(odb);
rugged_exception_check(error);
rb_result = rb_hash_new();
for (i = 0; i < expand_count; ++i) {
if (expand[i].length) {
rb_hash_aset(rb_result,
rb_ary_entry(rb_oids, i), rugged_create_oid(&expand[i].id));
}
}
return rb_result;
}
|