aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2026-03-13 07:45:19 +0100
committerJunio C Hamano <gitster@pobox.com>2026-03-13 08:54:15 -0700
commita1118c0a44606e0b71e515b05112ff38fef989c0 (patch)
tree96c80068cd2d0bc20628ade01261d5a531ed2d28
parent26986f4cbaf38d84a82b0b35da211389ce49552c (diff)
downloadgit-a1118c0a44606e0b71e515b05112ff38fef989c0.tar.xz
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>
-rw-r--r--csum-file.c22
-rw-r--r--csum-file.h14
2 files changed, 27 insertions, 9 deletions
diff --git a/csum-file.c b/csum-file.c
index 6e21e3cac8..a50416247e 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -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,
diff --git a/csum-file.h b/csum-file.h
index 07ae11024a..a03b60120d 100644
--- a/csum-file.h
+++ b/csum-file.h
@@ -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,