Skip to content

Commit ecc84b2

Browse files
committed
Merge branch 'ps/object-read-stream' into seen
The "git_istream" abstraction has been revamped to make it easier to interface with pluggable object database design. Comments? * ps/object-read-stream: streaming: drop redundant type and size pointers streaming: move into object database subsystem streaming: refactor interface to be object-database-centric streaming: move logic to read packed objects streams into backend streaming: move logic to read loose objects streams into backend streaming: make the `odb_read_stream` definition public streaming: get rid of `the_repository` streaming: rely on object sources to create object stream packfile: introduce function to read object info from a store streaming: move zlib stream into backends streaming: create structure for filtered object streams streaming: create structure for packed object streams streaming: create structure for loose object streams streaming: create structure for in-core object streams streaming: allocate stream inside the backend-specific logic streaming: explicitly pass packfile info when streaming a packed object streaming: propagate final object type via the stream streaming: drop the `open()` callback function streaming: rename `git_istream` into `odb_read_stream`
2 parents fc7d1b4 + 06523c6 commit ecc84b2

20 files changed

+780
-729
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,7 @@ LIB_OBJS += object-file.o
12011201
LIB_OBJS += object-name.o
12021202
LIB_OBJS += object.o
12031203
LIB_OBJS += odb.o
1204+
LIB_OBJS += odb/streaming.o
12041205
LIB_OBJS += oid-array.o
12051206
LIB_OBJS += oidmap.o
12061207
LIB_OBJS += oidset.o
@@ -1295,7 +1296,6 @@ LIB_OBJS += split-index.o
12951296
LIB_OBJS += stable-qsort.o
12961297
LIB_OBJS += statinfo.o
12971298
LIB_OBJS += strbuf.o
1298-
LIB_OBJS += streaming.o
12991299
LIB_OBJS += string-list.o
13001300
LIB_OBJS += strmap.o
13011301
LIB_OBJS += strvec.o

archive-tar.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include "tar.h"
1313
#include "archive.h"
1414
#include "odb.h"
15+
#include "odb/streaming.h"
1516
#include "strbuf.h"
16-
#include "streaming.h"
1717
#include "run-command.h"
1818
#include "write-or-die.h"
1919

@@ -129,22 +129,20 @@ static void write_trailer(void)
129129
*/
130130
static int stream_blocked(struct repository *r, const struct object_id *oid)
131131
{
132-
struct git_istream *st;
133-
enum object_type type;
134-
unsigned long sz;
132+
struct odb_read_stream *st;
135133
char buf[BLOCKSIZE];
136134
ssize_t readlen;
137135

138-
st = open_istream(r, oid, &type, &sz, NULL);
136+
st = odb_read_object_stream(r->objects, oid, NULL);
139137
if (!st)
140138
return error(_("cannot stream blob %s"), oid_to_hex(oid));
141139
for (;;) {
142-
readlen = read_istream(st, buf, sizeof(buf));
140+
readlen = odb_read_stream_read(st, buf, sizeof(buf));
143141
if (readlen <= 0)
144142
break;
145143
do_write_blocked(buf, readlen);
146144
}
147-
close_istream(st);
145+
odb_read_stream_close(st);
148146
if (!readlen)
149147
finish_record();
150148
return readlen;

archive-zip.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#include "gettext.h"
1111
#include "git-zlib.h"
1212
#include "hex.h"
13-
#include "streaming.h"
1413
#include "utf8.h"
1514
#include "odb.h"
15+
#include "odb/streaming.h"
1616
#include "strbuf.h"
1717
#include "userdiff.h"
1818
#include "write-or-die.h"
@@ -309,7 +309,7 @@ static int write_zip_entry(struct archiver_args *args,
309309
enum zip_method method;
310310
unsigned char *out;
311311
void *deflated = NULL;
312-
struct git_istream *stream = NULL;
312+
struct odb_read_stream *stream = NULL;
313313
unsigned long flags = 0;
314314
int is_binary = -1;
315315
const char *path_without_prefix = path + args->baselen;
@@ -347,12 +347,11 @@ static int write_zip_entry(struct archiver_args *args,
347347
method = ZIP_METHOD_DEFLATE;
348348

349349
if (!buffer) {
350-
enum object_type type;
351-
stream = open_istream(args->repo, oid, &type, &size,
352-
NULL);
350+
stream = odb_read_object_stream(args->repo->objects, oid, NULL);
353351
if (!stream)
354352
return error(_("cannot stream blob %s"),
355353
oid_to_hex(oid));
354+
size = stream->size;
356355
flags |= ZIP_STREAM;
357356
out = NULL;
358357
} else {
@@ -429,7 +428,7 @@ static int write_zip_entry(struct archiver_args *args,
429428
ssize_t readlen;
430429

431430
for (;;) {
432-
readlen = read_istream(stream, buf, sizeof(buf));
431+
readlen = odb_read_stream_read(stream, buf, sizeof(buf));
433432
if (readlen <= 0)
434433
break;
435434
crc = crc32(crc, buf, readlen);
@@ -439,7 +438,7 @@ static int write_zip_entry(struct archiver_args *args,
439438
buf, readlen);
440439
write_or_die(1, buf, readlen);
441440
}
442-
close_istream(stream);
441+
odb_read_stream_close(stream);
443442
if (readlen)
444443
return readlen;
445444

@@ -462,7 +461,7 @@ static int write_zip_entry(struct archiver_args *args,
462461
zstream.avail_out = sizeof(compressed);
463462

464463
for (;;) {
465-
readlen = read_istream(stream, buf, sizeof(buf));
464+
readlen = odb_read_stream_read(stream, buf, sizeof(buf));
466465
if (readlen <= 0)
467466
break;
468467
crc = crc32(crc, buf, readlen);
@@ -486,7 +485,7 @@ static int write_zip_entry(struct archiver_args *args,
486485
}
487486

488487
}
489-
close_istream(stream);
488+
odb_read_stream_close(stream);
490489
if (readlen)
491490
return readlen;
492491

builtin/cat-file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
#include "list-objects-filter-options.h"
1919
#include "parse-options.h"
2020
#include "userdiff.h"
21-
#include "streaming.h"
2221
#include "oid-array.h"
2322
#include "packfile.h"
2423
#include "pack-bitmap.h"
2524
#include "object-file.h"
2625
#include "object-name.h"
2726
#include "odb.h"
27+
#include "odb/streaming.h"
2828
#include "replace-object.h"
2929
#include "promisor-remote.h"
3030
#include "mailmap.h"
@@ -95,7 +95,7 @@ static int filter_object(const char *path, unsigned mode,
9595

9696
static int stream_blob(const struct object_id *oid)
9797
{
98-
if (stream_blob_to_fd(1, oid, NULL, 0))
98+
if (odb_stream_blob_to_fd(the_repository->objects, 1, oid, NULL, 0))
9999
die("unable to stream %s to stdout", oid_to_hex(oid));
100100
return 0;
101101
}

builtin/fsck.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
#include "fsck.h"
1414
#include "parse-options.h"
1515
#include "progress.h"
16-
#include "streaming.h"
1716
#include "packfile.h"
1817
#include "object-file.h"
1918
#include "object-name.h"
2019
#include "odb.h"
20+
#include "odb/streaming.h"
2121
#include "path.h"
2222
#include "read-cache-ll.h"
2323
#include "replace-object.h"
@@ -340,7 +340,8 @@ static void check_unreachable_object(struct object *obj)
340340
}
341341
f = xfopen(filename, "w");
342342
if (obj->type == OBJ_BLOB) {
343-
if (stream_blob_to_fd(fileno(f), &obj->oid, NULL, 1))
343+
if (odb_stream_blob_to_fd(the_repository->objects, fileno(f),
344+
&obj->oid, NULL, 1))
344345
die_errno(_("could not write '%s'"), filename);
345346
} else
346347
fprintf(f, "%s\n", describe_object(&obj->oid));

builtin/index-pack.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
#include "progress.h"
1717
#include "fsck.h"
1818
#include "strbuf.h"
19-
#include "streaming.h"
2019
#include "thread-utils.h"
2120
#include "packfile.h"
2221
#include "pack-revindex.h"
2322
#include "object-file.h"
2423
#include "odb.h"
24+
#include "odb/streaming.h"
2525
#include "oid-array.h"
2626
#include "oidset.h"
2727
#include "path.h"
@@ -762,7 +762,7 @@ static void find_ref_delta_children(const struct object_id *oid,
762762

763763
struct compare_data {
764764
struct object_entry *entry;
765-
struct git_istream *st;
765+
struct odb_read_stream *st;
766766
unsigned char *buf;
767767
unsigned long buf_size;
768768
};
@@ -779,7 +779,7 @@ static int compare_objects(const unsigned char *buf, unsigned long size,
779779
}
780780

781781
while (size) {
782-
ssize_t len = read_istream(data->st, data->buf, size);
782+
ssize_t len = odb_read_stream_read(data->st, data->buf, size);
783783
if (len == 0)
784784
die(_("SHA1 COLLISION FOUND WITH %s !"),
785785
oid_to_hex(&data->entry->idx.oid));
@@ -798,24 +798,21 @@ static int compare_objects(const unsigned char *buf, unsigned long size,
798798
static int check_collison(struct object_entry *entry)
799799
{
800800
struct compare_data data;
801-
enum object_type type;
802-
unsigned long size;
803801

804802
if (entry->size <= repo_settings_get_big_file_threshold(the_repository) ||
805803
entry->type != OBJ_BLOB)
806804
return -1;
807805

808806
memset(&data, 0, sizeof(data));
809807
data.entry = entry;
810-
data.st = open_istream(the_repository, &entry->idx.oid, &type, &size,
811-
NULL);
808+
data.st = odb_read_object_stream(the_repository->objects, &entry->idx.oid, NULL);
812809
if (!data.st)
813810
return -1;
814-
if (size != entry->size || type != entry->type)
811+
if (data.st->size != entry->size || data.st->type != entry->type)
815812
die(_("SHA1 COLLISION FOUND WITH %s !"),
816813
oid_to_hex(&entry->idx.oid));
817814
unpack_data(entry, compare_objects, &data);
818-
close_istream(data.st);
815+
odb_read_stream_close(data.st);
819816
free(data.buf);
820817
return 0;
821818
}

builtin/log.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "refs.h"
1717
#include "object-name.h"
1818
#include "odb.h"
19+
#include "odb/streaming.h"
1920
#include "pager.h"
2021
#include "color.h"
2122
#include "commit.h"
@@ -35,7 +36,6 @@
3536
#include "parse-options.h"
3637
#include "line-log.h"
3738
#include "branch.h"
38-
#include "streaming.h"
3939
#include "version.h"
4040
#include "mailmap.h"
4141
#include "progress.h"
@@ -584,7 +584,7 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c
584584
fflush(rev->diffopt.file);
585585
if (!rev->diffopt.flags.textconv_set_via_cmdline ||
586586
!rev->diffopt.flags.allow_textconv)
587-
return stream_blob_to_fd(1, oid, NULL, 0);
587+
return odb_stream_blob_to_fd(the_repository->objects, 1, oid, NULL, 0);
588588

589589
if (get_oid_with_context(the_repository, obj_name,
590590
GET_OID_RECORD_PATH,
@@ -594,7 +594,7 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c
594594
!textconv_object(the_repository, obj_context.path,
595595
obj_context.mode, &oidc, 1, &buf, &size)) {
596596
object_context_release(&obj_context);
597-
return stream_blob_to_fd(1, oid, NULL, 0);
597+
return odb_stream_blob_to_fd(the_repository->objects, 1, oid, NULL, 0);
598598
}
599599

600600
if (!buf)

builtin/pack-objects.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "pack-objects.h"
2323
#include "progress.h"
2424
#include "refs.h"
25-
#include "streaming.h"
2625
#include "thread-utils.h"
2726
#include "pack-bitmap.h"
2827
#include "delta-islands.h"
@@ -33,6 +32,7 @@
3332
#include "packfile.h"
3433
#include "object-file.h"
3534
#include "odb.h"
35+
#include "odb/streaming.h"
3636
#include "replace-object.h"
3737
#include "dir.h"
3838
#include "midx.h"
@@ -404,7 +404,7 @@ static unsigned long do_compress(void **pptr, unsigned long size)
404404
return stream.total_out;
405405
}
406406

407-
static unsigned long write_large_blob_data(struct git_istream *st, struct hashfile *f,
407+
static unsigned long write_large_blob_data(struct odb_read_stream *st, struct hashfile *f,
408408
const struct object_id *oid)
409409
{
410410
git_zstream stream;
@@ -417,7 +417,7 @@ static unsigned long write_large_blob_data(struct git_istream *st, struct hashfi
417417
for (;;) {
418418
ssize_t readlen;
419419
int zret = Z_OK;
420-
readlen = read_istream(st, ibuf, sizeof(ibuf));
420+
readlen = odb_read_stream_read(st, ibuf, sizeof(ibuf));
421421
if (readlen == -1)
422422
die(_("unable to read %s"), oid_to_hex(oid));
423423

@@ -513,17 +513,19 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
513513
unsigned hdrlen;
514514
enum object_type type;
515515
void *buf;
516-
struct git_istream *st = NULL;
516+
struct odb_read_stream *st = NULL;
517517
const unsigned hashsz = the_hash_algo->rawsz;
518518

519519
if (!usable_delta) {
520520
if (oe_type(entry) == OBJ_BLOB &&
521521
oe_size_greater_than(&to_pack, entry,
522522
repo_settings_get_big_file_threshold(the_repository)) &&
523-
(st = open_istream(the_repository, &entry->idx.oid, &type,
524-
&size, NULL)) != NULL)
523+
(st = odb_read_object_stream(the_repository->objects, &entry->idx.oid,
524+
NULL)) != NULL) {
525525
buf = NULL;
526-
else {
526+
type = st->type;
527+
size = st->size;
528+
} else {
527529
buf = odb_read_object(the_repository->objects,
528530
&entry->idx.oid, &type,
529531
&size);
@@ -577,7 +579,7 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
577579
dheader[--pos] = 128 | (--ofs & 127);
578580
if (limit && hdrlen + sizeof(dheader) - pos + datalen + hashsz >= limit) {
579581
if (st)
580-
close_istream(st);
582+
odb_read_stream_close(st);
581583
free(buf);
582584
return 0;
583585
}
@@ -591,7 +593,7 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
591593
*/
592594
if (limit && hdrlen + hashsz + datalen + hashsz >= limit) {
593595
if (st)
594-
close_istream(st);
596+
odb_read_stream_close(st);
595597
free(buf);
596598
return 0;
597599
}
@@ -601,15 +603,15 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
601603
} else {
602604
if (limit && hdrlen + datalen + hashsz >= limit) {
603605
if (st)
604-
close_istream(st);
606+
odb_read_stream_close(st);
605607
free(buf);
606608
return 0;
607609
}
608610
hashwrite(f, header, hdrlen);
609611
}
610612
if (st) {
611613
datalen = write_large_blob_data(st, f, &entry->idx.oid);
612-
close_istream(st);
614+
odb_read_stream_close(st);
613615
} else {
614616
hashwrite(f, buf, datalen);
615617
free(buf);

entry.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
#include "git-compat-util.h"
44
#include "odb.h"
5+
#include "odb/streaming.h"
56
#include "dir.h"
67
#include "environment.h"
78
#include "gettext.h"
89
#include "hex.h"
910
#include "name-hash.h"
1011
#include "sparse-index.h"
11-
#include "streaming.h"
1212
#include "submodule.h"
1313
#include "symlinks.h"
1414
#include "progress.h"
@@ -139,7 +139,7 @@ static int streaming_write_entry(const struct cache_entry *ce, char *path,
139139
if (fd < 0)
140140
return -1;
141141

142-
result |= stream_blob_to_fd(fd, &ce->oid, filter, 1);
142+
result |= odb_stream_blob_to_fd(the_repository->objects, fd, &ce->oid, filter, 1);
143143
*fstat_done = fstat_checkout_output(fd, state, statbuf);
144144
result |= close(fd);
145145

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ libgit_sources = [
397397
'object-name.c',
398398
'object.c',
399399
'odb.c',
400+
'odb/streaming.c',
400401
'oid-array.c',
401402
'oidmap.c',
402403
'oidset.c',
@@ -491,7 +492,6 @@ libgit_sources = [
491492
'stable-qsort.c',
492493
'statinfo.c',
493494
'strbuf.c',
494-
'streaming.c',
495495
'string-list.c',
496496
'strmap.c',
497497
'strvec.c',

0 commit comments

Comments
 (0)