Skip to content

Commit a1118c0

Browse files
pks-tgitster
authored andcommitted
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>
1 parent 26986f4 commit a1118c0

2 files changed

Lines changed: 27 additions & 9 deletions

File tree

csum-file.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,26 +161,25 @@ struct hashfile *hashfd_check(const struct git_hash_algo *algop,
161161
return f;
162162
}
163163

164-
static struct hashfile *hashfd_internal(const struct git_hash_algo *algop,
165-
int fd, const char *name,
166-
struct progress *tp,
167-
size_t buffer_len)
164+
struct hashfile *hashfd_ext(const struct git_hash_algo *algop,
165+
int fd, const char *name,
166+
const struct hashfd_options *opts)
168167
{
169168
struct hashfile *f = xmalloc(sizeof(*f));
170169
f->fd = fd;
171170
f->check_fd = -1;
172171
f->offset = 0;
173172
f->total = 0;
174-
f->tp = tp;
173+
f->tp = opts->progress;
175174
f->name = name;
176175
f->do_crc = 0;
177176
f->skip_hash = 0;
178177

179178
f->algop = unsafe_hash_algo(algop);
180179
f->algop->init_fn(&f->ctx);
181180

182-
f->buffer_len = buffer_len;
183-
f->buffer = xmalloc(buffer_len);
181+
f->buffer_len = opts->buffer_len ? opts->buffer_len : 128 * 1024;
182+
f->buffer = xmalloc(f->buffer_len);
184183
f->check_buffer = NULL;
185184

186185
return f;
@@ -194,7 +193,8 @@ struct hashfile *hashfd(const struct git_hash_algo *algop,
194193
* measure the rate of data passing through this hashfile,
195194
* use a larger buffer size to reduce fsync() calls.
196195
*/
197-
return hashfd_internal(algop, fd, name, NULL, 128 * 1024);
196+
struct hashfd_options opts = { 0 };
197+
return hashfd_ext(algop, fd, name, &opts);
198198
}
199199

200200
struct hashfile *hashfd_throughput(const struct git_hash_algo *algop,
@@ -206,7 +206,11 @@ struct hashfile *hashfd_throughput(const struct git_hash_algo *algop,
206206
* size so the progress indicators arrive at a more
207207
* frequent rate.
208208
*/
209-
return hashfd_internal(algop, fd, name, tp, 8 * 1024);
209+
struct hashfd_options opts = {
210+
.progress = tp,
211+
.buffer_len = 8 * 1024,
212+
};
213+
return hashfd_ext(algop, fd, name, &opts);
210214
}
211215

212216
void hashfile_checkpoint_init(struct hashfile *f,

csum-file.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ int hashfile_truncate(struct hashfile *, struct hashfile_checkpoint *);
4545
#define CSUM_FSYNC 2
4646
#define CSUM_HASH_IN_STREAM 4
4747

48+
struct hashfd_options {
49+
/*
50+
* Throughput progress that counts the number of bytes that have been
51+
* hashed.
52+
*/
53+
struct progress *progress;
54+
55+
/* The length of the buffer that shall be used read read data. */
56+
size_t buffer_len;
57+
};
58+
59+
struct hashfile *hashfd_ext(const struct git_hash_algo *algop,
60+
int fd, const char *name,
61+
const struct hashfd_options *opts);
4862
struct hashfile *hashfd(const struct git_hash_algo *algop,
4963
int fd, const char *name);
5064
struct hashfile *hashfd_check(const struct git_hash_algo *algop,

0 commit comments

Comments
 (0)