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 <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matheus Tavares committed
Jan 30, 2020 at 17:32 UTC
c8123e72f6d8bc4106afdd172895a28b0c30fb3b
7 files changed
+28
-21
archive-tar.c
+3
-3
@@ -112,7 +112,7 @@ static void write_trailer(void)
112
* queues up writes, so that all our write(2) calls write exactly one
113
* full block; pads writes to RECORDSIZE
114
*/
115
-static int stream_blocked(const struct object_id *oid)
115
+static int stream_blocked(struct repository *r, const struct object_id *oid)
116
{
117
struct git_istream *st;
118
enum object_type type;
@@ -120,7 +120,7 @@ static int stream_blocked(const struct object_id *oid)
120
char buf[BLOCKSIZE];
121
ssize_t readlen;
122
123
- st = open_istream(oid, &type, &sz, NULL);
123
+ st = open_istream(r, oid, &type, &sz, NULL);
124
if (!st)
125
return error(_("cannot stream blob %s"), oid_to_hex(oid));
126
for (;;) {
@@ -324,7 +324,7 @@ static int write_tar_entry(struct archiver_args *args,
324
if (buffer)
325
write_blocked(buffer, size);
326
else
327
- err = stream_blocked(oid);
327
+ err = stream_blocked(args->repo, oid);
328
}
329
free(buffer);
330
return err;
archive-zip.c
+2
-1
@@ -345,7 +345,8 @@ static int write_zip_entry(struct archiver_args *args,
345
346
if (S_ISREG(mode) && type == OBJ_BLOB && !args->convert &&
347
size > big_file_threshold) {
348
- stream = open_istream(oid, &type, &size, NULL);
348
+ stream = open_istream(args->repo, oid, &type, &size,
349
+ NULL);
350
if (!stream)
351
return error(_("cannot stream blob %s"),
352
oid_to_hex(oid));
builtin/index-pack.c
+2
-1
@@ -757,7 +757,8 @@ static int check_collison(struct object_entry *entry)
757
758
memset(&data, 0, sizeof(data));
759
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);
762
if (!data.st)
763
return -1;
764
if (size != entry->size || type != entry->type)
builtin/pack-objects.c
+2
-1
@@ -303,7 +303,8 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
303
if (!usable_delta) {
304
if (oe_type(entry) == OBJ_BLOB &&
305
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)
308
buf = NULL;
309
else {
310
buf = read_object_file(&entry->idx.oid, &type, &size);
sha1-file.c
+1
-1
@@ -986,7 +986,7 @@ int check_object_signature(const struct object_id *oid, void *map,
986
return !oideq(oid, &real_oid) ? -1 : 0;
987
}
988
989
- st = open_istream(oid, &obj_type, &size, NULL);
989
+ st = open_istream(the_repository, oid, &obj_type, &size, NULL);
990
if (!st)
991
return -1;
992
streaming.c
+15
-13
@@ -16,6 +16,7 @@ enum input_source {
16
};
17
18
typedef int (*open_istream_fn)(struct git_istream *,
19
+ struct repository *,
20
struct object_info *,
21
const struct object_id *,
22
enum object_type *);
@@ -29,8 +30,8 @@ struct stream_vtbl {
30
31
#define open_method_decl(name) \
32
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, \
35
enum object_type *type)
36
37
#define close_method_decl(name) \
@@ -108,7 +109,8 @@ ssize_t read_istream(struct git_istream *st, void *buf, size_t sz)
109
return st->vtbl->read(st, buf, sz);
110
}
111
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,
114
enum object_type *type,
115
struct object_info *oi)
116
{
@@ -117,7 +119,7 @@ static enum input_source istream_source(const struct object_id *oid,
119
120
oi->typep = type;
121
oi->sizep = &size;
120
- status = oid_object_info_extended(the_repository, oid, oi, 0);
122
+ status = oid_object_info_extended(r, oid, oi, 0);
123
if (status < 0)
124
return stream_error;
125
@@ -133,22 +135,23 @@ static enum input_source istream_source(const struct object_id *oid,
135
}
136
}
137
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,
140
enum object_type *type,
141
unsigned long *size,
142
struct stream_filter *filter)
143
{
144
struct git_istream *st;
145
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);
148
149
if (src < 0)
150
return NULL;
151
152
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)) {
155
free(st);
156
return NULL;
157
}
@@ -338,8 +341,7 @@ static struct stream_vtbl loose_vtbl = {
341
342
static open_method_decl(loose)
343
{
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);
345
if (!st->u.loose.mapped)
346
return -1;
347
if ((unpack_loose_header(&st->z,
@@ -499,7 +501,7 @@ static struct stream_vtbl incore_vtbl = {
501
502
static open_method_decl(incore)
503
{
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);
505
st->u.incore.read_ptr = 0;
506
st->vtbl = &incore_vtbl;
507
@@ -520,7 +522,7 @@ int stream_blob_to_fd(int fd, const struct object_id *oid, struct stream_filter
522
ssize_t kept = 0;
523
int result = -1;
524
523
- st = open_istream(oid, &type, &sz, filter);
525
+ st = open_istream(the_repository, oid, &type, &sz, filter);
526
if (!st) {
527
if (filter)
528
free_stream_filter(filter);
streaming.h
+3
-1
@@ -8,7 +8,9 @@
8
/* opaque */
9
struct git_istream;
10
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 *);
14
int close_istream(struct git_istream *);
15
ssize_t read_istream(struct git_istream *, void *, size_t);
16