Skip to content

Commit a2d923f

Browse files
ebiedermgitster
authored andcommitted
loose: compatibilty short name support
Update loose_objects_cache when udpating the loose objects map. This oidtree is used to discover which oids are possibilities when resolving short names, and it can support a mixture of sha1 and sha256 oids. With this any oid recorded objects/loose-objects-idx is usable for resolving an oid to an object. To make this maintainable a helper insert_loose_map is factored out of load_one_loose_object_map and repo_add_loose_object_map, and then modified to also update the loose_objects_cache. Signed-off-by: "Eric W. Biederman" <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 23b2c7e commit a2d923f

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

loose.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "gettext.h"
88
#include "loose.h"
99
#include "lockfile.h"
10+
#include "oidtree.h"
1011

1112
static const char *loose_object_header = "# loose-object-idx\n";
1213

@@ -42,22 +43,36 @@ static int insert_oid_pair(kh_oid_map_t *map, const struct object_id *key, const
4243
return 1;
4344
}
4445

46+
static int insert_loose_map(struct object_directory *odb,
47+
const struct object_id *oid,
48+
const struct object_id *compat_oid)
49+
{
50+
struct loose_object_map *map = odb->loose_map;
51+
int inserted = 0;
52+
53+
inserted |= insert_oid_pair(map->to_compat, oid, compat_oid);
54+
inserted |= insert_oid_pair(map->to_storage, compat_oid, oid);
55+
if (inserted)
56+
oidtree_insert(odb->loose_objects_cache, compat_oid);
57+
58+
return inserted;
59+
}
60+
4561
static int load_one_loose_object_map(struct repository *repo, struct object_directory *dir)
4662
{
4763
struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
4864
FILE *fp;
4965

5066
if (!dir->loose_map)
5167
loose_object_map_init(&dir->loose_map);
68+
if (!dir->loose_objects_cache) {
69+
ALLOC_ARRAY(dir->loose_objects_cache, 1);
70+
oidtree_init(dir->loose_objects_cache);
71+
}
5272

53-
insert_oid_pair(dir->loose_map->to_compat, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree);
54-
insert_oid_pair(dir->loose_map->to_storage, repo->compat_hash_algo->empty_tree, repo->hash_algo->empty_tree);
55-
56-
insert_oid_pair(dir->loose_map->to_compat, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob);
57-
insert_oid_pair(dir->loose_map->to_storage, repo->compat_hash_algo->empty_blob, repo->hash_algo->empty_blob);
58-
59-
insert_oid_pair(dir->loose_map->to_compat, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid);
60-
insert_oid_pair(dir->loose_map->to_storage, repo->compat_hash_algo->null_oid, repo->hash_algo->null_oid);
73+
insert_loose_map(dir, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree);
74+
insert_loose_map(dir, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob);
75+
insert_loose_map(dir, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid);
6176

6277
strbuf_git_common_path(&path, repo, "objects/loose-object-idx");
6378
fp = fopen(path.buf, "rb");
@@ -77,8 +92,7 @@ static int load_one_loose_object_map(struct repository *repo, struct object_dire
7792
parse_oid_hex_algop(p, &compat_oid, &p, repo->compat_hash_algo) ||
7893
p != buf.buf + buf.len)
7994
goto err;
80-
insert_oid_pair(dir->loose_map->to_compat, &oid, &compat_oid);
81-
insert_oid_pair(dir->loose_map->to_storage, &compat_oid, &oid);
95+
insert_loose_map(dir, &oid, &compat_oid);
8296
}
8397

8498
strbuf_release(&buf);
@@ -197,8 +211,7 @@ int repo_add_loose_object_map(struct repository *repo, const struct object_id *o
197211
if (!should_use_loose_object_map(repo))
198212
return 0;
199213

200-
inserted |= insert_oid_pair(repo->objects->odb->loose_map->to_compat, oid, compat_oid);
201-
inserted |= insert_oid_pair(repo->objects->odb->loose_map->to_storage, compat_oid, oid);
214+
inserted = insert_loose_map(repo->objects->odb, oid, compat_oid);
202215
if (inserted)
203216
return write_one_object(repo, oid, compat_oid);
204217
return 0;

0 commit comments

Comments
 (0)