Skip to content

Commit c8123e7

Browse files
matheustavaresgitster
authored andcommitted
streaming: allow open_istream() to handle any repo
Some callers of open_istream() at archive-tar.c and archive-zip.c are capable of working on arbitrary repositories but the repo struct is not passed down to open_istream(), which uses the_repository internally. For now, that's not a problem since the said callers are only being called with the_repository. But to be consistent and avoid future problems, let's allow open_istream() to receive a struct repository and use that instead of the_repository. This parameter addition will also be used in a future patch to make sha1-file.c:check_object_signature() be able to work on arbitrary repos. Signed-off-by: Matheus Tavares <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5ec9b8a commit c8123e7

7 files changed

+28
-21
lines changed

archive-tar.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ static void write_trailer(void)
112112
* queues up writes, so that all our write(2) calls write exactly one
113113
* full block; pads writes to RECORDSIZE
114114
*/
115-
static int stream_blocked(const struct object_id *oid)
115+
static int stream_blocked(struct repository *r, const struct object_id *oid)
116116
{
117117
struct git_istream *st;
118118
enum object_type type;
119119
unsigned long sz;
120120
char buf[BLOCKSIZE];
121121
ssize_t readlen;
122122

123-
st = open_istream(oid, &type, &sz, NULL);
123+
st = open_istream(r, oid, &type, &sz, NULL);
124124
if (!st)
125125
return error(_("cannot stream blob %s"), oid_to_hex(oid));
126126
for (;;) {
@@ -324,7 +324,7 @@ static int write_tar_entry(struct archiver_args *args,
324324
if (buffer)
325325
write_blocked(buffer, size);
326326
else
327-
err = stream_blocked(oid);
327+
err = stream_blocked(args->repo, oid);
328328
}
329329
free(buffer);
330330
return err;

archive-zip.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ static int write_zip_entry(struct archiver_args *args,
345345

346346
if (S_ISREG(mode) && type == OBJ_BLOB && !args->convert &&
347347
size > big_file_threshold) {
348-
stream = open_istream(oid, &type, &size, NULL);
348+
stream = open_istream(args->repo, oid, &type, &size,
349+
NULL);
349350
if (!stream)
350351
return error(_("cannot stream blob %s"),
351352
oid_to_hex(oid));

builtin/index-pack.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,8 @@ static int check_collison(struct object_entry *entry)
757757

758758
memset(&data, 0, sizeof(data));
759759
data.entry = entry;
760-
data.st = open_istream(&entry->idx.oid, &type, &size, NULL);
760+
data.st = open_istream(the_repository, &entry->idx.oid, &type, &size,
761+
NULL);
761762
if (!data.st)
762763
return -1;
763764
if (size != entry->size || type != entry->type)

builtin/pack-objects.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
303303
if (!usable_delta) {
304304
if (oe_type(entry) == OBJ_BLOB &&
305305
oe_size_greater_than(&to_pack, entry, big_file_threshold) &&
306-
(st = open_istream(&entry->idx.oid, &type, &size, NULL)) != NULL)
306+
(st = open_istream(the_repository, &entry->idx.oid, &type,
307+
&size, NULL)) != NULL)
307308
buf = NULL;
308309
else {
309310
buf = read_object_file(&entry->idx.oid, &type, &size);

sha1-file.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ int check_object_signature(const struct object_id *oid, void *map,
986986
return !oideq(oid, &real_oid) ? -1 : 0;
987987
}
988988

989-
st = open_istream(oid, &obj_type, &size, NULL);
989+
st = open_istream(the_repository, oid, &obj_type, &size, NULL);
990990
if (!st)
991991
return -1;
992992

streaming.c

+15-13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ enum input_source {
1616
};
1717

1818
typedef int (*open_istream_fn)(struct git_istream *,
19+
struct repository *,
1920
struct object_info *,
2021
const struct object_id *,
2122
enum object_type *);
@@ -29,8 +30,8 @@ struct stream_vtbl {
2930

3031
#define open_method_decl(name) \
3132
int open_istream_ ##name \
32-
(struct git_istream *st, struct object_info *oi, \
33-
const struct object_id *oid, \
33+
(struct git_istream *st, struct repository *r, \
34+
struct object_info *oi, const struct object_id *oid, \
3435
enum object_type *type)
3536

3637
#define close_method_decl(name) \
@@ -108,7 +109,8 @@ ssize_t read_istream(struct git_istream *st, void *buf, size_t sz)
108109
return st->vtbl->read(st, buf, sz);
109110
}
110111

111-
static enum input_source istream_source(const struct object_id *oid,
112+
static enum input_source istream_source(struct repository *r,
113+
const struct object_id *oid,
112114
enum object_type *type,
113115
struct object_info *oi)
114116
{
@@ -117,7 +119,7 @@ static enum input_source istream_source(const struct object_id *oid,
117119

118120
oi->typep = type;
119121
oi->sizep = &size;
120-
status = oid_object_info_extended(the_repository, oid, oi, 0);
122+
status = oid_object_info_extended(r, oid, oi, 0);
121123
if (status < 0)
122124
return stream_error;
123125

@@ -133,22 +135,23 @@ static enum input_source istream_source(const struct object_id *oid,
133135
}
134136
}
135137

136-
struct git_istream *open_istream(const struct object_id *oid,
138+
struct git_istream *open_istream(struct repository *r,
139+
const struct object_id *oid,
137140
enum object_type *type,
138141
unsigned long *size,
139142
struct stream_filter *filter)
140143
{
141144
struct git_istream *st;
142145
struct object_info oi = OBJECT_INFO_INIT;
143-
const struct object_id *real = lookup_replace_object(the_repository, oid);
144-
enum input_source src = istream_source(real, type, &oi);
146+
const struct object_id *real = lookup_replace_object(r, oid);
147+
enum input_source src = istream_source(r, real, type, &oi);
145148

146149
if (src < 0)
147150
return NULL;
148151

149152
st = xmalloc(sizeof(*st));
150-
if (open_istream_tbl[src](st, &oi, real, type)) {
151-
if (open_istream_incore(st, &oi, real, type)) {
153+
if (open_istream_tbl[src](st, r, &oi, real, type)) {
154+
if (open_istream_incore(st, r, &oi, real, type)) {
152155
free(st);
153156
return NULL;
154157
}
@@ -338,8 +341,7 @@ static struct stream_vtbl loose_vtbl = {
338341

339342
static open_method_decl(loose)
340343
{
341-
st->u.loose.mapped = map_loose_object(the_repository,
342-
oid, &st->u.loose.mapsize);
344+
st->u.loose.mapped = map_loose_object(r, oid, &st->u.loose.mapsize);
343345
if (!st->u.loose.mapped)
344346
return -1;
345347
if ((unpack_loose_header(&st->z,
@@ -499,7 +501,7 @@ static struct stream_vtbl incore_vtbl = {
499501

500502
static open_method_decl(incore)
501503
{
502-
st->u.incore.buf = read_object_file_extended(the_repository, oid, type, &st->size, 0);
504+
st->u.incore.buf = read_object_file_extended(r, oid, type, &st->size, 0);
503505
st->u.incore.read_ptr = 0;
504506
st->vtbl = &incore_vtbl;
505507

@@ -520,7 +522,7 @@ int stream_blob_to_fd(int fd, const struct object_id *oid, struct stream_filter
520522
ssize_t kept = 0;
521523
int result = -1;
522524

523-
st = open_istream(oid, &type, &sz, filter);
525+
st = open_istream(the_repository, oid, &type, &sz, filter);
524526
if (!st) {
525527
if (filter)
526528
free_stream_filter(filter);

streaming.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
/* opaque */
99
struct git_istream;
1010

11-
struct git_istream *open_istream(const struct object_id *, enum object_type *, unsigned long *, struct stream_filter *);
11+
struct git_istream *open_istream(struct repository *, const struct object_id *,
12+
enum object_type *, unsigned long *,
13+
struct stream_filter *);
1214
int close_istream(struct git_istream *);
1315
ssize_t read_istream(struct git_istream *, void *, size_t);
1416

0 commit comments

Comments
 (0)