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>
This commit is contained in:
Patrick Steinhardt
2026-08-05 09:44:52 +02:00
committed by Junio C Hamano
parent 3f8290ea85
commit ebdd7e10d6
8 changed files with 26 additions and 23 deletions

View File

@@ -133,7 +133,7 @@ static int stream_blocked(struct repository *r, const struct object_id *oid)
char buf[BLOCKSIZE];
ssize_t readlen;
st = odb_read_stream_open(r->objects, oid, NULL);
st = odb_stream_from_object(r->objects, oid, NULL);
if (!st)
return error(_("cannot stream blob %s"), oid_to_hex(oid));
for (;;) {

View File

@@ -347,7 +347,7 @@ static int write_zip_entry(struct archiver_args *args,
method = ZIP_METHOD_DEFLATE;
if (!buffer) {
stream = odb_read_stream_open(args->repo->objects, oid, NULL);
stream = odb_stream_from_object(args->repo->objects, oid, NULL);
if (!stream)
return error(_("cannot stream blob %s"),
oid_to_hex(oid));

View File

@@ -806,7 +806,7 @@ static int check_collison(struct object_entry *entry)
memset(&data, 0, sizeof(data));
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)
return -1;
if (data.st->size != entry->size || data.st->type != entry->type)

View File

@@ -528,8 +528,8 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
if (oe_type(entry) == OBJ_BLOB &&
oe_size_greater_than(&to_pack, entry,
repo_settings_get_big_file_threshold(the_repository)) &&
(st = odb_read_stream_open(the_repository->objects, &entry->idx.oid,
NULL)) != NULL) {
(st = odb_stream_from_object(the_repository->objects, &entry->idx.oid,
NULL)) != NULL) {
buf = NULL;
type = st->type;
size = st->size;

View File

@@ -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),
type, path, flags);
} else {
struct odb_stream *stream = odb_write_stream_from_fd(fd, xsize_t(st->st_size),
OBJ_BLOB);
struct odb_stream *stream = odb_stream_from_fd(fd, xsize_t(st->st_size),
OBJ_BLOB);
if (flags & INDEX_WRITE_OBJECT) {
struct object_database *odb = the_repository->objects;

View File

@@ -345,7 +345,7 @@ struct object *parse_object_with_flags(struct repository *r,
if ((!obj || obj->type == OBJ_NONE || obj->type == OBJ_BLOB) &&
odb_read_object_info(r->objects, oid, NULL) == OBJ_BLOB) {
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) {
error(_("unable to open object stream for %s"), oid_to_hex(oid));

View File

@@ -208,9 +208,9 @@ ssize_t odb_stream_read(struct odb_stream *st, void *buf, size_t sz)
return st->read(st, buf, sz);
}
struct odb_stream *odb_read_stream_open(struct object_database *odb,
const struct object_id *oid,
struct stream_filter *filter)
struct odb_stream *odb_stream_from_object(struct object_database *odb,
const struct object_id *oid,
struct stream_filter *filter)
{
struct odb_stream *st;
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;
int result = -1;
st = odb_read_stream_open(odb, oid, filter);
st = odb_stream_from_object(odb, oid, filter);
if (!st) {
if (filter)
free_stream_filter(filter);
@@ -320,7 +320,7 @@ static int fd_stream_close(struct odb_stream *stream UNUSED)
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;

View File

@@ -26,14 +26,22 @@ struct odb_stream {
};
/*
* Create a new object stream for the given object database. An optional filter
* can be used to transform the object's content.
* Create a new object stream for the given object. An optional filter can be
* used to transform the object's content.
*
* Returns the stream on success, a `NULL` pointer otherwise.
*/
struct odb_stream *odb_read_stream_open(struct object_database *odb,
const struct object_id *oid,
struct stream_filter *filter);
struct odb_stream *odb_stream_from_object(struct object_database *odb,
const struct object_id *oid,
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.
@@ -65,9 +73,4 @@ int odb_stream_blob_to_fd(struct object_database *odb,
struct stream_filter *filter,
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 */