odb/streaming: unify function names to create new streams
Unify the function names to create new streams from different sources so that they follow a common schema. While at it, document the ownership of the file descriptor passed to `odb_stream_from_fd()`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>main
parent
3f8290ea85
commit
ebdd7e10d6
|
|
@ -133,7 +133,7 @@ static int stream_blocked(struct repository *r, const struct object_id *oid)
|
||||||
char buf[BLOCKSIZE];
|
char buf[BLOCKSIZE];
|
||||||
ssize_t readlen;
|
ssize_t readlen;
|
||||||
|
|
||||||
st = odb_read_stream_open(r->objects, oid, NULL);
|
st = odb_stream_from_object(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,7 +347,7 @@ static int write_zip_entry(struct archiver_args *args,
|
||||||
method = ZIP_METHOD_DEFLATE;
|
method = ZIP_METHOD_DEFLATE;
|
||||||
|
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
stream = odb_read_stream_open(args->repo->objects, oid, NULL);
|
stream = odb_stream_from_object(args->repo->objects, oid, 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));
|
||||||
|
|
|
||||||
|
|
@ -806,7 +806,7 @@ 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, NULL);
|
data.st = odb_stream_from_object(the_repository->objects, &entry->idx.oid, NULL);
|
||||||
if (!data.st)
|
if (!data.st)
|
||||||
return -1;
|
return -1;
|
||||||
if (data.st->size != entry->size || data.st->type != entry->type)
|
if (data.st->size != entry->size || data.st->type != entry->type)
|
||||||
|
|
|
||||||
|
|
@ -528,8 +528,8 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
|
||||||
if (oe_type(entry) == OBJ_BLOB &&
|
if (oe_type(entry) == OBJ_BLOB &&
|
||||||
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_stream_from_object(the_repository->objects, &entry->idx.oid,
|
||||||
NULL)) != NULL) {
|
NULL)) != NULL) {
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
type = st->type;
|
type = st->type;
|
||||||
size = st->size;
|
size = st->size;
|
||||||
|
|
|
||||||
|
|
@ -952,8 +952,8 @@ int index_fd(struct index_state *istate, struct object_id *oid,
|
||||||
ret = index_core(istate, oid, fd, xsize_t(st->st_size),
|
ret = index_core(istate, oid, fd, xsize_t(st->st_size),
|
||||||
type, path, flags);
|
type, path, flags);
|
||||||
} else {
|
} else {
|
||||||
struct odb_stream *stream = odb_write_stream_from_fd(fd, xsize_t(st->st_size),
|
struct odb_stream *stream = odb_stream_from_fd(fd, xsize_t(st->st_size),
|
||||||
OBJ_BLOB);
|
OBJ_BLOB);
|
||||||
|
|
||||||
if (flags & INDEX_WRITE_OBJECT) {
|
if (flags & INDEX_WRITE_OBJECT) {
|
||||||
struct object_database *odb = the_repository->objects;
|
struct object_database *odb = the_repository->objects;
|
||||||
|
|
|
||||||
2
object.c
2
object.c
|
|
@ -345,7 +345,7 @@ struct object *parse_object_with_flags(struct repository *r,
|
||||||
if ((!obj || obj->type == OBJ_NONE || obj->type == OBJ_BLOB) &&
|
if ((!obj || obj->type == OBJ_NONE || obj->type == OBJ_BLOB) &&
|
||||||
odb_read_object_info(r->objects, oid, NULL) == OBJ_BLOB) {
|
odb_read_object_info(r->objects, oid, NULL) == OBJ_BLOB) {
|
||||||
if (!skip_hash) {
|
if (!skip_hash) {
|
||||||
struct odb_stream *stream = odb_read_stream_open(r->objects, oid, NULL);
|
struct odb_stream *stream = odb_stream_from_object(r->objects, oid, NULL);
|
||||||
|
|
||||||
if (!stream) {
|
if (!stream) {
|
||||||
error(_("unable to open object stream for %s"), oid_to_hex(oid));
|
error(_("unable to open object stream for %s"), oid_to_hex(oid));
|
||||||
|
|
|
||||||
|
|
@ -208,9 +208,9 @@ ssize_t odb_stream_read(struct odb_stream *st, void *buf, size_t sz)
|
||||||
return st->read(st, buf, sz);
|
return st->read(st, buf, sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct odb_stream *odb_read_stream_open(struct object_database *odb,
|
struct odb_stream *odb_stream_from_object(struct object_database *odb,
|
||||||
const struct object_id *oid,
|
const struct object_id *oid,
|
||||||
struct stream_filter *filter)
|
struct stream_filter *filter)
|
||||||
{
|
{
|
||||||
struct odb_stream *st;
|
struct odb_stream *st;
|
||||||
const struct object_id *real = lookup_replace_object(odb->repo, oid);
|
const struct object_id *real = lookup_replace_object(odb->repo, oid);
|
||||||
|
|
@ -242,7 +242,7 @@ int odb_stream_blob_to_fd(struct object_database *odb,
|
||||||
ssize_t kept = 0;
|
ssize_t kept = 0;
|
||||||
int result = -1;
|
int result = -1;
|
||||||
|
|
||||||
st = odb_read_stream_open(odb, oid, filter);
|
st = odb_stream_from_object(odb, oid, filter);
|
||||||
if (!st) {
|
if (!st) {
|
||||||
if (filter)
|
if (filter)
|
||||||
free_stream_filter(filter);
|
free_stream_filter(filter);
|
||||||
|
|
@ -320,7 +320,7 @@ static int fd_stream_close(struct odb_stream *stream UNUSED)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct odb_stream *odb_write_stream_from_fd(int fd, size_t size, enum object_type type)
|
struct odb_stream *odb_stream_from_fd(int fd, size_t size, enum object_type type)
|
||||||
{
|
{
|
||||||
struct fd_stream *fds;
|
struct fd_stream *fds;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,14 +26,22 @@ struct odb_stream {
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a new object stream for the given object database. An optional filter
|
* Create a new object stream for the given object. An optional filter can be
|
||||||
* can be used to transform the object's content.
|
* used to 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_stream *odb_read_stream_open(struct object_database *odb,
|
struct odb_stream *odb_stream_from_object(struct object_database *odb,
|
||||||
const struct object_id *oid,
|
const struct object_id *oid,
|
||||||
struct stream_filter *filter);
|
struct stream_filter *filter);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a new object stream for the given file descriptor. This can be used
|
||||||
|
* to, for example, stream an object into the object database. This function
|
||||||
|
* does _not_ take ownership of the file descriptor. It's the responsibility of
|
||||||
|
* the caller to close it after the stream has been closed.
|
||||||
|
*/
|
||||||
|
struct odb_stream *odb_stream_from_fd(int fd, size_t size, enum object_type type);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Close the given object stream and release all resources associated with it.
|
* Close the given object stream and release all resources associated with it.
|
||||||
|
|
@ -65,9 +73,4 @@ int odb_stream_blob_to_fd(struct object_database *odb,
|
||||||
struct stream_filter *filter,
|
struct stream_filter *filter,
|
||||||
int can_seek);
|
int can_seek);
|
||||||
|
|
||||||
/*
|
|
||||||
* Sets up an ODB write stream that reads from an fd.
|
|
||||||
*/
|
|
||||||
struct odb_stream *odb_write_stream_from_fd(int fd, size_t size, enum object_type type);
|
|
||||||
|
|
||||||
#endif /* STREAMING_H */
|
#endif /* STREAMING_H */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue