Skip to content

Commit 06523c6

Browse files
pks-tgitster
authored andcommitted
streaming: drop redundant type and size pointers
In the preceding commits we have turned `struct odb_read_stream` into a publicly visible structure. Furthermore, this structure now contains the type and size of the object that we are about to stream. Consequently, the out-pointers that we used before to propagate the type and size of the streamed object are now somewhat redundant with the data contained in the structure itself. Drop these out-pointers and adapt callers accordingly. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3e74504 commit 06523c6

File tree

7 files changed

+15
-30
lines changed

7 files changed

+15
-30
lines changed

archive-tar.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,10 @@ static void write_trailer(void)
130130
static int stream_blocked(struct repository *r, const struct object_id *oid)
131131
{
132132
struct odb_read_stream *st;
133-
enum object_type type;
134-
unsigned long sz;
135133
char buf[BLOCKSIZE];
136134
ssize_t readlen;
137135

138-
st = odb_read_object_stream(r->objects, 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 (;;) {

archive-zip.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = odb_read_object_stream(args->repo->objects, oid,
352-
&type, &size, 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 {

builtin/index-pack.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -798,20 +798,17 @@ 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 = odb_read_object_stream(the_repository->objects, &entry->idx.oid,
811-
&type, &size, 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);

builtin/pack-objects.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,11 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
521521
oe_size_greater_than(&to_pack, entry,
522522
repo_settings_get_big_file_threshold(the_repository)) &&
523523
(st = odb_read_object_stream(the_repository->objects, &entry->idx.oid,
524-
&type, &size, NULL)) != NULL)
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);

object-file.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,17 @@ int check_object_signature(struct repository *r, const struct object_id *oid,
132132
int stream_object_signature(struct repository *r, const struct object_id *oid)
133133
{
134134
struct object_id real_oid;
135-
unsigned long size;
136-
enum object_type obj_type;
137135
struct odb_read_stream *st;
138136
struct git_hash_ctx c;
139137
char hdr[MAX_HEADER_LEN];
140138
int hdrlen;
141139

142-
st = odb_read_object_stream(r->objects, oid, &obj_type, &size, NULL);
140+
st = odb_read_object_stream(r->objects, oid, NULL);
143141
if (!st)
144142
return -1;
145143

146144
/* Generate the header */
147-
hdrlen = format_object_header(hdr, sizeof(hdr), obj_type, size);
145+
hdrlen = format_object_header(hdr, sizeof(hdr), st->type, st->size);
148146

149147
/* Sha1.. */
150148
r->hash_algo->init_fn(&c);

odb/streaming.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ ssize_t odb_read_stream_read(struct odb_read_stream *st, void *buf, size_t sz)
214214

215215
struct odb_read_stream *odb_read_object_stream(struct object_database *odb,
216216
const struct object_id *oid,
217-
enum object_type *type,
218-
unsigned long *size,
219217
struct stream_filter *filter)
220218
{
221219
struct odb_read_stream *st;
@@ -236,8 +234,6 @@ struct odb_read_stream *odb_read_object_stream(struct object_database *odb,
236234
st = nst;
237235
}
238236

239-
*size = st->size;
240-
*type = st->type;
241237
return st;
242238
}
243239

@@ -248,18 +244,16 @@ int odb_stream_blob_to_fd(struct object_database *odb,
248244
int can_seek)
249245
{
250246
struct odb_read_stream *st;
251-
enum object_type type;
252-
unsigned long sz;
253247
ssize_t kept = 0;
254248
int result = -1;
255249

256-
st = odb_read_object_stream(odb, oid, &type, &sz, filter);
250+
st = odb_read_object_stream(odb, oid, filter);
257251
if (!st) {
258252
if (filter)
259253
free_stream_filter(filter);
260254
return result;
261255
}
262-
if (type != OBJ_BLOB)
256+
if (st->type != OBJ_BLOB)
263257
goto close_and_exit;
264258
for (;;) {
265259
char buf[1024 * 16];

odb/streaming.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,13 @@ struct odb_read_stream {
2525
};
2626

2727
/*
28-
* Create a new object stream for the given object database. Populates the type
29-
* and size pointers with the object's info. An optional filter can be used to
30-
* transform the object's content.
28+
* Create a new object stream for the given object database. An optional filter
29+
* can be used to transform the object's content.
3130
*
3231
* Returns the stream on success, a `NULL` pointer otherwise.
3332
*/
3433
struct odb_read_stream *odb_read_object_stream(struct object_database *odb,
3534
const struct object_id *oid,
36-
enum object_type *type,
37-
unsigned long *size,
3835
struct stream_filter *filter);
3936

4037
/*

0 commit comments

Comments
 (0)