mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
1599b68d5e
commit
7b94028652
@@ -130,12 +130,10 @@ static void write_trailer(void)
|
|||||||
static int stream_blocked(struct repository *r, const struct object_id *oid)
|
static int stream_blocked(struct repository *r, const struct object_id *oid)
|
||||||
{
|
{
|
||||||
struct odb_read_stream *st;
|
struct odb_read_stream *st;
|
||||||
enum object_type type;
|
|
||||||
unsigned long sz;
|
|
||||||
char buf[BLOCKSIZE];
|
char buf[BLOCKSIZE];
|
||||||
ssize_t readlen;
|
ssize_t readlen;
|
||||||
|
|
||||||
st = odb_read_stream_open(r->objects, oid, &type, &sz, NULL);
|
st = odb_read_stream_open(r->objects, oid, NULL);
|
||||||
if (!st)
|
if (!st)
|
||||||
return error(_("cannot stream blob %s"), oid_to_hex(oid));
|
return error(_("cannot stream blob %s"), oid_to_hex(oid));
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|||||||
@@ -347,12 +347,11 @@ static int write_zip_entry(struct archiver_args *args,
|
|||||||
method = ZIP_METHOD_DEFLATE;
|
method = ZIP_METHOD_DEFLATE;
|
||||||
|
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
enum object_type type;
|
stream = odb_read_stream_open(args->repo->objects, oid, NULL);
|
||||||
stream = odb_read_stream_open(args->repo->objects, oid,
|
|
||||||
&type, &size, NULL);
|
|
||||||
if (!stream)
|
if (!stream)
|
||||||
return error(_("cannot stream blob %s"),
|
return error(_("cannot stream blob %s"),
|
||||||
oid_to_hex(oid));
|
oid_to_hex(oid));
|
||||||
|
size = stream->size;
|
||||||
flags |= ZIP_STREAM;
|
flags |= ZIP_STREAM;
|
||||||
out = NULL;
|
out = NULL;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -798,8 +798,6 @@ static int compare_objects(const unsigned char *buf, unsigned long size,
|
|||||||
static int check_collison(struct object_entry *entry)
|
static int check_collison(struct object_entry *entry)
|
||||||
{
|
{
|
||||||
struct compare_data data;
|
struct compare_data data;
|
||||||
enum object_type type;
|
|
||||||
unsigned long size;
|
|
||||||
|
|
||||||
if (entry->size <= repo_settings_get_big_file_threshold(the_repository) ||
|
if (entry->size <= repo_settings_get_big_file_threshold(the_repository) ||
|
||||||
entry->type != OBJ_BLOB)
|
entry->type != OBJ_BLOB)
|
||||||
@@ -807,11 +805,10 @@ static int check_collison(struct object_entry *entry)
|
|||||||
|
|
||||||
memset(&data, 0, sizeof(data));
|
memset(&data, 0, sizeof(data));
|
||||||
data.entry = entry;
|
data.entry = entry;
|
||||||
data.st = odb_read_stream_open(the_repository->objects, &entry->idx.oid,
|
data.st = odb_read_stream_open(the_repository->objects, &entry->idx.oid, NULL);
|
||||||
&type, &size, NULL);
|
|
||||||
if (!data.st)
|
if (!data.st)
|
||||||
return -1;
|
return -1;
|
||||||
if (size != entry->size || type != entry->type)
|
if (data.st->size != entry->size || data.st->type != entry->type)
|
||||||
die(_("SHA1 COLLISION FOUND WITH %s !"),
|
die(_("SHA1 COLLISION FOUND WITH %s !"),
|
||||||
oid_to_hex(&entry->idx.oid));
|
oid_to_hex(&entry->idx.oid));
|
||||||
unpack_data(entry, compare_objects, &data);
|
unpack_data(entry, compare_objects, &data);
|
||||||
|
|||||||
@@ -521,9 +521,11 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
|
|||||||
oe_size_greater_than(&to_pack, entry,
|
oe_size_greater_than(&to_pack, entry,
|
||||||
repo_settings_get_big_file_threshold(the_repository)) &&
|
repo_settings_get_big_file_threshold(the_repository)) &&
|
||||||
(st = odb_read_stream_open(the_repository->objects, &entry->idx.oid,
|
(st = odb_read_stream_open(the_repository->objects, &entry->idx.oid,
|
||||||
&type, &size, NULL)) != NULL)
|
NULL)) != NULL) {
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
else {
|
type = st->type;
|
||||||
|
size = st->size;
|
||||||
|
} else {
|
||||||
buf = odb_read_object(the_repository->objects,
|
buf = odb_read_object(the_repository->objects,
|
||||||
&entry->idx.oid, &type,
|
&entry->idx.oid, &type,
|
||||||
&size);
|
&size);
|
||||||
|
|||||||
@@ -132,19 +132,17 @@ int check_object_signature(struct repository *r, const struct object_id *oid,
|
|||||||
int stream_object_signature(struct repository *r, const struct object_id *oid)
|
int stream_object_signature(struct repository *r, const struct object_id *oid)
|
||||||
{
|
{
|
||||||
struct object_id real_oid;
|
struct object_id real_oid;
|
||||||
unsigned long size;
|
|
||||||
enum object_type obj_type;
|
|
||||||
struct odb_read_stream *st;
|
struct odb_read_stream *st;
|
||||||
struct git_hash_ctx c;
|
struct git_hash_ctx c;
|
||||||
char hdr[MAX_HEADER_LEN];
|
char hdr[MAX_HEADER_LEN];
|
||||||
int hdrlen;
|
int hdrlen;
|
||||||
|
|
||||||
st = odb_read_stream_open(r->objects, oid, &obj_type, &size, NULL);
|
st = odb_read_stream_open(r->objects, oid, NULL);
|
||||||
if (!st)
|
if (!st)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Generate the header */
|
/* Generate the header */
|
||||||
hdrlen = format_object_header(hdr, sizeof(hdr), obj_type, size);
|
hdrlen = format_object_header(hdr, sizeof(hdr), st->type, st->size);
|
||||||
|
|
||||||
/* Sha1.. */
|
/* Sha1.. */
|
||||||
r->hash_algo->init_fn(&c);
|
r->hash_algo->init_fn(&c);
|
||||||
|
|||||||
@@ -214,8 +214,6 @@ ssize_t odb_read_stream_read(struct odb_read_stream *st, void *buf, size_t sz)
|
|||||||
|
|
||||||
struct odb_read_stream *odb_read_stream_open(struct object_database *odb,
|
struct odb_read_stream *odb_read_stream_open(struct object_database *odb,
|
||||||
const struct object_id *oid,
|
const struct object_id *oid,
|
||||||
enum object_type *type,
|
|
||||||
unsigned long *size,
|
|
||||||
struct stream_filter *filter)
|
struct stream_filter *filter)
|
||||||
{
|
{
|
||||||
struct odb_read_stream *st;
|
struct odb_read_stream *st;
|
||||||
@@ -235,8 +233,6 @@ struct odb_read_stream *odb_read_stream_open(struct object_database *odb,
|
|||||||
st = nst;
|
st = nst;
|
||||||
}
|
}
|
||||||
|
|
||||||
*size = st->size;
|
|
||||||
*type = st->type;
|
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,18 +243,16 @@ int odb_stream_blob_to_fd(struct object_database *odb,
|
|||||||
int can_seek)
|
int can_seek)
|
||||||
{
|
{
|
||||||
struct odb_read_stream *st;
|
struct odb_read_stream *st;
|
||||||
enum object_type type;
|
|
||||||
unsigned long sz;
|
|
||||||
ssize_t kept = 0;
|
ssize_t kept = 0;
|
||||||
int result = -1;
|
int result = -1;
|
||||||
|
|
||||||
st = odb_read_stream_open(odb, oid, &type, &sz, filter);
|
st = odb_read_stream_open(odb, oid, filter);
|
||||||
if (!st) {
|
if (!st) {
|
||||||
if (filter)
|
if (filter)
|
||||||
free_stream_filter(filter);
|
free_stream_filter(filter);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (type != OBJ_BLOB)
|
if (st->type != OBJ_BLOB)
|
||||||
goto close_and_exit;
|
goto close_and_exit;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char buf[1024 * 16];
|
char buf[1024 * 16];
|
||||||
|
|||||||
@@ -25,16 +25,13 @@ struct odb_read_stream {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a new object stream for the given object database. Populates the type
|
* Create a new object stream for the given object database. An optional filter
|
||||||
* and size pointers with the object's info. An optional filter can be used to
|
* can be used to transform the object's content.
|
||||||
* transform the object's content.
|
|
||||||
*
|
*
|
||||||
* Returns the stream on success, a `NULL` pointer otherwise.
|
* Returns the stream on success, a `NULL` pointer otherwise.
|
||||||
*/
|
*/
|
||||||
struct odb_read_stream *odb_read_stream_open(struct object_database *odb,
|
struct odb_read_stream *odb_read_stream_open(struct object_database *odb,
|
||||||
const struct object_id *oid,
|
const struct object_id *oid,
|
||||||
enum object_type *type,
|
|
||||||
unsigned long *size,
|
|
||||||
struct stream_filter *filter);
|
struct stream_filter *filter);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user