csum-file: introduce hashfd_ext()

Introduce a new `hashfd_ext()` function that takes an options structure.
This function will replace `hashd_throughput()` in the next commit.

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-03-03 16:00:23 +01:00
committed by Junio C Hamano
parent ba9ec78248
commit 0cd8f12b23
2 changed files with 27 additions and 9 deletions

View File

@@ -161,17 +161,16 @@ struct hashfile *hashfd_check(const struct git_hash_algo *algop,
return f;
}
static struct hashfile *hashfd_internal(const struct git_hash_algo *algop,
int fd, const char *name,
struct progress *tp,
size_t buffer_len)
struct hashfile *hashfd_ext(const struct git_hash_algo *algop,
int fd, const char *name,
const struct hashfd_options *opts)
{
struct hashfile *f = xmalloc(sizeof(*f));
f->fd = fd;
f->check_fd = -1;
f->offset = 0;
f->total = 0;
f->tp = tp;
f->tp = opts->progress;
f->name = name;
f->do_crc = 0;
f->skip_hash = 0;
@@ -179,8 +178,8 @@ static struct hashfile *hashfd_internal(const struct git_hash_algo *algop,
f->algop = unsafe_hash_algo(algop);
f->algop->init_fn(&f->ctx);
f->buffer_len = buffer_len;
f->buffer = xmalloc(buffer_len);
f->buffer_len = opts->buffer_len ? opts->buffer_len : 128 * 1024;
f->buffer = xmalloc(f->buffer_len);
f->check_buffer = NULL;
return f;
@@ -194,7 +193,8 @@ struct hashfile *hashfd(const struct git_hash_algo *algop,
* measure the rate of data passing through this hashfile,
* use a larger buffer size to reduce fsync() calls.
*/
return hashfd_internal(algop, fd, name, NULL, 128 * 1024);
struct hashfd_options opts = { 0 };
return hashfd_ext(algop, fd, name, &opts);
}
struct hashfile *hashfd_throughput(const struct git_hash_algo *algop,
@@ -206,7 +206,11 @@ struct hashfile *hashfd_throughput(const struct git_hash_algo *algop,
* size so the progress indicators arrive at a more
* frequent rate.
*/
return hashfd_internal(algop, fd, name, tp, 8 * 1024);
struct hashfd_options opts = {
.progress = tp,
.buffer_len = 8 * 1024,
};
return hashfd_ext(algop, fd, name, &opts);
}
void hashfile_checkpoint_init(struct hashfile *f,

View File

@@ -45,6 +45,20 @@ int hashfile_truncate(struct hashfile *, struct hashfile_checkpoint *);
#define CSUM_FSYNC 2
#define CSUM_HASH_IN_STREAM 4
struct hashfd_options {
/*
* Throughput progress that counts the number of bytes that have been
* hashed.
*/
struct progress *progress;
/* The length of the buffer that shall be used read read data. */
size_t buffer_len;
};
struct hashfile *hashfd_ext(const struct git_hash_algo *algop,
int fd, const char *name,
const struct hashfd_options *opts);
struct hashfile *hashfd(const struct git_hash_algo *algop,
int fd, const char *name);
struct hashfile *hashfd_check(const struct git_hash_algo *algop,