Skip to content

Commit 06f63df

Browse files
committed
Merge branch 'ps/odb-source-loose'
The loose object source has been refactored into a proper `struct odb_source`. * ps/odb-source-loose: odb/source-loose: drop pointer to the "files" source odb/source-loose: stub out remaining callbacks odb/source-loose: wire up `write_object_stream()` callback object-file: refactor writing objects to use loose source odb/source-loose: wire up `write_object()` callback loose: refactor object map to operate on `struct odb_source_loose` odb/source-loose: wire up `freshen_object()` callback odb/source-loose: drop `odb_source_loose_has_object()` odb/source-loose: wire up `count_objects()` callback odb/source-loose: wire up `find_abbrev_len()` callback odb/source-loose: wire up `for_each_object()` callback odb/source-loose: wire up `read_object_stream()` callback odb/source-loose: wire up `read_object_info()` callback odb/source-loose: wire up `close()` callback odb/source-loose: wire up `reprepare()` callback odb/source-loose: start converting to a proper `struct odb_source` odb/source-loose: store pointer to "files" instead of generic source odb/source-loose: move loose source into "odb/" subsystem
2 parents 53ff393 + ef4778b commit 06f63df

15 files changed

Lines changed: 973 additions & 870 deletions

‎Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,7 @@ LIB_OBJS += odb.o
12171217
LIB_OBJS += odb/source.o
12181218
LIB_OBJS += odb/source-files.o
12191219
LIB_OBJS += odb/source-inmemory.o
1220+
LIB_OBJS += odb/source-loose.o
12201221
LIB_OBJS += odb/streaming.o
12211222
LIB_OBJS += odb/transaction.o
12221223
LIB_OBJS += oid-array.o

‎builtin/cat-file.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -890,8 +890,9 @@ static void batch_each_object(struct batch_options *opt,
890890
*/
891891
odb_prepare_alternates(the_repository->objects);
892892
for (source = the_repository->objects->sources; source; source = source->next) {
893-
int ret = odb_source_loose_for_each_object(source, NULL, batch_one_object_oi,
894-
&payload, &opts);
893+
struct odb_source_files *files = odb_source_files_downcast(source);
894+
int ret = odb_source_for_each_object(&files->loose->base, NULL, batch_one_object_oi,
895+
&payload, &opts);
895896
if (ret)
896897
break;
897898
}

‎builtin/gc.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ static int rerere_gc_condition(struct gc_config *cfg UNUSED)
466466

467467
static int too_many_loose_objects(int limit)
468468
{
469+
struct odb_source_files *files = odb_source_files_downcast(the_repository->objects->sources);
469470
/*
470471
* This is weird, but stems from legacy behaviour: the GC auto
471472
* threshold was always essentially interpreted as if it was rounded up
@@ -474,9 +475,8 @@ static int too_many_loose_objects(int limit)
474475
int auto_threshold = DIV_ROUND_UP(limit, 256) * 256;
475476
unsigned long loose_count;
476477

477-
if (odb_source_loose_count_objects(the_repository->objects->sources,
478-
ODB_COUNT_OBJECTS_APPROXIMATE,
479-
&loose_count) < 0)
478+
if (odb_source_count_objects(&files->loose->base, ODB_COUNT_OBJECTS_APPROXIMATE,
479+
&loose_count) < 0)
480480
return 0;
481481

482482
return loose_count > auto_threshold;

‎builtin/pack-objects.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,9 +1750,11 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
17501750
* skip the local object source.
17511751
*/
17521752
struct odb_source *source = the_repository->objects->sources->next;
1753-
for (; source; source = source->next)
1754-
if (odb_source_loose_has_object(source, oid))
1753+
for (; source; source = source->next) {
1754+
struct odb_source_files *files = odb_source_files_downcast(source);
1755+
if (!odb_source_read_object_info(&files->loose->base, oid, NULL, 0))
17551756
return 0;
1757+
}
17561758
}
17571759

17581760
/*
@@ -4135,9 +4137,11 @@ static void add_cruft_object_entry(const struct object_id *oid, enum object_type
41354137
struct odb_source *source = the_repository->objects->sources;
41364138
int found = 0;
41374139

4138-
for (; !found && source; source = source->next)
4139-
if (odb_source_loose_has_object(source, oid))
4140+
for (; !found && source; source = source->next) {
4141+
struct odb_source_files *files = odb_source_files_downcast(source);
4142+
if (!odb_source_read_object_info(&files->loose->base, oid, NULL, 0))
41404143
found = 1;
4144+
}
41414145

41424146
/*
41434147
* If a traversed tree has a missing blob then we want

‎http-walker.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,9 @@ static int fetch_object(struct walker *walker, const struct object_id *oid)
539539
} else if (!oideq(&obj_req->oid, &req->real_oid)) {
540540
ret = error("File %s has bad hash", hex);
541541
} else if (req->rename < 0) {
542+
struct odb_source_files *files = odb_source_files_downcast(the_repository->objects->sources);
542543
struct strbuf buf = STRBUF_INIT;
543-
odb_loose_path(the_repository->objects->sources, &buf, &req->oid);
544+
odb_loose_path(files->loose, &buf, &req->oid);
544545
ret = error("unable to write sha1 filename %s", buf.buf);
545546
strbuf_release(&buf);
546547
}

‎http.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2826,6 +2826,7 @@ static size_t fwrite_sha1_file(char *ptr, size_t eltsize, size_t nmemb,
28262826
struct http_object_request *new_http_object_request(const char *base_url,
28272827
const struct object_id *oid)
28282828
{
2829+
struct odb_source_files *files = odb_source_files_downcast(the_repository->objects->sources);
28292830
char *hex = oid_to_hex(oid);
28302831
struct strbuf filename = STRBUF_INIT;
28312832
struct strbuf prevfile = STRBUF_INIT;
@@ -2840,7 +2841,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
28402841
oidcpy(&freq->oid, oid);
28412842
freq->localfile = -1;
28422843

2843-
odb_loose_path(the_repository->objects->sources, &filename, oid);
2844+
odb_loose_path(files->loose, &filename, oid);
28442845
strbuf_addf(&freq->tmpfile, "%s.temp", filename.buf);
28452846

28462847
strbuf_addf(&prevfile, "%s.prev", filename.buf);
@@ -2966,6 +2967,7 @@ void process_http_object_request(struct http_object_request *freq)
29662967

29672968
int finish_http_object_request(struct http_object_request *freq)
29682969
{
2970+
struct odb_source_files *files = odb_source_files_downcast(the_repository->objects->sources);
29692971
struct stat st;
29702972
struct strbuf filename = STRBUF_INIT;
29712973

@@ -2992,7 +2994,7 @@ int finish_http_object_request(struct http_object_request *freq)
29922994
unlink_or_warn(freq->tmpfile.buf);
29932995
return -1;
29942996
}
2995-
odb_loose_path(the_repository->objects->sources, &filename, &freq->oid);
2997+
odb_loose_path(files->loose, &filename, &freq->oid);
29962998
freq->rename = finalize_object_file(the_repository, freq->tmpfile.buf, filename.buf);
29972999
strbuf_release(&filename);
29983000

‎loose.c‎

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,38 +46,36 @@ static int insert_oid_pair(kh_oid_map_t *map, const struct object_id *key, const
4646
return 1;
4747
}
4848

49-
static int insert_loose_map(struct odb_source *source,
49+
static int insert_loose_map(struct odb_source_loose *loose,
5050
const struct object_id *oid,
5151
const struct object_id *compat_oid)
5252
{
53-
struct odb_source_files *files = odb_source_files_downcast(source);
54-
struct loose_object_map *map = files->loose->map;
53+
struct loose_object_map *map = loose->map;
5554
int inserted = 0;
5655

5756
inserted |= insert_oid_pair(map->to_compat, oid, compat_oid);
5857
inserted |= insert_oid_pair(map->to_storage, compat_oid, oid);
5958
if (inserted)
60-
oidtree_insert(files->loose->cache, compat_oid, NULL);
59+
oidtree_insert(loose->cache, compat_oid, NULL);
6160

6261
return inserted;
6362
}
6463

65-
static int load_one_loose_object_map(struct repository *repo, struct odb_source *source)
64+
static int load_one_loose_object_map(struct repository *repo, struct odb_source_loose *loose)
6665
{
67-
struct odb_source_files *files = odb_source_files_downcast(source);
6866
struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
6967
FILE *fp;
7068

71-
if (!files->loose->map)
72-
loose_object_map_init(&files->loose->map);
73-
if (!files->loose->cache) {
74-
ALLOC_ARRAY(files->loose->cache, 1);
75-
oidtree_init(files->loose->cache);
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);
7674
}
7775

78-
insert_loose_map(source, repo->hash_algo->empty_tree, repo->compat_hash_algo->empty_tree);
79-
insert_loose_map(source, repo->hash_algo->empty_blob, repo->compat_hash_algo->empty_blob);
80-
insert_loose_map(source, repo->hash_algo->null_oid, repo->compat_hash_algo->null_oid);
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);
8179

8280
repo_common_path_replace(repo, &path, "objects/loose-object-idx");
8381
fp = fopen(path.buf, "rb");
@@ -97,7 +95,7 @@ static int load_one_loose_object_map(struct repository *repo, struct odb_source
9795
parse_oid_hex_algop(p, &compat_oid, &p, repo->compat_hash_algo) ||
9896
p != buf.buf + buf.len)
9997
goto err;
100-
insert_loose_map(source, &oid, &compat_oid);
98+
insert_loose_map(loose, &oid, &compat_oid);
10199
}
102100

103101
strbuf_release(&buf);
@@ -119,7 +117,8 @@ int repo_read_loose_object_map(struct repository *repo)
119117
odb_prepare_alternates(repo->objects);
120118

121119
for (source = repo->objects->sources; source; source = source->next) {
122-
if (load_one_loose_object_map(repo, source) < 0) {
120+
struct odb_source_files *files = odb_source_files_downcast(source);
121+
if (load_one_loose_object_map(repo, files->loose) < 0) {
123122
return -1;
124123
}
125124
}
@@ -171,7 +170,7 @@ int repo_write_loose_object_map(struct repository *repo)
171170
return -1;
172171
}
173172

174-
static int write_one_object(struct odb_source *source,
173+
static int write_one_object(struct odb_source_loose *loose,
175174
const struct object_id *oid,
176175
const struct object_id *compat_oid)
177176
{
@@ -180,7 +179,7 @@ static int write_one_object(struct odb_source *source,
180179
struct stat st;
181180
struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
182181

183-
strbuf_addf(&path, "%s/loose-object-idx", source->path);
182+
strbuf_addf(&path, "%s/loose-object-idx", loose->base.path);
184183
hold_lock_file_for_update_timeout(&lock, path.buf, LOCK_DIE_ON_ERROR, -1);
185184

186185
fd = open(path.buf, O_WRONLY | O_CREAT | O_APPEND, 0666);
@@ -196,7 +195,7 @@ static int write_one_object(struct odb_source *source,
196195
goto errout;
197196
if (close(fd))
198197
goto errout;
199-
adjust_shared_perm(source->odb->repo, path.buf);
198+
adjust_shared_perm(loose->base.odb->repo, path.buf);
200199
rollback_lock_file(&lock);
201200
strbuf_release(&buf);
202201
strbuf_release(&path);
@@ -210,18 +209,18 @@ static int write_one_object(struct odb_source *source,
210209
return -1;
211210
}
212211

213-
int repo_add_loose_object_map(struct odb_source *source,
212+
int repo_add_loose_object_map(struct odb_source_loose *loose,
214213
const struct object_id *oid,
215214
const struct object_id *compat_oid)
216215
{
217216
int inserted = 0;
218217

219-
if (!should_use_loose_object_map(source->odb->repo))
218+
if (!should_use_loose_object_map(loose->base.odb->repo))
220219
return 0;
221220

222-
inserted = insert_loose_map(source, oid, compat_oid);
221+
inserted = insert_loose_map(loose, oid, compat_oid);
223222
if (inserted)
224-
return write_one_object(source, oid, compat_oid);
223+
return write_one_object(loose, oid, compat_oid);
225224
return 0;
226225
}
227226

‎loose.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "khash.h"
55

66
struct repository;
7-
struct odb_source;
7+
struct odb_source_loose;
88

99
struct loose_object_map {
1010
kh_oid_map_t *to_compat;
@@ -17,7 +17,7 @@ int repo_loose_object_map_oid(struct repository *repo,
1717
const struct object_id *src,
1818
const struct git_hash_algo *dest_algo,
1919
struct object_id *dest);
20-
int repo_add_loose_object_map(struct odb_source *source,
20+
int repo_add_loose_object_map(struct odb_source_loose *loose,
2121
const struct object_id *oid,
2222
const struct object_id *compat_oid);
2323
int repo_read_loose_object_map(struct repository *repo);

‎meson.build‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ libgit_sources = [
405405
'odb/source.c',
406406
'odb/source-files.c',
407407
'odb/source-inmemory.c',
408+
'odb/source-loose.c',
408409
'odb/streaming.c',
409410
'odb/transaction.c',
410411
'oid-array.c',

0 commit comments

Comments
 (0)