Git fork

odb: rename `oid_object_info()`

Rename `oid_object_info()` to `odb_read_object_info()` as well as their
`_extended()` variant to match other functions related to the object
database and our modern coding guidelines.

Introduce compatibility wrappers so that any in-flight topics will
continue to compile.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
e989dd96 16cf7494

+213 -170
+1 -1
archive.c
··· 215 216 /* Stream it? */ 217 if (S_ISREG(mode) && !args->convert && 218 - oid_object_info(args->repo, oid, &size) == OBJ_BLOB && 219 size > repo_settings_get_big_file_threshold(the_repository)) 220 return write_entry(args, oid, path.buf, path.len, mode, NULL, size); 221
··· 215 216 /* Stream it? */ 217 if (S_ISREG(mode) && !args->convert && 218 + odb_read_object_info(args->repo->objects, oid, &size) == OBJ_BLOB && 219 size > repo_settings_get_big_file_threshold(the_repository)) 220 return write_entry(args, oid, path.buf, path.len, mode, NULL, size); 221
+2 -2
blame.c
··· 116 unsigned short mode; 117 118 if (!get_tree_entry(r, commit_oid, path, &blob_oid, &mode) && 119 - oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB) 120 return; 121 } 122 ··· 1245 return 0; 1246 if (get_tree_entry(r, &origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode)) 1247 goto error_out; 1248 - if (oid_object_info(r, &origin->blob_oid, NULL) != OBJ_BLOB) 1249 goto error_out; 1250 return 0; 1251 error_out:
··· 116 unsigned short mode; 117 118 if (!get_tree_entry(r, commit_oid, path, &blob_oid, &mode) && 119 + odb_read_object_info(r->objects, &blob_oid, NULL) == OBJ_BLOB) 120 return; 121 } 122 ··· 1245 return 0; 1246 if (get_tree_entry(r, &origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode)) 1247 goto error_out; 1248 + if (odb_read_object_info(r->objects, &origin->blob_oid, NULL) != OBJ_BLOB) 1249 goto error_out; 1250 return 0; 1251 error_out:
+2 -2
builtin/blame.c
··· 837 838 if (repo_get_oid(the_repository, name, &oid)) 839 return 0; 840 - return OBJ_NONE < oid_object_info(the_repository, &oid, NULL); 841 } 842 843 static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata) ··· 848 oidcpy(&oid, oid_ret); 849 while (1) { 850 struct object *obj; 851 - int kind = oid_object_info(r, &oid, NULL); 852 if (kind == OBJ_COMMIT) { 853 oidcpy(oid_ret, &oid); 854 return 0;
··· 837 838 if (repo_get_oid(the_repository, name, &oid)) 839 return 0; 840 + return OBJ_NONE < odb_read_object_info(the_repository->objects, &oid, NULL); 841 } 842 843 static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata) ··· 848 oidcpy(&oid, oid_ret); 849 while (1) { 850 struct object *obj; 851 + int kind = odb_read_object_info(r->objects, &oid, NULL); 852 if (kind == OBJ_COMMIT) { 853 oidcpy(oid_ret, &oid); 854 return 0;
+14 -12
builtin/cat-file.c
··· 132 switch (opt) { 133 case 't': 134 oi.typep = &type; 135 - if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0) 136 die("git cat-file: could not get object info"); 137 printf("%s\n", type_name(type)); 138 ret = 0; ··· 146 oi.contentp = (void**)&buf; 147 } 148 149 - if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0) 150 die("git cat-file: could not get object info"); 151 152 if (use_mailmap && (type == OBJ_COMMIT || type == OBJ_TAG)) { ··· 180 /* else fallthrough */ 181 182 case 'p': 183 - type = oid_object_info(the_repository, &oid, NULL); 184 if (type < 0) 185 die("Not a valid object name %s", obj_name); 186 ··· 217 218 if (exp_type_id == OBJ_BLOB) { 219 struct object_id blob_oid; 220 - if (oid_object_info(the_repository, &oid, NULL) == OBJ_TAG) { 221 char *buffer = repo_read_object_file(the_repository, 222 &oid, 223 &type, ··· 235 } else 236 oidcpy(&blob_oid, &oid); 237 238 - if (oid_object_info(the_repository, &blob_oid, NULL) == OBJ_BLOB) { 239 ret = stream_blob(&blob_oid); 240 goto cleanup; 241 } ··· 294 295 /* 296 * After a mark_query run, this object_info is set up to be 297 - * passed to oid_object_info_extended. It will point to the data 298 * elements above, so you can retrieve the response from there. 299 */ 300 struct object_info info; ··· 484 data->info.sizep = &data->size; 485 486 if (pack) 487 - ret = packed_object_info(the_repository, pack, offset, 488 - &data->info); 489 else 490 - ret = oid_object_info_extended(the_repository, 491 - &data->oid, &data->info, 492 - OBJECT_INFO_LOOKUP_REPLACE); 493 if (ret < 0) { 494 report_object_status(opt, obj_name, &data->oid, "missing"); 495 return; ··· 872 873 /* 874 * Expand once with our special mark_query flag, which will prime the 875 - * object_info to be handed to oid_object_info_extended for each 876 * object. 877 */ 878 memset(&data, 0, sizeof(data));
··· 132 switch (opt) { 133 case 't': 134 oi.typep = &type; 135 + if (odb_read_object_info_extended(the_repository->objects, &oid, &oi, flags) < 0) 136 die("git cat-file: could not get object info"); 137 printf("%s\n", type_name(type)); 138 ret = 0; ··· 146 oi.contentp = (void**)&buf; 147 } 148 149 + if (odb_read_object_info_extended(the_repository->objects, &oid, &oi, flags) < 0) 150 die("git cat-file: could not get object info"); 151 152 if (use_mailmap && (type == OBJ_COMMIT || type == OBJ_TAG)) { ··· 180 /* else fallthrough */ 181 182 case 'p': 183 + type = odb_read_object_info(the_repository->objects, &oid, NULL); 184 if (type < 0) 185 die("Not a valid object name %s", obj_name); 186 ··· 217 218 if (exp_type_id == OBJ_BLOB) { 219 struct object_id blob_oid; 220 + if (odb_read_object_info(the_repository->objects, 221 + &oid, NULL) == OBJ_TAG) { 222 char *buffer = repo_read_object_file(the_repository, 223 &oid, 224 &type, ··· 236 } else 237 oidcpy(&blob_oid, &oid); 238 239 + if (odb_read_object_info(the_repository->objects, 240 + &blob_oid, NULL) == OBJ_BLOB) { 241 ret = stream_blob(&blob_oid); 242 goto cleanup; 243 } ··· 296 297 /* 298 * After a mark_query run, this object_info is set up to be 299 + * passed to odb_read_object_info_extended. It will point to the data 300 * elements above, so you can retrieve the response from there. 301 */ 302 struct object_info info; ··· 486 data->info.sizep = &data->size; 487 488 if (pack) 489 + ret = packed_object_info(the_repository, pack, 490 + offset, &data->info); 491 else 492 + ret = odb_read_object_info_extended(the_repository->objects, 493 + &data->oid, &data->info, 494 + OBJECT_INFO_LOOKUP_REPLACE); 495 if (ret < 0) { 496 report_object_status(opt, obj_name, &data->oid, "missing"); 497 return; ··· 874 875 /* 876 * Expand once with our special mark_query flag, which will prime the 877 + * object_info to be handed to odb_read_object_info_extended for each 878 * object. 879 */ 880 memset(&data, 0, sizeof(data));
+2 -1
builtin/describe.c
··· 552 553 if (cmit) 554 describe_commit(&oid, &sb); 555 - else if (oid_object_info(the_repository, &oid, NULL) == OBJ_BLOB) 556 describe_blob(oid, &sb); 557 else 558 die(_("%s is neither a commit nor blob"), arg);
··· 552 553 if (cmit) 554 describe_commit(&oid, &sb); 555 + else if (odb_read_object_info(the_repository->objects, 556 + &oid, NULL) == OBJ_BLOB) 557 describe_blob(oid, &sb); 558 else 559 die(_("%s is neither a commit nor blob"), arg);
+1 -1
builtin/fast-export.c
··· 1200 if (last_idnum < mark) 1201 last_idnum = mark; 1202 1203 - type = oid_object_info(the_repository, &oid, NULL); 1204 if (type < 0) 1205 die("object not found: %s", oid_to_hex(&oid)); 1206
··· 1200 if (last_idnum < mark) 1201 last_idnum = mark; 1202 1203 + type = odb_read_object_info(the_repository->objects, &oid, NULL); 1204 if (type < 0) 1205 die("object not found: %s", oid_to_hex(&oid)); 1206
+9 -8
builtin/fast-import.c
··· 1756 struct object_entry *e; 1757 e = find_object(oid); 1758 if (!e) { 1759 - enum object_type type = oid_object_info(the_repository, 1760 - oid, NULL); 1761 if (type < 0) 1762 die("object not found: %s", oid_to_hex(oid)); 1763 e = insert_object(oid); ··· 2416 enum object_type expected = S_ISDIR(mode) ? 2417 OBJ_TREE: OBJ_BLOB; 2418 enum object_type type = oe ? oe->type : 2419 - oid_object_info(the_repository, &oid, 2420 - NULL); 2421 if (type < 0) 2422 die("%s not found: %s", 2423 S_ISDIR(mode) ? "Tree" : "Blob", ··· 2553 die("Not a blob (actually a %s): %s", 2554 type_name(oe->type), command_buf.buf); 2555 } else if (!is_null_oid(&oid)) { 2556 - enum object_type type = oid_object_info(the_repository, &oid, 2557 NULL); 2558 if (type < 0) 2559 die("Blob not found: %s", command_buf.buf); ··· 2895 } else if (!repo_get_oid(the_repository, from, &oid)) { 2896 struct object_entry *oe = find_object(&oid); 2897 if (!oe) { 2898 - type = oid_object_info(the_repository, &oid, NULL); 2899 if (type < 0) 2900 die("Not a valid object: %s", from); 2901 } else ··· 3085 const unsigned hexsz = the_hash_algo->hexsz; 3086 3087 if (!oe) { 3088 - enum object_type type = oid_object_info(the_repository, oid, 3089 - NULL); 3090 if (type < 0) 3091 die("object not found: %s", oid_to_hex(oid)); 3092 /* cache it! */
··· 1756 struct object_entry *e; 1757 e = find_object(oid); 1758 if (!e) { 1759 + enum object_type type = odb_read_object_info(the_repository->objects, 1760 + oid, NULL); 1761 if (type < 0) 1762 die("object not found: %s", oid_to_hex(oid)); 1763 e = insert_object(oid); ··· 2416 enum object_type expected = S_ISDIR(mode) ? 2417 OBJ_TREE: OBJ_BLOB; 2418 enum object_type type = oe ? oe->type : 2419 + odb_read_object_info(the_repository->objects, 2420 + &oid, NULL); 2421 if (type < 0) 2422 die("%s not found: %s", 2423 S_ISDIR(mode) ? "Tree" : "Blob", ··· 2553 die("Not a blob (actually a %s): %s", 2554 type_name(oe->type), command_buf.buf); 2555 } else if (!is_null_oid(&oid)) { 2556 + enum object_type type = odb_read_object_info(the_repository->objects, &oid, 2557 NULL); 2558 if (type < 0) 2559 die("Blob not found: %s", command_buf.buf); ··· 2895 } else if (!repo_get_oid(the_repository, from, &oid)) { 2896 struct object_entry *oe = find_object(&oid); 2897 if (!oe) { 2898 + type = odb_read_object_info(the_repository->objects, 2899 + &oid, NULL); 2900 if (type < 0) 2901 die("Not a valid object: %s", from); 2902 } else ··· 3086 const unsigned hexsz = the_hash_algo->hexsz; 3087 3088 if (!oe) { 3089 + enum object_type type = odb_read_object_info(the_repository->objects, 3090 + oid, NULL); 3091 if (type < 0) 3092 die("object not found: %s", oid_to_hex(oid)); 3093 /* cache it! */
+4 -3
builtin/fsck.c
··· 71 const char *ret; 72 73 if (type == OBJ_NONE) 74 - type = oid_object_info(the_repository, oid, NULL); 75 76 ret = type_name(type); 77 if (!ret) ··· 232 * (and we want to avoid parsing blobs). 233 */ 234 if (obj->type == OBJ_NONE) { 235 - enum object_type type = oid_object_info(the_repository, 236 - &obj->oid, NULL); 237 if (type > 0) 238 object_as_type(obj, type, 0); 239 }
··· 71 const char *ret; 72 73 if (type == OBJ_NONE) 74 + type = odb_read_object_info(the_repository->objects, 75 + oid, NULL); 76 77 ret = type_name(type); 78 if (!ret) ··· 233 * (and we want to avoid parsing blobs). 234 */ 235 if (obj->type == OBJ_NONE) { 236 + enum object_type type = odb_read_object_info(the_repository->objects, 237 + &obj->oid, NULL); 238 if (type > 0) 239 object_as_type(obj, type, 0); 240 }
+1 -1
builtin/gc.c
··· 1080 1081 if (!peel_iterated_oid(the_repository, oid, &peeled)) 1082 oid = &peeled; 1083 - if (oid_object_info(the_repository, oid, NULL) != OBJ_COMMIT) 1084 return 0; 1085 1086 commit = lookup_commit(the_repository, oid);
··· 1080 1081 if (!peel_iterated_oid(the_repository, oid, &peeled)) 1082 oid = &peeled; 1083 + if (odb_read_object_info(the_repository->objects, oid, NULL) != OBJ_COMMIT) 1084 return 0; 1085 1086 commit = lookup_commit(the_repository, oid);
+1 -1
builtin/grep.c
··· 520 struct strbuf base = STRBUF_INIT; 521 522 obj_read_lock(); 523 - object_type = oid_object_info(subrepo, oid, NULL); 524 obj_read_unlock(); 525 data = read_object_with_reference(subrepo, 526 oid, OBJ_TREE,
··· 520 struct strbuf base = STRBUF_INIT; 521 522 obj_read_lock(); 523 + object_type = odb_read_object_info(subrepo->objects, oid, NULL); 524 obj_read_unlock(); 525 data = read_object_with_reference(subrepo, 526 oid, OBJ_TREE,
+7 -6
builtin/index-pack.c
··· 260 261 if (!(obj->flags & FLAG_CHECKED)) { 262 unsigned long size; 263 - int type = oid_object_info(the_repository, &obj->oid, &size); 264 if (type <= 0) 265 die(_("did not receive expected object %s"), 266 oid_to_hex(&obj->oid)); ··· 908 enum object_type has_type; 909 unsigned long has_size; 910 read_lock(); 911 - has_type = oid_object_info(the_repository, oid, &has_size); 912 if (has_type < 0) 913 die(_("cannot read existing object info %s"), oid_to_hex(oid)); 914 if (has_type != type || has_size != size) ··· 1501 struct oid_array to_fetch = OID_ARRAY_INIT; 1502 for (i = 0; i < nr_ref_deltas; i++) { 1503 struct ref_delta_entry *d = sorted_by_pos[i]; 1504 - if (!oid_object_info_extended(the_repository, &d->oid, 1505 - NULL, 1506 - OBJECT_INFO_FOR_PREFETCH)) 1507 continue; 1508 oid_array_append(&to_fetch, &d->oid); 1509 } ··· 1829 oidset_iter_init(&outgoing_links, &iter); 1830 while ((oid = oidset_iter_next(&iter))) { 1831 struct object_info info = OBJECT_INFO_INIT; 1832 - if (oid_object_info_extended(the_repository, oid, &info, 0)) 1833 /* Missing; assume it is a promisor object */ 1834 continue; 1835 if (info.whence == OI_PACKED && info.u.packed.pack->pack_promisor)
··· 260 261 if (!(obj->flags & FLAG_CHECKED)) { 262 unsigned long size; 263 + int type = odb_read_object_info(the_repository->objects, 264 + &obj->oid, &size); 265 if (type <= 0) 266 die(_("did not receive expected object %s"), 267 oid_to_hex(&obj->oid)); ··· 909 enum object_type has_type; 910 unsigned long has_size; 911 read_lock(); 912 + has_type = odb_read_object_info(the_repository->objects, oid, &has_size); 913 if (has_type < 0) 914 die(_("cannot read existing object info %s"), oid_to_hex(oid)); 915 if (has_type != type || has_size != size) ··· 1502 struct oid_array to_fetch = OID_ARRAY_INIT; 1503 for (i = 0; i < nr_ref_deltas; i++) { 1504 struct ref_delta_entry *d = sorted_by_pos[i]; 1505 + if (!odb_read_object_info_extended(the_repository->objects, 1506 + &d->oid, NULL, 1507 + OBJECT_INFO_FOR_PREFETCH)) 1508 continue; 1509 oid_array_append(&to_fetch, &d->oid); 1510 } ··· 1830 oidset_iter_init(&outgoing_links, &iter); 1831 while ((oid = oidset_iter_next(&iter))) { 1832 struct object_info info = OBJECT_INFO_INIT; 1833 + if (odb_read_object_info_extended(the_repository->objects, oid, &info, 0)) 1834 /* Missing; assume it is a promisor object */ 1835 continue; 1836 if (info.whence == OI_PACKED && info.u.packed.pack->pack_promisor)
+1 -1
builtin/ls-files.c
··· 251 { 252 if (type == OBJ_BLOB) { 253 unsigned long size; 254 - if (oid_object_info(repo, oid, &size) < 0) 255 die(_("could not get object info about '%s'"), 256 oid_to_hex(oid)); 257 if (padded)
··· 251 { 252 if (type == OBJ_BLOB) { 253 unsigned long size; 254 + if (odb_read_object_info(repo->objects, oid, &size) < 0) 255 die(_("could not get object info about '%s'"), 256 oid_to_hex(oid)); 257 if (padded)
+2 -2
builtin/ls-tree.c
··· 27 { 28 if (type == OBJ_BLOB) { 29 unsigned long size; 30 - if (oid_object_info(the_repository, oid, &size) < 0) 31 die(_("could not get object info about '%s'"), 32 oid_to_hex(oid)); 33 if (padded) ··· 217 218 if (type == OBJ_BLOB) { 219 unsigned long size; 220 - if (oid_object_info(the_repository, oid, &size) == OBJ_BAD) 221 xsnprintf(size_text, sizeof(size_text), "BAD"); 222 else 223 xsnprintf(size_text, sizeof(size_text),
··· 27 { 28 if (type == OBJ_BLOB) { 29 unsigned long size; 30 + if (odb_read_object_info(the_repository->objects, oid, &size) < 0) 31 die(_("could not get object info about '%s'"), 32 oid_to_hex(oid)); 33 if (padded) ··· 217 218 if (type == OBJ_BLOB) { 219 unsigned long size; 220 + if (odb_read_object_info(the_repository->objects, oid, &size) == OBJ_BAD) 221 xsnprintf(size_text, sizeof(size_text), "BAD"); 222 else 223 xsnprintf(size_text, sizeof(size_text),
+4 -4
builtin/mktree.c
··· 124 125 /* Check the type of object identified by oid without fetching objects */ 126 oi.typep = &obj_type; 127 - if (oid_object_info_extended(the_repository, &oid, &oi, 128 - OBJECT_INFO_LOOKUP_REPLACE | 129 - OBJECT_INFO_QUICK | 130 - OBJECT_INFO_SKIP_FETCH_OBJECT) < 0) 131 obj_type = -1; 132 133 if (obj_type < 0) {
··· 124 125 /* Check the type of object identified by oid without fetching objects */ 126 oi.typep = &obj_type; 127 + if (odb_read_object_info_extended(the_repository->objects, &oid, &oi, 128 + OBJECT_INFO_LOOKUP_REPLACE | 129 + OBJECT_INFO_QUICK | 130 + OBJECT_INFO_SKIP_FETCH_OBJECT) < 0) 131 obj_type = -1; 132 133 if (obj_type < 0) {
+16 -14
builtin/pack-objects.c
··· 2154 for (i = object_index_start; i < to_pack.nr_objects; i++) { 2155 struct object_entry *entry = to_pack.objects + i; 2156 2157 - if (!oid_object_info_extended(the_repository, 2158 - &entry->idx.oid, 2159 - NULL, 2160 - OBJECT_INFO_FOR_PREFETCH)) 2161 continue; 2162 oid_array_append(&to_fetch, &entry->idx.oid); 2163 } ··· 2298 2299 /* 2300 * No choice but to fall back to the recursive delta walk 2301 - * with oid_object_info() to find about the object type 2302 * at this point... 2303 */ 2304 give_up: 2305 unuse_pack(&w_curs); 2306 } 2307 2308 - if (oid_object_info_extended(the_repository, &entry->idx.oid, &oi, 2309 - OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0) { 2310 if (repo_has_promisor_remote(the_repository)) { 2311 prefetch_to_pack(object_index); 2312 - if (oid_object_info_extended(the_repository, &entry->idx.oid, &oi, 2313 - OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0) 2314 type = -1; 2315 } else { 2316 type = -1; ··· 2384 if (packed_object_info(the_repository, IN_PACK(entry), entry->in_pack_offset, &oi) < 0) { 2385 /* 2386 * We failed to get the info from this pack for some reason; 2387 - * fall back to oid_object_info, which may find another copy. 2388 * And if that fails, the error will be recorded in oe_type(entry) 2389 * and dealt with in prepare_pack(). 2390 */ 2391 oe_set_type(entry, 2392 - oid_object_info(the_repository, &entry->idx.oid, &size)); 2393 } else { 2394 oe_set_type(entry, type); 2395 } ··· 2677 2678 if (e->type_ != OBJ_OFS_DELTA && e->type_ != OBJ_REF_DELTA) { 2679 packing_data_lock(&to_pack); 2680 - if (oid_object_info(the_repository, &e->idx.oid, &size) < 0) 2681 die(_("unable to get size of %s"), 2682 oid_to_hex(&e->idx.oid)); 2683 packing_data_unlock(&to_pack); ··· 4063 static int add_loose_object(const struct object_id *oid, const char *path, 4064 void *data UNUSED) 4065 { 4066 - enum object_type type = oid_object_info(the_repository, oid, NULL); 4067 4068 if (type < 0) { 4069 warning(_("loose object at %s could not be examined"), path); ··· 4449 static int is_not_in_promisor_pack_obj(struct object *obj, void *data UNUSED) 4450 { 4451 struct object_info info = OBJECT_INFO_INIT; 4452 - if (oid_object_info_extended(the_repository, &obj->oid, &info, 0)) 4453 BUG("should_include_obj should only be called on existing objects"); 4454 return info.whence != OI_PACKED || !info.u.packed.pack->pack_promisor; 4455 }
··· 2154 for (i = object_index_start; i < to_pack.nr_objects; i++) { 2155 struct object_entry *entry = to_pack.objects + i; 2156 2157 + if (!odb_read_object_info_extended(the_repository->objects, 2158 + &entry->idx.oid, 2159 + NULL, 2160 + OBJECT_INFO_FOR_PREFETCH)) 2161 continue; 2162 oid_array_append(&to_fetch, &entry->idx.oid); 2163 } ··· 2298 2299 /* 2300 * No choice but to fall back to the recursive delta walk 2301 + * with odb_read_object_info() to find about the object type 2302 * at this point... 2303 */ 2304 give_up: 2305 unuse_pack(&w_curs); 2306 } 2307 2308 + if (odb_read_object_info_extended(the_repository->objects, &entry->idx.oid, &oi, 2309 + OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0) { 2310 if (repo_has_promisor_remote(the_repository)) { 2311 prefetch_to_pack(object_index); 2312 + if (odb_read_object_info_extended(the_repository->objects, &entry->idx.oid, &oi, 2313 + OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0) 2314 type = -1; 2315 } else { 2316 type = -1; ··· 2384 if (packed_object_info(the_repository, IN_PACK(entry), entry->in_pack_offset, &oi) < 0) { 2385 /* 2386 * We failed to get the info from this pack for some reason; 2387 + * fall back to odb_read_object_info, which may find another copy. 2388 * And if that fails, the error will be recorded in oe_type(entry) 2389 * and dealt with in prepare_pack(). 2390 */ 2391 oe_set_type(entry, 2392 + odb_read_object_info(the_repository->objects, 2393 + &entry->idx.oid, &size)); 2394 } else { 2395 oe_set_type(entry, type); 2396 } ··· 2678 2679 if (e->type_ != OBJ_OFS_DELTA && e->type_ != OBJ_REF_DELTA) { 2680 packing_data_lock(&to_pack); 2681 + if (odb_read_object_info(the_repository->objects, 2682 + &e->idx.oid, &size) < 0) 2683 die(_("unable to get size of %s"), 2684 oid_to_hex(&e->idx.oid)); 2685 packing_data_unlock(&to_pack); ··· 4065 static int add_loose_object(const struct object_id *oid, const char *path, 4066 void *data UNUSED) 4067 { 4068 + enum object_type type = odb_read_object_info(the_repository->objects, oid, NULL); 4069 4070 if (type < 0) { 4071 warning(_("loose object at %s could not be examined"), path); ··· 4451 static int is_not_in_promisor_pack_obj(struct object *obj, void *data UNUSED) 4452 { 4453 struct object_info info = OBJECT_INFO_INIT; 4454 + if (odb_read_object_info_extended(the_repository->objects, &obj->oid, &info, 0)) 4455 BUG("should_include_obj should only be called on existing objects"); 4456 return info.whence != OI_PACKED || !info.u.packed.pack->pack_promisor; 4457 }
+2 -2
builtin/prune.c
··· 99 if (st.st_mtime > expire) 100 return 0; 101 if (show_only || verbose) { 102 - enum object_type type = oid_object_info(the_repository, oid, 103 - NULL); 104 printf("%s %s\n", oid_to_hex(oid), 105 (type > 0) ? type_name(type) : "unknown"); 106 }
··· 99 if (st.st_mtime > expire) 100 return 0; 101 if (show_only || verbose) { 102 + enum object_type type = odb_read_object_info(the_repository->objects, 103 + oid, NULL); 104 printf("%s %s\n", oid_to_hex(oid), 105 (type > 0) ? type_name(type) : "unknown"); 106 }
+1 -1
builtin/repack.c
··· 707 if (oidset_insert(&data->seen, oid)) 708 return 0; /* already seen */ 709 710 - if (oid_object_info(the_repository, oid, NULL) != OBJ_COMMIT) 711 return 0; 712 713 fprintf(data->f->fp, "%s%s\n", data->preferred ? "+" : "",
··· 707 if (oidset_insert(&data->seen, oid)) 708 return 0; /* already seen */ 709 710 + if (odb_read_object_info(the_repository->objects, oid, NULL) != OBJ_COMMIT) 711 return 0; 712 713 fprintf(data->f->fp, "%s%s\n", data->preferred ? "+" : "",
+5 -5
builtin/replace.c
··· 65 if (repo_get_oid(data->repo, refname, &object)) 66 return error(_("failed to resolve '%s' as a valid ref"), refname); 67 68 - obj_type = oid_object_info(data->repo, &object, NULL); 69 - repl_type = oid_object_info(data->repo, oid, NULL); 70 71 printf("%s (%s) -> %s (%s)\n", refname, type_name(obj_type), 72 oid_to_hex(oid), type_name(repl_type)); ··· 185 struct strbuf err = STRBUF_INIT; 186 int res = 0; 187 188 - obj_type = oid_object_info(the_repository, object, NULL); 189 - repl_type = oid_object_info(the_repository, repl, NULL); 190 if (!force && obj_type != repl_type) 191 return error(_("Objects must be of the same type.\n" 192 "'%s' points to a replaced object of type '%s'\n" ··· 334 if (repo_get_oid(the_repository, object_ref, &old_oid) < 0) 335 return error(_("not a valid object name: '%s'"), object_ref); 336 337 - type = oid_object_info(the_repository, &old_oid, NULL); 338 if (type < 0) 339 return error(_("unable to get object type for %s"), 340 oid_to_hex(&old_oid));
··· 65 if (repo_get_oid(data->repo, refname, &object)) 66 return error(_("failed to resolve '%s' as a valid ref"), refname); 67 68 + obj_type = odb_read_object_info(data->repo->objects, &object, NULL); 69 + repl_type = odb_read_object_info(data->repo->objects, oid, NULL); 70 71 printf("%s (%s) -> %s (%s)\n", refname, type_name(obj_type), 72 oid_to_hex(oid), type_name(repl_type)); ··· 185 struct strbuf err = STRBUF_INIT; 186 int res = 0; 187 188 + obj_type = odb_read_object_info(the_repository->objects, object, NULL); 189 + repl_type = odb_read_object_info(the_repository->objects, repl, NULL); 190 if (!force && obj_type != repl_type) 191 return error(_("Objects must be of the same type.\n" 192 "'%s' points to a replaced object of type '%s'\n" ··· 334 if (repo_get_oid(the_repository, object_ref, &old_oid) < 0) 335 return error(_("not a valid object name: '%s'"), object_ref); 336 337 + type = odb_read_object_info(the_repository->objects, &old_oid, NULL); 338 if (type < 0) 339 return error(_("unable to get object type for %s"), 340 oid_to_hex(&old_oid));
+4 -2
builtin/rev-list.c
··· 110 off_t size; 111 struct object_info oi = OBJECT_INFO_INIT; 112 oi.disk_sizep = &size; 113 - if (oid_object_info_extended(the_repository, &obj->oid, &oi, 0) < 0) 114 die(_("unable to get disk usage of %s"), oid_to_hex(&obj->oid)); 115 return size; 116 } ··· 346 static int finish_object(struct object *obj, const char *name, void *cb_data) 347 { 348 struct rev_list_info *info = cb_data; 349 - if (oid_object_info_extended(the_repository, &obj->oid, NULL, 0) < 0) { 350 finish_object__ma(obj, name); 351 return 1; 352 }
··· 110 off_t size; 111 struct object_info oi = OBJECT_INFO_INIT; 112 oi.disk_sizep = &size; 113 + if (odb_read_object_info_extended(the_repository->objects, 114 + &obj->oid, &oi, 0) < 0) 115 die(_("unable to get disk usage of %s"), oid_to_hex(&obj->oid)); 116 return size; 117 } ··· 347 static int finish_object(struct object *obj, const char *name, void *cb_data) 348 { 349 struct rev_list_info *info = cb_data; 350 + if (odb_read_object_info_extended(the_repository->objects, 351 + &obj->oid, NULL, 0) < 0) { 352 finish_object__ma(obj, name); 353 return 1; 354 }
+2 -2
builtin/tag.c
··· 304 struct strbuf header = STRBUF_INIT; 305 int should_edit; 306 307 - type = oid_object_info(the_repository, object, NULL); 308 if (type <= OBJ_NONE) 309 die(_("bad object type.")); 310 ··· 401 } 402 403 strbuf_addstr(sb, " ("); 404 - type = oid_object_info(the_repository, oid, NULL); 405 switch (type) { 406 default: 407 strbuf_addstr(sb, "object of unknown type");
··· 304 struct strbuf header = STRBUF_INIT; 305 int should_edit; 306 307 + type = odb_read_object_info(the_repository->objects, object, NULL); 308 if (type <= OBJ_NONE) 309 die(_("bad object type.")); 310 ··· 401 } 402 403 strbuf_addstr(sb, " ("); 404 + type = odb_read_object_info(the_repository->objects, oid, NULL); 405 switch (type) { 406 default: 407 strbuf_addstr(sb, "object of unknown type");
+1 -1
builtin/unpack-objects.c
··· 232 233 if (!(obj->flags & FLAG_OPEN)) { 234 unsigned long size; 235 - int type = oid_object_info(the_repository, &obj->oid, &size); 236 if (type != obj->type || type <= 0) 237 die("object of unexpected type"); 238 obj->flags |= FLAG_WRITTEN;
··· 232 233 if (!(obj->flags & FLAG_OPEN)) { 234 unsigned long size; 235 + int type = odb_read_object_info(the_repository->objects, &obj->oid, &size); 236 if (type != obj->type || type <= 0) 237 die("object of unexpected type"); 238 obj->flags |= FLAG_WRITTEN;
+1 -1
commit-graph.c
··· 1862 1863 if (!peel_iterated_oid(the_repository, oid, &peeled)) 1864 oid = &peeled; 1865 - if (oid_object_info(the_repository, oid, NULL) == OBJ_COMMIT) 1866 oidset_insert(data->commits, oid); 1867 1868 display_progress(data->progress, oidset_size(data->commits));
··· 1862 1863 if (!peel_iterated_oid(the_repository, oid, &peeled)) 1864 oid = &peeled; 1865 + if (odb_read_object_info(the_repository->objects, oid, NULL) == OBJ_COMMIT) 1866 oidset_insert(data->commits, oid); 1867 1868 display_progress(data->progress, oidset_size(data->commits));
+2 -1
commit.c
··· 585 return 0; 586 } 587 588 - if (oid_object_info_extended(r, &item->object.oid, &oi, flags) < 0) 589 return quiet_on_missing ? -1 : 590 error("Could not read %s", 591 oid_to_hex(&item->object.oid));
··· 585 return 0; 586 } 587 588 + if (odb_read_object_info_extended(r->objects, &item->object.oid, 589 + &oi, flags) < 0) 590 return quiet_on_missing ? -1 : 591 error("Could not read %s", 592 oid_to_hex(&item->object.oid));
+9 -9
diff.c
··· 4230 info.contentp = &s->data; 4231 4232 if (options && options->missing_object_cb) { 4233 - if (!oid_object_info_extended(r, &s->oid, &info, 4234 - OBJECT_INFO_LOOKUP_REPLACE | 4235 - OBJECT_INFO_SKIP_FETCH_OBJECT)) 4236 goto object_read; 4237 options->missing_object_cb(options->missing_object_data); 4238 } 4239 - if (oid_object_info_extended(r, &s->oid, &info, 4240 - OBJECT_INFO_LOOKUP_REPLACE)) 4241 die("unable to read %s", oid_to_hex(&s->oid)); 4242 4243 object_read: ··· 4252 } 4253 if (!info.contentp) { 4254 info.contentp = &s->data; 4255 - if (oid_object_info_extended(r, &s->oid, &info, 4256 - OBJECT_INFO_LOOKUP_REPLACE)) 4257 die("unable to read %s", oid_to_hex(&s->oid)); 4258 } 4259 s->should_free = 1; ··· 7019 { 7020 if (filespec && filespec->oid_valid && 7021 !S_ISGITLINK(filespec->mode) && 7022 - oid_object_info_extended(r, &filespec->oid, NULL, 7023 - OBJECT_INFO_FOR_PREFETCH)) 7024 oid_array_append(to_fetch, &filespec->oid); 7025 } 7026
··· 4230 info.contentp = &s->data; 4231 4232 if (options && options->missing_object_cb) { 4233 + if (!odb_read_object_info_extended(r->objects, &s->oid, &info, 4234 + OBJECT_INFO_LOOKUP_REPLACE | 4235 + OBJECT_INFO_SKIP_FETCH_OBJECT)) 4236 goto object_read; 4237 options->missing_object_cb(options->missing_object_data); 4238 } 4239 + if (odb_read_object_info_extended(r->objects, &s->oid, &info, 4240 + OBJECT_INFO_LOOKUP_REPLACE)) 4241 die("unable to read %s", oid_to_hex(&s->oid)); 4242 4243 object_read: ··· 4252 } 4253 if (!info.contentp) { 4254 info.contentp = &s->data; 4255 + if (odb_read_object_info_extended(r->objects, &s->oid, &info, 4256 + OBJECT_INFO_LOOKUP_REPLACE)) 4257 die("unable to read %s", oid_to_hex(&s->oid)); 4258 } 4259 s->should_free = 1; ··· 7019 { 7020 if (filespec && filespec->oid_valid && 7021 !S_ISGITLINK(filespec->mode) && 7022 + odb_read_object_info_extended(r->objects, &filespec->oid, NULL, 7023 + OBJECT_INFO_FOR_PREFETCH)) 7024 oid_array_append(to_fetch, &filespec->oid); 7025 } 7026
+2 -2
fetch-pack.c
··· 149 } 150 151 while (1) { 152 - if (oid_object_info_extended(the_repository, oid, &info, 153 - OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK)) 154 return NULL; 155 if (type == OBJ_TAG) { 156 struct tag *tag = (struct tag *)
··· 149 } 150 151 while (1) { 152 + if (odb_read_object_info_extended(the_repository->objects, oid, &info, 153 + OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK)) 154 return NULL; 155 if (type == OBJ_TAG) { 156 struct tag *tag = (struct tag *)
+1 -1
list-objects-filter.c
··· 310 assert(obj->type == OBJ_BLOB); 311 assert((obj->flags & SEEN) == 0); 312 313 - t = oid_object_info(r, &obj->oid, &object_length); 314 if (t != OBJ_BLOB) { /* probably OBJ_NONE */ 315 /* 316 * We DO NOT have the blob locally, so we cannot
··· 310 assert(obj->type == OBJ_BLOB); 311 assert((obj->flags & SEEN) == 0); 312 313 + t = odb_read_object_info(r->objects, &obj->oid, &object_length); 314 if (t != OBJ_BLOB) { /* probably OBJ_NONE */ 315 /* 316 * We DO NOT have the blob locally, so we cannot
+1 -1
log-tree.c
··· 176 return 0; 177 } 178 179 - objtype = oid_object_info(the_repository, oid, NULL); 180 if (objtype < 0) 181 return 0; 182 obj = lookup_object_by_type(the_repository, oid, objtype);
··· 176 return 0; 177 } 178 179 + objtype = odb_read_object_info(the_repository->objects, oid, NULL); 180 if (objtype < 0) 181 return 0; 182 obj = lookup_object_by_type(the_repository, oid, objtype);
+2 -2
merge-ort.c
··· 4385 4386 if ((ci->filemask & side_mask) && 4387 S_ISREG(vi->mode) && 4388 - oid_object_info_extended(opt->repo, &vi->oid, NULL, 4389 - OBJECT_INFO_FOR_PREFETCH)) 4390 oid_array_append(&to_fetch, &vi->oid); 4391 } 4392 }
··· 4385 4386 if ((ci->filemask & side_mask) && 4387 S_ISREG(vi->mode) && 4388 + odb_read_object_info_extended(opt->repo->objects, &vi->oid, NULL, 4389 + OBJECT_INFO_FOR_PREFETCH)) 4390 oid_array_append(&to_fetch, &vi->oid); 4391 } 4392 }
+1 -1
object-file.c
··· 1108 oi.typep = &type; 1109 oi.sizep = &len; 1110 oi.contentp = &buf; 1111 - if (oid_object_info_extended(the_repository, oid, &oi, 0)) 1112 return error(_("cannot read object for %s"), oid_to_hex(oid)); 1113 if (compat) { 1114 if (repo_oid_to_algop(repo, oid, compat, &compat_oid))
··· 1108 oi.typep = &type; 1109 oi.sizep = &len; 1110 oi.contentp = &buf; 1111 + if (odb_read_object_info_extended(the_repository->objects, oid, &oi, 0)) 1112 return error(_("cannot read object for %s"), oid_to_hex(oid)); 1113 if (compat) { 1114 if (repo_oid_to_algop(repo, oid, compat, &compat_oid))
+1 -1
object-file.h
··· 8 struct index_state; 9 10 /* 11 - * Set this to 0 to prevent oid_object_info_extended() from fetching missing 12 * blobs. This has a difference only if extensions.partialClone is set. 13 * 14 * Its default value is 1.
··· 8 struct index_state; 9 10 /* 11 + * Set this to 0 to prevent odb_read_object_info_extended() from fetching missing 12 * blobs. This has a difference only if extensions.partialClone is set. 13 * 14 * Its default value is 1.
+8 -8
object-name.c
··· 251 const struct object_id *oid, 252 void *cb_data UNUSED) 253 { 254 - int kind = oid_object_info(r, oid, NULL); 255 return kind == OBJ_COMMIT; 256 } 257 ··· 262 struct object *obj; 263 int kind; 264 265 - kind = oid_object_info(r, oid, NULL); 266 if (kind == OBJ_COMMIT) 267 return 1; 268 if (kind != OBJ_TAG) ··· 279 const struct object_id *oid, 280 void *cb_data UNUSED) 281 { 282 - int kind = oid_object_info(r, oid, NULL); 283 return kind == OBJ_TREE; 284 } 285 ··· 290 struct object *obj; 291 int kind; 292 293 - kind = oid_object_info(r, oid, NULL); 294 if (kind == OBJ_TREE || kind == OBJ_COMMIT) 295 return 1; 296 if (kind != OBJ_TAG) ··· 307 const struct object_id *oid, 308 void *cb_data UNUSED) 309 { 310 - int kind = oid_object_info(r, oid, NULL); 311 return kind == OBJ_BLOB; 312 } 313 ··· 399 return 0; 400 401 hash = repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV); 402 - type = oid_object_info(ds->repo, oid, NULL); 403 404 if (type < 0) { 405 /* ··· 514 { 515 struct repository *sort_ambiguous_repo = ctx; 516 const struct object_id *a = va, *b = vb; 517 - int a_type = oid_object_info(sort_ambiguous_repo, a, NULL); 518 - int b_type = oid_object_info(sort_ambiguous_repo, b, NULL); 519 int a_type_sort; 520 int b_type_sort; 521
··· 251 const struct object_id *oid, 252 void *cb_data UNUSED) 253 { 254 + int kind = odb_read_object_info(r->objects, oid, NULL); 255 return kind == OBJ_COMMIT; 256 } 257 ··· 262 struct object *obj; 263 int kind; 264 265 + kind = odb_read_object_info(r->objects, oid, NULL); 266 if (kind == OBJ_COMMIT) 267 return 1; 268 if (kind != OBJ_TAG) ··· 279 const struct object_id *oid, 280 void *cb_data UNUSED) 281 { 282 + int kind = odb_read_object_info(r->objects, oid, NULL); 283 return kind == OBJ_TREE; 284 } 285 ··· 290 struct object *obj; 291 int kind; 292 293 + kind = odb_read_object_info(r->objects, oid, NULL); 294 if (kind == OBJ_TREE || kind == OBJ_COMMIT) 295 return 1; 296 if (kind != OBJ_TAG) ··· 307 const struct object_id *oid, 308 void *cb_data UNUSED) 309 { 310 + int kind = odb_read_object_info(r->objects, oid, NULL); 311 return kind == OBJ_BLOB; 312 } 313 ··· 399 return 0; 400 401 hash = repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV); 402 + type = odb_read_object_info(ds->repo->objects, oid, NULL); 403 404 if (type < 0) { 405 /* ··· 514 { 515 struct repository *sort_ambiguous_repo = ctx; 516 const struct object_id *a = va, *b = vb; 517 + int a_type = odb_read_object_info(sort_ambiguous_repo->objects, a, NULL); 518 + int b_type = odb_read_object_info(sort_ambiguous_repo->objects, b, NULL); 519 int a_type_sort; 520 int b_type_sort; 521
+3 -3
object.c
··· 214 struct object *o = lookup_unknown_object(r, name); 215 216 if (o->type == OBJ_NONE) { 217 - int type = oid_object_info(r, name, NULL); 218 if (type < 0 || !object_as_type(o, type, 0)) 219 return PEEL_INVALID; 220 } ··· 315 } 316 317 if ((!obj || obj->type == OBJ_BLOB) && 318 - oid_object_info(r, oid, NULL) == OBJ_BLOB) { 319 if (!skip_hash && stream_object_signature(r, repl) < 0) { 320 error(_("hash mismatch %s"), oid_to_hex(oid)); 321 return NULL; ··· 331 */ 332 if (skip_hash && discard_tree && 333 (!obj || obj->type == OBJ_TREE) && 334 - oid_object_info(r, oid, NULL) == OBJ_TREE) { 335 return &lookup_tree(r, oid)->object; 336 } 337
··· 214 struct object *o = lookup_unknown_object(r, name); 215 216 if (o->type == OBJ_NONE) { 217 + int type = odb_read_object_info(r->objects, name, NULL); 218 if (type < 0 || !object_as_type(o, type, 0)) 219 return PEEL_INVALID; 220 } ··· 315 } 316 317 if ((!obj || obj->type == OBJ_BLOB) && 318 + odb_read_object_info(r->objects, oid, NULL) == OBJ_BLOB) { 319 if (!skip_hash && stream_object_signature(r, repl) < 0) { 320 error(_("hash mismatch %s"), oid_to_hex(oid)); 321 return NULL; ··· 331 */ 332 if (skip_hash && discard_tree && 333 (!obj || obj->type == OBJ_TREE) && 334 + odb_read_object_info(r->objects, oid, NULL) == OBJ_TREE) { 335 return &lookup_tree(r, oid)->object; 336 } 337
+31 -29
odb.c
··· 647 return ret; 648 } 649 650 - static int do_oid_object_info_extended(struct repository *r, 651 const struct object_id *oid, 652 struct object_info *oi, unsigned flags) 653 { ··· 660 661 662 if (flags & OBJECT_INFO_LOOKUP_REPLACE) 663 - real = lookup_replace_object(r, oid); 664 665 if (is_null_oid(real)) 666 return -1; ··· 668 if (!oi) 669 oi = &blank_oi; 670 671 - co = find_cached_object(r->objects, real); 672 if (co) { 673 if (oi->typep) 674 *(oi->typep) = co->type; ··· 677 if (oi->disk_sizep) 678 *(oi->disk_sizep) = 0; 679 if (oi->delta_base_oid) 680 - oidclr(oi->delta_base_oid, r->hash_algo); 681 if (oi->contentp) 682 *oi->contentp = xmemdupz(co->buf, co->size); 683 oi->whence = OI_CACHED; ··· 685 } 686 687 while (1) { 688 - if (find_pack_entry(r, real, &e)) 689 break; 690 691 /* Most likely it's a loose object. */ 692 - if (!loose_object_info(r, real, oi, flags)) 693 return 0; 694 695 /* Not a loose object; someone else may have just packed it. */ 696 if (!(flags & OBJECT_INFO_QUICK)) { 697 - reprepare_packed_git(r); 698 - if (find_pack_entry(r, real, &e)) 699 break; 700 } 701 ··· 705 * `odb_add_submodule_source_by_path()` on that submodule's 706 * ODB). If any such ODBs exist, register them and try again. 707 */ 708 - if (register_all_submodule_sources(r->objects)) 709 /* We added some alternates; retry */ 710 continue; 711 712 /* Check if it is a missing object */ 713 - if (fetch_if_missing && repo_has_promisor_remote(r) && 714 !already_retried && 715 !(flags & OBJECT_INFO_SKIP_FETCH_OBJECT)) { 716 - promisor_remote_get_direct(r, real, 1); 717 already_retried = 1; 718 continue; 719 } ··· 723 if ((flags & OBJECT_INFO_LOOKUP_REPLACE) && !oideq(real, oid)) 724 die(_("replacement %s not found for %s"), 725 oid_to_hex(real), oid_to_hex(oid)); 726 - if ((p = has_packed_and_bad(r, real))) 727 die(_("packed object %s (stored in %s) is corrupt"), 728 oid_to_hex(real), p->pack_name); 729 } ··· 736 * information below, so return early. 737 */ 738 return 0; 739 - rtype = packed_object_info(r, e.p, e.offset, oi); 740 if (rtype < 0) { 741 mark_bad_packed_object(e.p, real); 742 - return do_oid_object_info_extended(r, real, oi, 0); 743 } else if (oi->whence == OI_PACKED) { 744 oi->u.packed.offset = e.offset; 745 oi->u.packed.pack = e.p; ··· 787 oi = &new_oi; 788 } 789 790 - ret = oid_object_info_extended(r, &oid, oi, flags); 791 if (ret) 792 return -1; 793 if (oi == input_oi) ··· 830 return ret; 831 } 832 833 - int oid_object_info_extended(struct repository *r, const struct object_id *oid, 834 - struct object_info *oi, unsigned flags) 835 { 836 int ret; 837 838 - if (oid->algo && (hash_algo_by_ptr(r->hash_algo) != oid->algo)) 839 - return oid_object_info_convert(r, oid, oi, flags); 840 841 obj_read_lock(); 842 - ret = do_oid_object_info_extended(r, oid, oi, flags); 843 obj_read_unlock(); 844 return ret; 845 } 846 847 848 /* returns enum object_type or negative */ 849 - int oid_object_info(struct repository *r, 850 - const struct object_id *oid, 851 - unsigned long *sizep) 852 { 853 enum object_type type; 854 struct object_info oi = OBJECT_INFO_INIT; 855 856 oi.typep = &type; 857 oi.sizep = sizep; 858 - if (oid_object_info_extended(r, oid, &oi, 859 - OBJECT_INFO_LOOKUP_REPLACE) < 0) 860 return -1; 861 return type; 862 } ··· 887 888 /* 889 * This function dies on corrupt objects; the callers who want to 890 - * deal with them should arrange to call oid_object_info_extended() and give 891 * error messages themselves. 892 */ 893 void *repo_read_object_file(struct repository *r, ··· 902 oi.typep = type; 903 oi.sizep = size; 904 oi.contentp = &data; 905 - if (oid_object_info_extended(r, oid, &oi, flags)) 906 return NULL; 907 908 return data; ··· 968 if (!(flags & HAS_OBJECT_FETCH_PROMISOR)) 969 object_info_flags |= OBJECT_INFO_SKIP_FETCH_OBJECT; 970 971 - return oid_object_info_extended(r, oid, NULL, object_info_flags) >= 0; 972 } 973 974 void odb_assert_oid_type(struct object_database *odb, 975 const struct object_id *oid, enum object_type expect) 976 { 977 - enum object_type type = oid_object_info(odb->repo, oid, NULL); 978 if (type < 0) 979 die(_("%s is not a valid object"), oid_to_hex(oid)); 980 if (type != expect)
··· 647 return ret; 648 } 649 650 + static int do_oid_object_info_extended(struct object_database *odb, 651 const struct object_id *oid, 652 struct object_info *oi, unsigned flags) 653 { ··· 660 661 662 if (flags & OBJECT_INFO_LOOKUP_REPLACE) 663 + real = lookup_replace_object(odb->repo, oid); 664 665 if (is_null_oid(real)) 666 return -1; ··· 668 if (!oi) 669 oi = &blank_oi; 670 671 + co = find_cached_object(odb, real); 672 if (co) { 673 if (oi->typep) 674 *(oi->typep) = co->type; ··· 677 if (oi->disk_sizep) 678 *(oi->disk_sizep) = 0; 679 if (oi->delta_base_oid) 680 + oidclr(oi->delta_base_oid, odb->repo->hash_algo); 681 if (oi->contentp) 682 *oi->contentp = xmemdupz(co->buf, co->size); 683 oi->whence = OI_CACHED; ··· 685 } 686 687 while (1) { 688 + if (find_pack_entry(odb->repo, real, &e)) 689 break; 690 691 /* Most likely it's a loose object. */ 692 + if (!loose_object_info(odb->repo, real, oi, flags)) 693 return 0; 694 695 /* Not a loose object; someone else may have just packed it. */ 696 if (!(flags & OBJECT_INFO_QUICK)) { 697 + reprepare_packed_git(odb->repo); 698 + if (find_pack_entry(odb->repo, real, &e)) 699 break; 700 } 701 ··· 705 * `odb_add_submodule_source_by_path()` on that submodule's 706 * ODB). If any such ODBs exist, register them and try again. 707 */ 708 + if (register_all_submodule_sources(odb)) 709 /* We added some alternates; retry */ 710 continue; 711 712 /* Check if it is a missing object */ 713 + if (fetch_if_missing && repo_has_promisor_remote(odb->repo) && 714 !already_retried && 715 !(flags & OBJECT_INFO_SKIP_FETCH_OBJECT)) { 716 + promisor_remote_get_direct(odb->repo, real, 1); 717 already_retried = 1; 718 continue; 719 } ··· 723 if ((flags & OBJECT_INFO_LOOKUP_REPLACE) && !oideq(real, oid)) 724 die(_("replacement %s not found for %s"), 725 oid_to_hex(real), oid_to_hex(oid)); 726 + if ((p = has_packed_and_bad(odb->repo, real))) 727 die(_("packed object %s (stored in %s) is corrupt"), 728 oid_to_hex(real), p->pack_name); 729 } ··· 736 * information below, so return early. 737 */ 738 return 0; 739 + rtype = packed_object_info(odb->repo, e.p, e.offset, oi); 740 if (rtype < 0) { 741 mark_bad_packed_object(e.p, real); 742 + return do_oid_object_info_extended(odb, real, oi, 0); 743 } else if (oi->whence == OI_PACKED) { 744 oi->u.packed.offset = e.offset; 745 oi->u.packed.pack = e.p; ··· 787 oi = &new_oi; 788 } 789 790 + ret = odb_read_object_info_extended(r->objects, &oid, oi, flags); 791 if (ret) 792 return -1; 793 if (oi == input_oi) ··· 830 return ret; 831 } 832 833 + int odb_read_object_info_extended(struct object_database *odb, 834 + const struct object_id *oid, 835 + struct object_info *oi, 836 + unsigned flags) 837 { 838 int ret; 839 840 + if (oid->algo && (hash_algo_by_ptr(odb->repo->hash_algo) != oid->algo)) 841 + return oid_object_info_convert(odb->repo, oid, oi, flags); 842 843 obj_read_lock(); 844 + ret = do_oid_object_info_extended(odb, oid, oi, flags); 845 obj_read_unlock(); 846 return ret; 847 } 848 849 850 /* returns enum object_type or negative */ 851 + int odb_read_object_info(struct object_database *odb, 852 + const struct object_id *oid, 853 + unsigned long *sizep) 854 { 855 enum object_type type; 856 struct object_info oi = OBJECT_INFO_INIT; 857 858 oi.typep = &type; 859 oi.sizep = sizep; 860 + if (odb_read_object_info_extended(odb, oid, &oi, 861 + OBJECT_INFO_LOOKUP_REPLACE) < 0) 862 return -1; 863 return type; 864 } ··· 889 890 /* 891 * This function dies on corrupt objects; the callers who want to 892 + * deal with them should arrange to call odb_read_object_info_extended() and give 893 * error messages themselves. 894 */ 895 void *repo_read_object_file(struct repository *r, ··· 904 oi.typep = type; 905 oi.sizep = size; 906 oi.contentp = &data; 907 + if (odb_read_object_info_extended(r->objects, oid, &oi, flags)) 908 return NULL; 909 910 return data; ··· 970 if (!(flags & HAS_OBJECT_FETCH_PROMISOR)) 971 object_info_flags |= OBJECT_INFO_SKIP_FETCH_OBJECT; 972 973 + return odb_read_object_info_extended(r->objects, oid, NULL, object_info_flags) >= 0; 974 } 975 976 void odb_assert_oid_type(struct object_database *odb, 977 const struct object_id *oid, enum object_type expect) 978 { 979 + enum object_type type = odb_read_object_info(odb, oid, NULL); 980 if (type < 0) 981 die(_("%s is not a valid object"), oid_to_hex(oid)); 982 if (type != expect)
+38 -8
odb.h
··· 265 enum object_type *type, 266 unsigned long *size); 267 268 - /* Read and unpack an object file into memory, write memory to an object file */ 269 - int oid_object_info(struct repository *r, const struct object_id *, unsigned long *); 270 - 271 /* 272 * Add an object file to the in-memory object store, without writing it 273 * to disk. ··· 336 /* Die if object corruption (not just an object being missing) was detected. */ 337 #define OBJECT_INFO_DIE_IF_CORRUPT 32 338 339 - int oid_object_info_extended(struct repository *r, 340 - const struct object_id *, 341 - struct object_info *, unsigned flags); 342 343 enum { 344 /* Retry packed storage after checking packed and loose storage */ ··· 360 /* 361 * Enabling the object read lock allows multiple threads to safely call the 362 * following functions in parallel: repo_read_object_file(), 363 - * read_object_with_reference(), oid_object_info() and oid_object_info_extended(). 364 * 365 * obj_read_lock() and obj_read_unlock() may also be used to protect other 366 * section which cannot execute in parallel with object reading. Since the used ··· 368 * reading functions. However, beware that in these cases zlib inflation won't 369 * be performed in parallel, losing performance. 370 * 371 - * TODO: oid_object_info_extended()'s call stack has a recursive behavior. If 372 * any of its callees end up calling it, this recursive call won't benefit from 373 * parallel inflation. 374 */ ··· 415 enum object_type required_type, 416 unsigned long *size, 417 struct object_id *oid_ret); 418 419 #endif /* ODB_H */
··· 265 enum object_type *type, 266 unsigned long *size); 267 268 /* 269 * Add an object file to the in-memory object store, without writing it 270 * to disk. ··· 333 /* Die if object corruption (not just an object being missing) was detected. */ 334 #define OBJECT_INFO_DIE_IF_CORRUPT 32 335 336 + /* 337 + * Read object info from the object database and populate the `object_info` 338 + * structure. Returns 0 on success, a negative error code otherwise. 339 + */ 340 + int odb_read_object_info_extended(struct object_database *odb, 341 + const struct object_id *oid, 342 + struct object_info *oi, 343 + unsigned flags); 344 + 345 + /* 346 + * Read a subset of object info for the given object ID. Returns an `enum 347 + * object_type` on success, a negative error code otherwise. If successful and 348 + * `sizep` is non-NULL, then the size of the object will be written to the 349 + * pointer. 350 + */ 351 + int odb_read_object_info(struct object_database *odb, 352 + const struct object_id *oid, 353 + unsigned long *sizep); 354 355 enum { 356 /* Retry packed storage after checking packed and loose storage */ ··· 372 /* 373 * Enabling the object read lock allows multiple threads to safely call the 374 * following functions in parallel: repo_read_object_file(), 375 + * read_object_with_reference(), odb_read_object_info() and odb(). 376 * 377 * obj_read_lock() and obj_read_unlock() may also be used to protect other 378 * section which cannot execute in parallel with object reading. Since the used ··· 380 * reading functions. However, beware that in these cases zlib inflation won't 381 * be performed in parallel, losing performance. 382 * 383 + * TODO: odb_read_object_info_extended()'s call stack has a recursive behavior. If 384 * any of its callees end up calling it, this recursive call won't benefit from 385 * parallel inflation. 386 */ ··· 427 enum object_type required_type, 428 unsigned long *size, 429 struct object_id *oid_ret); 430 + 431 + /* Compatibility wrappers, to be removed once Git 2.51 has been released. */ 432 + #include "repository.h" 433 + 434 + static inline int oid_object_info_extended(struct repository *r, 435 + const struct object_id *oid, 436 + struct object_info *oi, 437 + unsigned flags) 438 + { 439 + return odb_read_object_info_extended(r->objects, oid, oi, flags); 440 + } 441 + 442 + static inline int oid_object_info(struct repository *r, 443 + const struct object_id *oid, 444 + unsigned long *sizep) 445 + { 446 + return odb_read_object_info(r->objects, oid, sizep); 447 + } 448 449 #endif /* ODB_H */
+2 -2
pack-bitmap-write.c
··· 144 break; 145 146 default: 147 - real_type = oid_object_info(writer->to_pack->repo, 148 - &entry->idx.oid, NULL); 149 break; 150 } 151
··· 144 break; 145 146 default: 147 + real_type = odb_read_object_info(writer->to_pack->repo->objects, 148 + &entry->idx.oid, NULL); 149 break; 150 } 151
+4 -4
pack-bitmap.c
··· 1868 size_t eindex_pos = pos - bitmap_num_objects_total(bitmap_git); 1869 struct eindex *eindex = &bitmap_git->ext_index; 1870 struct object *obj = eindex->objects[eindex_pos]; 1871 - if (oid_object_info_extended(bitmap_repo(bitmap_git), &obj->oid, 1872 - &oi, 0) < 0) 1873 die(_("unable to get size of %s"), oid_to_hex(&obj->oid)); 1874 } 1875 ··· 3220 i))) 3221 continue; 3222 3223 - if (oid_object_info_extended(bitmap_repo(bitmap_git), &obj->oid, 3224 - &oi, 0) < 0) 3225 die(_("unable to get disk usage of '%s'"), 3226 oid_to_hex(&obj->oid)); 3227
··· 1868 size_t eindex_pos = pos - bitmap_num_objects_total(bitmap_git); 1869 struct eindex *eindex = &bitmap_git->ext_index; 1870 struct object *obj = eindex->objects[eindex_pos]; 1871 + if (odb_read_object_info_extended(bitmap_repo(bitmap_git)->objects, &obj->oid, 1872 + &oi, 0) < 0) 1873 die(_("unable to get size of %s"), oid_to_hex(&obj->oid)); 1874 } 1875 ··· 3220 i))) 3221 continue; 3222 3223 + if (odb_read_object_info_extended(bitmap_repo(bitmap_git)->objects, 3224 + &obj->oid, &oi, 0) < 0) 3225 die(_("unable to get disk usage of '%s'"), 3226 oid_to_hex(&obj->oid)); 3227
+3 -2
packfile.c
··· 1321 return OBJ_BAD; 1322 nth_packed_object_id(&oid, p, pack_pos_to_index(p, pos)); 1323 mark_bad_packed_object(p, &oid); 1324 - type = oid_object_info(r, &oid, NULL); 1325 if (type <= OBJ_NONE) 1326 return OBJ_BAD; 1327 return type; ··· 1849 oi.typep = &type; 1850 oi.sizep = &base_size; 1851 oi.contentp = &base; 1852 - if (oid_object_info_extended(r, &base_oid, &oi, 0) < 0) 1853 base = NULL; 1854 1855 external_base = base;
··· 1321 return OBJ_BAD; 1322 nth_packed_object_id(&oid, p, pack_pos_to_index(p, pos)); 1323 mark_bad_packed_object(p, &oid); 1324 + type = odb_read_object_info(r->objects, &oid, NULL); 1325 if (type <= OBJ_NONE) 1326 return OBJ_BAD; 1327 return type; ··· 1849 oi.typep = &type; 1850 oi.sizep = &base_size; 1851 oi.contentp = &base; 1852 + if (odb_read_object_info_extended(r->objects, &base_oid, 1853 + &oi, 0) < 0) 1854 base = NULL; 1855 1856 external_base = base;
+2 -2
promisor-remote.c
··· 245 struct object_id *new_oids; 246 247 for (i = 0; i < oid_nr; i++) 248 - if (oid_object_info_extended(repo, &old_oids[i], NULL, 249 - OBJECT_INFO_SKIP_FETCH_OBJECT)) { 250 remaining[i] = 1; 251 remaining_nr++; 252 }
··· 245 struct object_id *new_oids; 246 247 for (i = 0; i < oid_nr; i++) 248 + if (odb_read_object_info_extended(repo->objects, &old_oids[i], NULL, 249 + OBJECT_INFO_SKIP_FETCH_OBJECT)) { 250 remaining[i] = 1; 251 remaining_nr++; 252 }
+1 -1
protocol-caps.c
··· 64 strbuf_addstr(&send_buffer, oid_str); 65 66 if (info->size) { 67 - if (oid_object_info(r, &oid, &object_size) < 0) { 68 strbuf_addstr(&send_buffer, " "); 69 } else { 70 strbuf_addf(&send_buffer, " %lu", object_size);
··· 64 strbuf_addstr(&send_buffer, oid_str); 65 66 if (info->size) { 67 + if (odb_read_object_info(r->objects, &oid, &object_size) < 0) { 68 strbuf_addstr(&send_buffer, " "); 69 } else { 70 strbuf_addf(&send_buffer, " %lu", object_size);
+1 -1
reachable.c
··· 211 * later processing, and the revision machinery expects 212 * commits and tags to have been parsed. 213 */ 214 - type = oid_object_info(the_repository, oid, NULL); 215 if (type < 0) 216 die("unable to get object info for %s", oid_to_hex(oid)); 217
··· 211 * later processing, and the revision machinery expects 212 * commits and tags to have been parsed. 213 */ 214 + type = odb_read_object_info(the_repository->objects, oid, NULL); 215 if (type < 0) 216 die("unable to get object info for %s", oid_to_hex(oid)); 217
+3 -3
read-cache.c
··· 3729 3730 if (S_ISGITLINK(ce->ce_mode) || !must_prefetch(ce)) 3731 continue; 3732 - if (!oid_object_info_extended(the_repository, &ce->oid, 3733 - NULL, 3734 - OBJECT_INFO_FOR_PREFETCH)) 3735 continue; 3736 oid_array_append(&to_fetch, &ce->oid); 3737 }
··· 3729 3730 if (S_ISGITLINK(ce->ce_mode) || !must_prefetch(ce)) 3731 continue; 3732 + if (!odb_read_object_info_extended(the_repository->objects, 3733 + &ce->oid, NULL, 3734 + OBJECT_INFO_FOR_PREFETCH)) 3735 continue; 3736 oid_array_append(&to_fetch, &ce->oid); 3737 }
+2 -2
ref-filter.c
··· 2302 oi->info.sizep = &oi->size; 2303 oi->info.typep = &oi->type; 2304 } 2305 - if (oid_object_info_extended(the_repository, &oi->oid, &oi->info, 2306 - OBJECT_INFO_LOOKUP_REPLACE)) 2307 return strbuf_addf_ret(err, -1, _("missing object %s for %s"), 2308 oid_to_hex(&oi->oid), ref->refname); 2309 if (oi->info.disk_sizep && oi->disk_size < 0)
··· 2302 oi->info.sizep = &oi->size; 2303 oi->info.typep = &oi->type; 2304 } 2305 + if (odb_read_object_info_extended(the_repository->objects, &oi->oid, &oi->info, 2306 + OBJECT_INFO_LOOKUP_REPLACE)) 2307 return strbuf_addf_ret(err, -1, _("missing object %s for %s"), 2308 oid_to_hex(&oi->oid), ref->refname); 2309 if (oi->info.disk_sizep && oi->disk_size < 0)
+3 -2
remote.c
··· 1182 BUG("'%s' is not a valid object, " 1183 "match_explicit_lhs() should catch this!", 1184 matched_src_name); 1185 - type = oid_object_info(the_repository, &oid, NULL); 1186 if (type == OBJ_COMMIT) { 1187 advise(_("The <src> part of the refspec is a commit object.\n" 1188 "Did you mean to create a new branch by pushing to\n" ··· 1412 continue; /* not a tag */ 1413 if (string_list_has_string(&dst_tag, ref->name)) 1414 continue; /* they already have it */ 1415 - if (oid_object_info(the_repository, &ref->new_oid, NULL) != OBJ_TAG) 1416 continue; /* be conservative */ 1417 item = string_list_append(&src_tag, ref->name); 1418 item->util = ref;
··· 1182 BUG("'%s' is not a valid object, " 1183 "match_explicit_lhs() should catch this!", 1184 matched_src_name); 1185 + type = odb_read_object_info(the_repository->objects, &oid, NULL); 1186 if (type == OBJ_COMMIT) { 1187 advise(_("The <src> part of the refspec is a commit object.\n" 1188 "Did you mean to create a new branch by pushing to\n" ··· 1412 continue; /* not a tag */ 1413 if (string_list_has_string(&dst_tag, ref->name)) 1414 continue; /* they already have it */ 1415 + if (odb_read_object_info(the_repository->objects, 1416 + &ref->new_oid, NULL) != OBJ_TAG) 1417 continue; /* be conservative */ 1418 item = string_list_append(&src_tag, ref->name); 1419 item->util = ref;
+2 -3
sequencer.c
··· 5503 5504 if (!repo_get_oid(r, name, &oid)) { 5505 if (!lookup_commit_reference_gently(r, &oid, 1)) { 5506 - enum object_type type = oid_object_info(r, 5507 - &oid, 5508 - NULL); 5509 res = error(_("%s: can't cherry-pick a %s"), 5510 name, type_name(type)); 5511 goto out;
··· 5503 5504 if (!repo_get_oid(r, name, &oid)) { 5505 if (!lookup_commit_reference_gently(r, &oid, 1)) { 5506 + enum object_type type = odb_read_object_info(r->objects, 5507 + &oid, NULL); 5508 res = error(_("%s: can't cherry-pick a %s"), 5509 name, type_name(type)); 5510 goto out;
+4 -4
streaming.c
··· 44 45 union { 46 struct { 47 - char *buf; /* from oid_object_info_extended() */ 48 unsigned long read_ptr; 49 } incore; 50 ··· 403 oi.typep = type; 404 oi.sizep = &st->size; 405 oi.contentp = (void **)&st->u.incore.buf; 406 - return oid_object_info_extended(r, oid, &oi, 407 - OBJECT_INFO_DIE_IF_CORRUPT); 408 } 409 410 /***************************************************************************** ··· 422 423 oi.typep = type; 424 oi.sizep = &size; 425 - status = oid_object_info_extended(r, oid, &oi, 0); 426 if (status < 0) 427 return status; 428
··· 44 45 union { 46 struct { 47 + char *buf; /* from odb_read_object_info_extended() */ 48 unsigned long read_ptr; 49 } incore; 50 ··· 403 oi.typep = type; 404 oi.sizep = &st->size; 405 oi.contentp = (void **)&st->u.incore.buf; 406 + return odb_read_object_info_extended(r->objects, oid, &oi, 407 + OBJECT_INFO_DIE_IF_CORRUPT); 408 } 409 410 /***************************************************************************** ··· 422 423 oi.typep = type; 424 oi.sizep = &size; 425 + status = odb_read_object_info_extended(r->objects, oid, &oi, 0); 426 if (status < 0) 427 return status; 428
+2 -3
submodule.c
··· 968 return 0; 969 } 970 971 - type = oid_object_info(&subrepo, oid, NULL); 972 973 switch (type) { 974 case OBJ_COMMIT: ··· 1752 static int commit_missing_in_sub(const struct object_id *oid, void *data) 1753 { 1754 struct repository *subrepo = data; 1755 - 1756 - enum object_type type = oid_object_info(subrepo, oid, NULL); 1757 1758 return type != OBJ_COMMIT; 1759 }
··· 968 return 0; 969 } 970 971 + type = odb_read_object_info(subrepo.objects, oid, NULL); 972 973 switch (type) { 974 case OBJ_COMMIT: ··· 1752 static int commit_missing_in_sub(const struct object_id *oid, void *data) 1753 { 1754 struct repository *subrepo = data; 1755 + enum object_type type = odb_read_object_info(subrepo->objects, oid, NULL); 1756 1757 return type != OBJ_COMMIT; 1758 }
+1 -1
t/helper/test-partial-clone.c
··· 23 die("could not init repo"); 24 if (parse_oid_hex_algop(oid_hex, &oid, &p, r.hash_algo)) 25 die("could not parse oid"); 26 - if (oid_object_info_extended(&r, &oid, &oi, 0)) 27 die("could not obtain object info"); 28 printf("%d\n", (int) size); 29
··· 23 die("could not init repo"); 24 if (parse_oid_hex_algop(oid_hex, &oid, &p, r.hash_algo)) 25 die("could not parse oid"); 26 + if (odb_read_object_info_extended(r.objects, &oid, &oi, 0)) 27 die("could not obtain object info"); 28 printf("%d\n", (int) size); 29
+1 -1
tag.c
··· 52 unsigned long size; 53 int ret; 54 55 - type = oid_object_info(the_repository, oid, NULL); 56 if (type != OBJ_TAG) 57 return error("%s: cannot verify a non-tag object of type %s.", 58 name_to_report ?
··· 52 unsigned long size; 53 int ret; 54 55 + type = odb_read_object_info(the_repository->objects, oid, NULL); 56 if (type != OBJ_TAG) 57 return error("%s: cannot verify a non-tag object of type %s.", 58 name_to_report ?