]> git.ipfire.org Git - thirdparty/git.git/commitdiff
reftable/stack: stop using `write_in_full()`
authorPatrick Steinhardt <ps@pks.im>
Tue, 18 Feb 2025 09:20:38 +0000 (10:20 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 18 Feb 2025 18:55:35 +0000 (10:55 -0800)
Similar to the preceding commit, drop our use of `write_in_full()` and
implement a new wrapper `reftable_write_full()` that handles this logic
for us. This is done to reduce our dependency on the Git library.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
reftable/stack.c

index 1cc47b94d9c89e396c0c6ce66629e99ebf1fac4b..c33f0c3333accd05a9d1ca11079b74d5b63daafc 100644 (file)
@@ -48,6 +48,25 @@ static int stack_fsync(const struct reftable_write_options *opts, int fd)
        return fsync(fd);
 }
 
+static ssize_t reftable_write_data(int fd, const void *data, size_t size)
+{
+       size_t total_written = 0;
+       const char *p = data;
+
+       while (total_written < size) {
+               ssize_t bytes_written = write(fd, p, size - total_written);
+               if (bytes_written < 0 && (errno == EAGAIN || errno == EINTR))
+                       continue;
+               if (bytes_written < 0)
+                       return REFTABLE_IO_ERROR;
+
+               total_written += bytes_written;
+               p += bytes_written;
+       }
+
+       return total_written;
+}
+
 struct fd_writer {
        const struct reftable_write_options *opts;
        int fd;
@@ -56,7 +75,7 @@ struct fd_writer {
 static ssize_t fd_writer_write(void *arg, const void *data, size_t sz)
 {
        struct fd_writer *writer = arg;
-       return write_in_full(writer->fd, data, sz);
+       return reftable_write_data(writer->fd, data, sz);
 }
 
 static int fd_writer_flush(void *arg)
@@ -784,7 +803,8 @@ int reftable_addition_commit(struct reftable_addition *add)
                        goto done;
        }
 
-       err = write_in_full(add->tables_list_lock.fd, table_list.buf, table_list.len);
+       err = reftable_write_data(add->tables_list_lock.fd,
+                                 table_list.buf, table_list.len);
        reftable_buf_release(&table_list);
        if (err < 0) {
                err = REFTABLE_IO_ERROR;
@@ -1470,8 +1490,8 @@ static int stack_compact_range(struct reftable_stack *st,
                        goto done;
        }
 
-       err = write_in_full(tables_list_lock.fd,
-                           tables_list_buf.buf, tables_list_buf.len);
+       err = reftable_write_data(tables_list_lock.fd,
+                                 tables_list_buf.buf, tables_list_buf.len);
        if (err < 0) {
                err = REFTABLE_IO_ERROR;
                unlink(new_table_path.buf);