mirror of
https://github.com/git/git.git
synced 2026-06-24 08:48:31 +00:00
object-file: remove flags from transaction packfile writes
The `index_blob_packfile_transaction()` function handles streaming a blob from an fd to compute its object ID and conditionally writes the object directly to a packfile if the INDEX_WRITE_OBJECT flag is set. A subsequent commit will make these packfile object writes part of the transaction interface. Consequently, having the object write be conditional on this flag is a bit awkward. In preparation for this change, introduce a dedicated `hash_blob_stream()` helper that only computes the OID from a `struct odb_write_stream`. This is invoked by `index_fd()` instead when the INDEX_WRITE_OBJECT is not set. The object write performed via `index_blob_packfile_transaction()` is made unconditional accordingly. Signed-off-by: Justin Tobler <jltobler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
970f63519e
commit
8a1f5ecf28
@@ -237,6 +237,11 @@ ssize_t odb_write_stream_read(struct odb_write_stream *st, void *buf, size_t sz)
|
||||
return st->read(st, buf, sz);
|
||||
}
|
||||
|
||||
void odb_write_stream_release(struct odb_write_stream *st)
|
||||
{
|
||||
free(st->data);
|
||||
}
|
||||
|
||||
int odb_stream_blob_to_fd(struct object_database *odb,
|
||||
int fd,
|
||||
const struct object_id *oid,
|
||||
@@ -292,3 +297,44 @@ int odb_stream_blob_to_fd(struct object_database *odb,
|
||||
odb_read_stream_close(st);
|
||||
return result;
|
||||
}
|
||||
|
||||
struct read_object_fd_data {
|
||||
int fd;
|
||||
size_t remaining;
|
||||
};
|
||||
|
||||
static ssize_t read_object_fd(struct odb_write_stream *stream,
|
||||
unsigned char *buf, size_t len)
|
||||
{
|
||||
struct read_object_fd_data *data = stream->data;
|
||||
ssize_t read_result;
|
||||
size_t count;
|
||||
|
||||
if (stream->is_finished)
|
||||
return 0;
|
||||
|
||||
count = data->remaining < len ? data->remaining : len;
|
||||
read_result = read_in_full(data->fd, buf, count);
|
||||
if (read_result < 0 || (size_t)read_result != count)
|
||||
return -1;
|
||||
|
||||
data->remaining -= count;
|
||||
if (!data->remaining)
|
||||
stream->is_finished = 1;
|
||||
|
||||
return read_result;
|
||||
}
|
||||
|
||||
void odb_write_stream_from_fd(struct odb_write_stream *stream, int fd,
|
||||
size_t size)
|
||||
{
|
||||
struct read_object_fd_data *data;
|
||||
|
||||
CALLOC_ARRAY(data, 1);
|
||||
data->fd = fd;
|
||||
data->remaining = size;
|
||||
|
||||
stream->data = data;
|
||||
stream->read = read_object_fd;
|
||||
stream->is_finished = 0;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#define STREAMING_H 1
|
||||
|
||||
#include "object.h"
|
||||
#include "odb.h"
|
||||
|
||||
struct object_database;
|
||||
struct odb_read_stream;
|
||||
@@ -65,6 +66,11 @@ struct odb_write_stream {
|
||||
ssize_t odb_write_stream_read(struct odb_write_stream *stream, void *buf,
|
||||
size_t len);
|
||||
|
||||
/*
|
||||
* Releases memory allocated for underlying stream data.
|
||||
*/
|
||||
void odb_write_stream_release(struct odb_write_stream *stream);
|
||||
|
||||
/*
|
||||
* Look up the object by its ID and write the full contents to the file
|
||||
* descriptor. The object must be a blob, or the function will fail. When
|
||||
@@ -82,4 +88,10 @@ 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.
|
||||
*/
|
||||
void odb_write_stream_from_fd(struct odb_write_stream *stream, int fd,
|
||||
size_t size);
|
||||
|
||||
#endif /* STREAMING_H */
|
||||
|
||||
Reference in New Issue
Block a user