| 62 | } |
| 63 | |
| 64 | static int load_one_loose_object_map(struct repository *repo, struct odb_source_loose *loose) |
| 65 | { |
| 66 | struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT; |
| 67 | FILE *fp; |
| 68 | |
| 69 | if (!loose->map) |
| 70 | loose_object_map_init(&loose->map); |
| 71 | if (!loose->cache) { |
| 72 | ALLOC_ARRAY(loose->cache, 1); |
| 73 | oidtree_init(loose->cache); |
| 74 | } |
| 75 | |
| 76 | insert_loose_map(loose, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree); |
| 77 | insert_loose_map(loose, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob); |
| 78 | insert_loose_map(loose, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid); |
| 79 | |
| 80 | repo_common_path_replace(repo, &path, "objects/loose-object-idx"); |
| 81 | fp = fopen(path.buf, "rb"); |
| 82 | if (!fp) { |
| 83 | strbuf_release(&path); |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | errno = 0; |
| 88 | if (strbuf_getwholeline(&buf, fp, '\n') || strcmp(buf.buf, loose_object_header)) |
| 89 | goto err; |
| 90 | while (!strbuf_getline_lf(&buf, fp)) { |
| 91 | const char *p; |
| 92 | struct object_id oid, compat_oid; |
| 93 | if (parse_oid_hex_algop(buf.buf, &oid, &p, repo->hash_algo) || |
| 94 | *p++ != ' ' || |
| 95 | parse_oid_hex_algop(p, &compat_oid, &p, repo->compat_hash_algo) || |
| 96 | p != buf.buf + buf.len) |
| 97 | goto err; |
| 98 | insert_loose_map(loose, &oid, &compat_oid); |
| 99 | } |
| 100 | |
| 101 | strbuf_release(&buf); |
| 102 | strbuf_release(&path); |
| 103 | return errno ? -1 : 0; |
| 104 | err: |
| 105 | strbuf_release(&buf); |
| 106 | strbuf_release(&path); |
| 107 | return -1; |
| 108 | } |
| 109 | |
| 110 | int repo_read_loose_object_map(struct repository *repo) |
| 111 | { |
no test coverage detected