Skip to content

Commit cb3e368

Browse files
pks-tgitster
authored andcommitted
reftable/stack: stop using read_in_full()
There is a single callsite of `read_in_full()` in the reftable library. Open-code the function to reduce our dependency on the Git library. Note that we only partially port over the logic from `read_in_full()` and its underlying `xread()` helper. Most importantly, the latter also knows to handle `EWOULDBLOCK` via `handle_nonblock()`. This logic is irrelevant for us though because the reftable library never sets the `O_NONBLOCK` option in the first place. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0394451 commit cb3e368

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

reftable/stack.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,16 @@ int reftable_new_stack(struct reftable_stack **dest, const char *dir,
115115

116116
static int fd_read_lines(int fd, char ***namesp)
117117
{
118-
off_t size = lseek(fd, 0, SEEK_END);
119118
char *buf = NULL;
120119
int err = 0;
120+
off_t size;
121+
122+
size = lseek(fd, 0, SEEK_END);
121123
if (size < 0) {
122124
err = REFTABLE_IO_ERROR;
123125
goto done;
124126
}
127+
125128
err = lseek(fd, 0, SEEK_SET);
126129
if (err < 0) {
127130
err = REFTABLE_IO_ERROR;
@@ -134,9 +137,16 @@ static int fd_read_lines(int fd, char ***namesp)
134137
goto done;
135138
}
136139

137-
if (read_in_full(fd, buf, size) != size) {
138-
err = REFTABLE_IO_ERROR;
139-
goto done;
140+
for (off_t total_read = 0; total_read < size; ) {
141+
ssize_t bytes_read = read(fd, buf + total_read, size - total_read);
142+
if (bytes_read < 0 && (errno == EAGAIN || errno == EINTR))
143+
continue;
144+
if (bytes_read < 0 || !bytes_read) {
145+
err = REFTABLE_IO_ERROR;
146+
goto done;
147+
}
148+
149+
total_read += bytes_read;
140150
}
141151
buf[size] = 0;
142152

0 commit comments

Comments
 (0)