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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Feb 18, 2025 at 10:20 UTC cb3e368b6913a2446f245e7ae7a7e4ae4a2e6794
1 file changed +14 -4
reftable/stack.c
+14 -4
@@ -115,13 +115,16 @@ out:
115
116 static int fd_read_lines(int fd, char ***namesp)
117 {
118 - off_t size = lseek(fd, 0, SEEK_END);
118 char *buf = NULL;
119 int err = 0;
120 + off_t size;
121 +
122 + size = lseek(fd, 0, SEEK_END);
123 if (size < 0) {
124 err = REFTABLE_IO_ERROR;
125 goto done;
126 }
127 +
128 err = lseek(fd, 0, SEEK_SET);
129 if (err < 0) {
130 err = REFTABLE_IO_ERROR;
@@ -134,9 +137,16 @@ static int fd_read_lines(int fd, char ***namesp)
137 goto done;
138 }
139
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;
150 }
151 buf[size] = 0;
152