|
30 | 30 | * to write them into the object store (e.g. a browse-only
|
31 | 31 | * application).
|
32 | 32 | */
|
33 |
| -static struct cached_object_entry { |
| 33 | +struct cached_object_entry { |
34 | 34 | struct object_id oid;
|
35 | 35 | struct cached_object {
|
36 | 36 | enum object_type type;
|
37 | 37 | const void *buf;
|
38 | 38 | unsigned long size;
|
39 | 39 | } value;
|
40 |
| -} *cached_objects; |
41 |
| -static int cached_object_nr, cached_object_alloc; |
| 40 | +}; |
42 | 41 |
|
43 |
| -static const struct cached_object *find_cached_object(const struct object_id *oid) |
| 42 | +static const struct cached_object *find_cached_object(struct raw_object_store *object_store, |
| 43 | + const struct object_id *oid) |
44 | 44 | {
|
45 | 45 | static const struct cached_object empty_tree = {
|
46 | 46 | .type = OBJ_TREE,
|
47 | 47 | .buf = "",
|
48 | 48 | };
|
49 |
| - int i; |
50 |
| - const struct cached_object_entry *co = cached_objects; |
| 49 | + const struct cached_object_entry *co = object_store->cached_objects; |
51 | 50 |
|
52 |
| - for (i = 0; i < cached_object_nr; i++, co++) { |
| 51 | + for (size_t i = 0; i < object_store->cached_object_nr; i++, co++) |
53 | 52 | if (oideq(&co->oid, oid))
|
54 | 53 | return &co->value;
|
55 |
| - } |
56 |
| - if (oideq(oid, the_hash_algo->empty_tree)) |
| 54 | + |
| 55 | + if (oid->algo && oideq(oid, hash_algos[oid->algo].empty_tree)) |
57 | 56 | return &empty_tree;
|
| 57 | + |
58 | 58 | return NULL;
|
59 | 59 | }
|
60 | 60 |
|
@@ -650,7 +650,7 @@ static int do_oid_object_info_extended(struct repository *r,
|
650 | 650 | if (!oi)
|
651 | 651 | oi = &blank_oi;
|
652 | 652 |
|
653 |
| - co = find_cached_object(real); |
| 653 | + co = find_cached_object(r->objects, real); |
654 | 654 | if (co) {
|
655 | 655 | if (oi->typep)
|
656 | 656 | *(oi->typep) = co->type;
|
@@ -853,18 +853,21 @@ int oid_object_info(struct repository *r,
|
853 | 853 | return type;
|
854 | 854 | }
|
855 | 855 |
|
856 |
| -int pretend_object_file(void *buf, unsigned long len, enum object_type type, |
| 856 | +int pretend_object_file(struct repository *repo, |
| 857 | + void *buf, unsigned long len, enum object_type type, |
857 | 858 | struct object_id *oid)
|
858 | 859 | {
|
859 | 860 | struct cached_object_entry *co;
|
860 | 861 | char *co_buf;
|
861 | 862 |
|
862 |
| - hash_object_file(the_hash_algo, buf, len, type, oid); |
863 |
| - if (repo_has_object_file_with_flags(the_repository, oid, OBJECT_INFO_QUICK | OBJECT_INFO_SKIP_FETCH_OBJECT) || |
864 |
| - find_cached_object(oid)) |
| 863 | + hash_object_file(repo->hash_algo, buf, len, type, oid); |
| 864 | + if (repo_has_object_file_with_flags(repo, oid, OBJECT_INFO_QUICK | OBJECT_INFO_SKIP_FETCH_OBJECT) || |
| 865 | + find_cached_object(repo->objects, oid)) |
865 | 866 | return 0;
|
866 |
| - ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc); |
867 |
| - co = &cached_objects[cached_object_nr++]; |
| 867 | + |
| 868 | + ALLOC_GROW(repo->objects->cached_objects, |
| 869 | + repo->objects->cached_object_nr + 1, repo->objects->cached_object_alloc); |
| 870 | + co = &repo->objects->cached_objects[repo->objects->cached_object_nr++]; |
868 | 871 | co->value.size = len;
|
869 | 872 | co->value.type = type;
|
870 | 873 | co_buf = xmalloc(len);
|
@@ -1021,6 +1024,10 @@ void raw_object_store_clear(struct raw_object_store *o)
|
1021 | 1024 | o->odb_tail = NULL;
|
1022 | 1025 | o->loaded_alternates = 0;
|
1023 | 1026 |
|
| 1027 | + for (size_t i = 0; i < o->cached_object_nr; i++) |
| 1028 | + free((char *) o->cached_objects[i].value.buf); |
| 1029 | + FREE_AND_NULL(o->cached_objects); |
| 1030 | + |
1024 | 1031 | INIT_LIST_HEAD(&o->packed_git_mru);
|
1025 | 1032 | close_object_store(o);
|
1026 | 1033 |
|
|
0 commit comments