Skip to content

Commit 90734da

Browse files
committed
Merge branch 'ps/object-source-loose' into seen
A part of code paths that deals with loose objects has been cleaned up. * ps/object-source-loose: object-file: refactor writing objects via a stream object-file: rename `write_object_file()` object-file: refactor freshening of objects object-file: rename `has_loose_object()` object-file: read objects via the loose object source object-file: move loose object map into loose source object-file: hide internals when we need to reprepare loose sources object-file: move loose object cache into loose source object-file: introduce `struct odb_loose_source` object-file: move `fetch_if_missing` odb: adjust naming to free object sources odb: introduce `odb_source_new()` odb: fix subtle logic to check whether an alternate is usable
2 parents 6189123 + 4dbccd3 commit 90734da

File tree

12 files changed

+287
-207
lines changed

12 files changed

+287
-207
lines changed

builtin/pack-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,7 +1715,7 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
17151715
*/
17161716
struct odb_source *source = the_repository->objects->sources->next;
17171717
for (; source; source = source->next)
1718-
if (has_loose_object(source, oid))
1718+
if (odb_loose_source_has_object(source, oid))
17191719
return 0;
17201720
}
17211721

@@ -3976,7 +3976,7 @@ static void add_cruft_object_entry(const struct object_id *oid, enum object_type
39763976
int found = 0;
39773977

39783978
for (; !found && source; source = source->next)
3979-
if (has_loose_object(source, oid))
3979+
if (odb_loose_source_has_object(source, oid))
39803980
found = 1;
39813981

39823982
/*

builtin/unpack-objects.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ struct input_zstream_data {
363363
int status;
364364
};
365365

366-
static const void *feed_input_zstream(struct input_stream *in_stream,
366+
static const void *feed_input_zstream(struct odb_write_stream *in_stream,
367367
unsigned long *readlen)
368368
{
369369
struct input_zstream_data *data = in_stream->data;
@@ -393,7 +393,7 @@ static void stream_blob(unsigned long size, unsigned nr)
393393
{
394394
git_zstream zstream = { 0 };
395395
struct input_zstream_data data = { 0 };
396-
struct input_stream in_stream = {
396+
struct odb_write_stream in_stream = {
397397
.read = feed_input_zstream,
398398
.data = &data,
399399
};
@@ -402,8 +402,7 @@ static void stream_blob(unsigned long size, unsigned nr)
402402
data.zstream = &zstream;
403403
git_inflate_init(&zstream);
404404

405-
if (stream_loose_object(the_repository->objects->sources,
406-
&in_stream, size, &info->oid))
405+
if (odb_write_object_stream(the_repository->objects, &in_stream, size, &info->oid))
407406
die(_("failed to write object in stream"));
408407

409408
if (data.status != Z_STREAM_END)

loose.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "git-compat-util.h"
22
#include "hash.h"
33
#include "path.h"
4+
#include "object-file.h"
45
#include "odb.h"
56
#include "hex.h"
67
#include "repository.h"
@@ -48,13 +49,13 @@ static int insert_loose_map(struct odb_source *source,
4849
const struct object_id *oid,
4950
const struct object_id *compat_oid)
5051
{
51-
struct loose_object_map *map = source->loose_map;
52+
struct loose_object_map *map = source->loose->map;
5253
int inserted = 0;
5354

5455
inserted |= insert_oid_pair(map->to_compat, oid, compat_oid);
5556
inserted |= insert_oid_pair(map->to_storage, compat_oid, oid);
5657
if (inserted)
57-
oidtree_insert(source->loose_objects_cache, compat_oid);
58+
oidtree_insert(source->loose->cache, compat_oid);
5859

5960
return inserted;
6061
}
@@ -64,11 +65,11 @@ static int load_one_loose_object_map(struct repository *repo, struct odb_source
6465
struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
6566
FILE *fp;
6667

67-
if (!source->loose_map)
68-
loose_object_map_init(&source->loose_map);
69-
if (!source->loose_objects_cache) {
70-
ALLOC_ARRAY(source->loose_objects_cache, 1);
71-
oidtree_init(source->loose_objects_cache);
68+
if (!source->loose->map)
69+
loose_object_map_init(&source->loose->map);
70+
if (!source->loose->cache) {
71+
ALLOC_ARRAY(source->loose->cache, 1);
72+
oidtree_init(source->loose->cache);
7273
}
7374

7475
insert_loose_map(source, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree);
@@ -124,7 +125,7 @@ int repo_read_loose_object_map(struct repository *repo)
124125

125126
int repo_write_loose_object_map(struct repository *repo)
126127
{
127-
kh_oid_map_t *map = repo->objects->sources->loose_map->to_compat;
128+
kh_oid_map_t *map = repo->objects->sources->loose->map->to_compat;
128129
struct lock_file lock;
129130
int fd;
130131
khiter_t iter;
@@ -230,7 +231,7 @@ int repo_loose_object_map_oid(struct repository *repo,
230231
khiter_t pos;
231232

232233
for (source = repo->objects->sources; source; source = source->next) {
233-
struct loose_object_map *loose_map = source->loose_map;
234+
struct loose_object_map *loose_map = source->loose->map;
234235
if (!loose_map)
235236
continue;
236237
map = (to == repo->compat_hash_algo) ?

0 commit comments

Comments
 (0)