]> git.ipfire.org Git - thirdparty/git.git/commitdiff
streaming: allow open_istream() to handle any repo
authorMatheus Tavares <matheus.bernardino@usp.br>
Thu, 30 Jan 2020 20:32:20 +0000 (17:32 -0300)
committerJunio C Hamano <gitster@pobox.com>
Fri, 31 Jan 2020 18:45:39 +0000 (10:45 -0800)
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>
archive-tar.c
archive-zip.c
builtin/index-pack.c
builtin/pack-objects.c
sha1-file.c
streaming.c
streaming.h

index e16d3f756ddd61d38477e73b71aa01e912ba2b13..5a77701a15c2068ce91dcffb835335203a5860aa 100644 (file)
@@ -112,7 +112,7 @@ static void write_trailer(void)
  * queues up writes, so that all our write(2) calls write exactly one
  * full block; pads writes to RECORDSIZE
  */
-static int stream_blocked(const struct object_id *oid)
+static int stream_blocked(struct repository *r, const struct object_id *oid)
 {
        struct git_istream *st;
        enum object_type type;
@@ -120,7 +120,7 @@ static int stream_blocked(const struct object_id *oid)
        char buf[BLOCKSIZE];
        ssize_t readlen;
 
-       st = open_istream(oid, &type, &sz, NULL);
+       st = open_istream(r, oid, &type, &sz, NULL);
        if (!st)
                return error(_("cannot stream blob %s"), oid_to_hex(oid));
        for (;;) {
@@ -324,7 +324,7 @@ static int write_tar_entry(struct archiver_args *args,
                if (buffer)
                        write_blocked(buffer, size);
                else
-                       err = stream_blocked(oid);
+                       err = stream_blocked(args->repo, oid);
        }
        free(buffer);
        return err;
index 11f5b1974ba433fd77f9558528a053e4e2bb0a88..e9f426298b6d1c4ce64a1ef537a97375a8855d3c 100644 (file)
@@ -345,7 +345,8 @@ static int write_zip_entry(struct archiver_args *args,
 
                if (S_ISREG(mode) && type == OBJ_BLOB && !args->convert &&
                    size > big_file_threshold) {
-                       stream = open_istream(oid, &type, &size, NULL);
+                       stream = open_istream(args->repo, oid, &type, &size,
+                                             NULL);
                        if (!stream)
                                return error(_("cannot stream blob %s"),
                                             oid_to_hex(oid));
index 60a5591039abbdb9e0050bfda53123c577b41864..7a08da8401078d70224748b1ea4b8983696f600d 100644 (file)
@@ -757,7 +757,8 @@ static int check_collison(struct object_entry *entry)
 
        memset(&data, 0, sizeof(data));
        data.entry = entry;
-       data.st = open_istream(&entry->idx.oid, &type, &size, NULL);
+       data.st = open_istream(the_repository, &entry->idx.oid, &type, &size,
+                              NULL);
        if (!data.st)
                return -1;
        if (size != entry->size || type != entry->type)
index 393c20a2d78b50f8852ed11bc9e943b27ba58d2e..ef17efd94e282a3f74b947e8a11ae18f6712ea31 100644 (file)
@@ -303,7 +303,8 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
        if (!usable_delta) {
                if (oe_type(entry) == OBJ_BLOB &&
                    oe_size_greater_than(&to_pack, entry, big_file_threshold) &&
-                   (st = open_istream(&entry->idx.oid, &type, &size, NULL)) != NULL)
+                   (st = open_istream(the_repository, &entry->idx.oid, &type,
+                                      &size, NULL)) != NULL)
                        buf = NULL;
                else {
                        buf = read_object_file(&entry->idx.oid, &type, &size);
index 188de57634bb1b0b15fbe3ab97f062bed7927763..89ab9862053c0008d4f3e03c9d28fc57e97cba62 100644 (file)
@@ -986,7 +986,7 @@ int check_object_signature(const struct object_id *oid, void *map,
                return !oideq(oid, &real_oid) ? -1 : 0;
        }
 
-       st = open_istream(oid, &obj_type, &size, NULL);
+       st = open_istream(the_repository, oid, &obj_type, &size, NULL);
        if (!st)
                return -1;
 
index fcd63032192ff4056946ce3a0a266c7fb021353b..800f07a52cc850d7f972d7c651a8641eda2dfe38 100644 (file)
@@ -16,6 +16,7 @@ enum input_source {
 };
 
 typedef int (*open_istream_fn)(struct git_istream *,
+                              struct repository *,
                               struct object_info *,
                               const struct object_id *,
                               enum object_type *);
@@ -29,8 +30,8 @@ struct stream_vtbl {
 
 #define open_method_decl(name) \
        int open_istream_ ##name \
-       (struct git_istream *st, struct object_info *oi, \
-        const struct object_id *oid, \
+       (struct git_istream *st, struct repository *r, \
+        struct object_info *oi, const struct object_id *oid, \
         enum object_type *type)
 
 #define close_method_decl(name) \
@@ -108,7 +109,8 @@ ssize_t read_istream(struct git_istream *st, void *buf, size_t sz)
        return st->vtbl->read(st, buf, sz);
 }
 
-static enum input_source istream_source(const struct object_id *oid,
+static enum input_source istream_source(struct repository *r,
+                                       const struct object_id *oid,
                                        enum object_type *type,
                                        struct object_info *oi)
 {
@@ -117,7 +119,7 @@ static enum input_source istream_source(const struct object_id *oid,
 
        oi->typep = type;
        oi->sizep = &size;
-       status = oid_object_info_extended(the_repository, oid, oi, 0);
+       status = oid_object_info_extended(r, oid, oi, 0);
        if (status < 0)
                return stream_error;
 
@@ -133,22 +135,23 @@ static enum input_source istream_source(const struct object_id *oid,
        }
 }
 
-struct git_istream *open_istream(const struct object_id *oid,
+struct git_istream *open_istream(struct repository *r,
+                                const struct object_id *oid,
                                 enum object_type *type,
                                 unsigned long *size,
                                 struct stream_filter *filter)
 {
        struct git_istream *st;
        struct object_info oi = OBJECT_INFO_INIT;
-       const struct object_id *real = lookup_replace_object(the_repository, oid);
-       enum input_source src = istream_source(real, type, &oi);
+       const struct object_id *real = lookup_replace_object(r, oid);
+       enum input_source src = istream_source(r, real, type, &oi);
 
        if (src < 0)
                return NULL;
 
        st = xmalloc(sizeof(*st));
-       if (open_istream_tbl[src](st, &oi, real, type)) {
-               if (open_istream_incore(st, &oi, real, type)) {
+       if (open_istream_tbl[src](st, r, &oi, real, type)) {
+               if (open_istream_incore(st, r, &oi, real, type)) {
                        free(st);
                        return NULL;
                }
@@ -338,8 +341,7 @@ static struct stream_vtbl loose_vtbl = {
 
 static open_method_decl(loose)
 {
-       st->u.loose.mapped = map_loose_object(the_repository,
-                                             oid, &st->u.loose.mapsize);
+       st->u.loose.mapped = map_loose_object(r, oid, &st->u.loose.mapsize);
        if (!st->u.loose.mapped)
                return -1;
        if ((unpack_loose_header(&st->z,
@@ -499,7 +501,7 @@ static struct stream_vtbl incore_vtbl = {
 
 static open_method_decl(incore)
 {
-       st->u.incore.buf = read_object_file_extended(the_repository, oid, type, &st->size, 0);
+       st->u.incore.buf = read_object_file_extended(r, oid, type, &st->size, 0);
        st->u.incore.read_ptr = 0;
        st->vtbl = &incore_vtbl;
 
@@ -520,7 +522,7 @@ int stream_blob_to_fd(int fd, const struct object_id *oid, struct stream_filter
        ssize_t kept = 0;
        int result = -1;
 
-       st = open_istream(oid, &type, &sz, filter);
+       st = open_istream(the_repository, oid, &type, &sz, filter);
        if (!st) {
                if (filter)
                        free_stream_filter(filter);
index f465a3cd311ea7e899ec7bf922a1c24fc831f0b4..5e4e6acfd0dc947bcb92680fbae71de1fc486a78 100644 (file)
@@ -8,7 +8,9 @@
 /* opaque */
 struct git_istream;
 
-struct git_istream *open_istream(const struct object_id *, enum object_type *, unsigned long *, struct stream_filter *);
+struct git_istream *open_istream(struct repository *, const struct object_id *,
+                                enum object_type *, unsigned long *,
+                                struct stream_filter *);
 int close_istream(struct git_istream *);
 ssize_t read_istream(struct git_istream *, void *, size_t);