Skip to content

Commit 030ebee

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: 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 6cfb99a + 783ee36 commit 030ebee

20 files changed

+784
-719
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 & 5 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,22 @@ 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;
132+
struct odb_read_stream *st;
133133
enum object_type type;
134134
unsigned long sz;
135135
char buf[BLOCKSIZE];
136136
ssize_t readlen;
137137

138-
st = open_istream(r, oid, &type, &sz, NULL);
138+
st = odb_read_object_stream(r->objects, oid, &type, &sz, NULL);
139139
if (!st)
140140
return error(_("cannot stream blob %s"), oid_to_hex(oid));
141141
for (;;) {
142-
readlen = read_istream(st, buf, sizeof(buf));
142+
readlen = odb_read_stream_read(st, buf, sizeof(buf));
143143
if (readlen <= 0)
144144
break;
145145
do_write_blocked(buf, readlen);
146146
}
147-
close_istream(st);
147+
odb_read_stream_close(st);
148148
if (!readlen)
149149
finish_record();
150150
return readlen;

archive-zip.c

Lines changed: 8 additions & 8 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;
@@ -348,8 +348,8 @@ static int write_zip_entry(struct archiver_args *args,
348348

349349
if (!buffer) {
350350
enum object_type type;
351-
stream = open_istream(args->repo, oid, &type, &size,
352-
NULL);
351+
stream = odb_read_object_stream(args->repo->objects, oid,
352+
&type, &size, NULL);
353353
if (!stream)
354354
return error(_("cannot stream blob %s"),
355355
oid_to_hex(oid));
@@ -429,7 +429,7 @@ static int write_zip_entry(struct archiver_args *args,
429429
ssize_t readlen;
430430

431431
for (;;) {
432-
readlen = read_istream(stream, buf, sizeof(buf));
432+
readlen = odb_read_stream_read(stream, buf, sizeof(buf));
433433
if (readlen <= 0)
434434
break;
435435
crc = crc32(crc, buf, readlen);
@@ -439,7 +439,7 @@ static int write_zip_entry(struct archiver_args *args,
439439
buf, readlen);
440440
write_or_die(1, buf, readlen);
441441
}
442-
close_istream(stream);
442+
odb_read_stream_close(stream);
443443
if (readlen)
444444
return readlen;
445445

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

464464
for (;;) {
465-
readlen = read_istream(stream, buf, sizeof(buf));
465+
readlen = odb_read_stream_read(stream, buf, sizeof(buf));
466466
if (readlen <= 0)
467467
break;
468468
crc = crc32(crc, buf, readlen);
@@ -486,7 +486,7 @@ static int write_zip_entry(struct archiver_args *args,
486486
}
487487

488488
}
489-
close_istream(stream);
489+
odb_read_stream_close(stream);
490490
if (readlen)
491491
return readlen;
492492

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 & 6 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));
@@ -807,15 +807,15 @@ static int check_collison(struct object_entry *entry)
807807

808808
memset(&data, 0, sizeof(data));
809809
data.entry = entry;
810-
data.st = open_istream(the_repository, &entry->idx.oid, &type, &size,
811-
NULL);
810+
data.st = odb_read_object_stream(the_repository->objects, &entry->idx.oid,
811+
&type, &size, NULL);
812812
if (!data.st)
813813
return -1;
814814
if (size != entry->size || type != entry->type)
815815
die(_("SHA1 COLLISION FOUND WITH %s !"),
816816
oid_to_hex(&entry->idx.oid));
817817
unpack_data(entry, compare_objects, &data);
818-
close_istream(data.st);
818+
odb_read_stream_close(data.st);
819819
free(data.buf);
820820
return 0;
821821
}

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: 10 additions & 10 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,15 +513,15 @@ 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+
&type, &size, NULL)) != NULL)
525525
buf = NULL;
526526
else {
527527
buf = odb_read_object(the_repository->objects,
@@ -577,7 +577,7 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
577577
dheader[--pos] = 128 | (--ofs & 127);
578578
if (limit && hdrlen + sizeof(dheader) - pos + datalen + hashsz >= limit) {
579579
if (st)
580-
close_istream(st);
580+
odb_read_stream_close(st);
581581
free(buf);
582582
return 0;
583583
}
@@ -591,7 +591,7 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
591591
*/
592592
if (limit && hdrlen + hashsz + datalen + hashsz >= limit) {
593593
if (st)
594-
close_istream(st);
594+
odb_read_stream_close(st);
595595
free(buf);
596596
return 0;
597597
}
@@ -601,15 +601,15 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
601601
} else {
602602
if (limit && hdrlen + datalen + hashsz >= limit) {
603603
if (st)
604-
close_istream(st);
604+
odb_read_stream_close(st);
605605
free(buf);
606606
return 0;
607607
}
608608
hashwrite(f, header, hdrlen);
609609
}
610610
if (st) {
611611
datalen = write_large_blob_data(st, f, &entry->idx.oid);
612-
close_istream(st);
612+
odb_read_stream_close(st);
613613
} else {
614614
hashwrite(f, buf, datalen);
615615
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)