int write_packetized_from_fd(int fd_in, int fd_out) { static char buf[LARGE_PACKET_DATA_MAX]; int err = 0; ssize_t bytes_to_write; while (!err) { bytes_to_write = xread(fd_in, buf, sizeof(buf)); if (bytes_to_write < 0) return COPY_READ_ERROR; if (bytes_to_write == 0) break; err = packet_write_gently(fd_out, buf, bytes_to_write); } if (!err) err = packet_flush_gently(fd_out); return err; }
int write_packetized_from_buf(const char *src_in, size_t len, int fd_out) { int err = 0; size_t bytes_written = 0; size_t bytes_to_write; while (!err) { if ((len - bytes_written) > LARGE_PACKET_DATA_MAX) bytes_to_write = LARGE_PACKET_DATA_MAX; else bytes_to_write = len - bytes_written; if (bytes_to_write == 0) break; err = packet_write_gently(fd_out, src_in + bytes_written, bytes_to_write); bytes_written += bytes_to_write; } if (!err) err = packet_flush_gently(fd_out); return err; }
/* * Print changed/unmerged items. * We write raw (not c-quoted) pathname(s). The rename_source is only * set when status computed a rename/copy. * * We ALWAYS write a final LF to the packet-line (for debugging) * even though Linux pathnames allow LFs. */ static inline void wt_serialize_v1_changed(struct wt_status *s, int fd, struct string_list_item *item) { struct wt_status_change_data *d = item->util; struct wt_status_serialize_data sd; char *begin; char *end; char *p; int len_path, len_rename_source; trace_printf_key(&trace_serialize, "change: %d %d %d %d %o %o %o %d %d %s %s '%s' '%s'", d->worktree_status, d->index_status, d->stagemask, d->rename_score, d->mode_head, d->mode_index, d->mode_worktree, d->dirty_submodule, d->new_submodule_commits, oid_to_hex(&d->oid_head), oid_to_hex(&d->oid_index), item->string, (d->rename_source ? d->rename_source : "")); sd.fixed.worktree_status = htonl(d->worktree_status); sd.fixed.index_status = htonl(d->index_status); sd.fixed.stagemask = htonl(d->stagemask); sd.fixed.rename_score = htonl(d->rename_score); sd.fixed.mode_head = htonl(d->mode_head); sd.fixed.mode_index = htonl(d->mode_index); sd.fixed.mode_worktree = htonl(d->mode_worktree); sd.fixed.dirty_submodule = htonl(d->dirty_submodule); sd.fixed.new_submodule_commits = htonl(d->new_submodule_commits); oidcpy(&sd.fixed.oid_head, &d->oid_head); oidcpy(&sd.fixed.oid_index, &d->oid_index); begin = (char *)&sd; end = begin + sizeof(sd); p = sd.variant; /* * Write <path> NUL [<rename_source>] NUL LF at the end of the buffer. */ len_path = strlen(item->string); len_rename_source = d->rename_source ? strlen(d->rename_source) : 0; /* * This is a bit of a hack, but I don't want to split the * status detail record across multiple pkt-lines. */ if (p + len_path + 1 + len_rename_source + 1 + 1 >= end) BUG("path to long to serialize '%s'", item->string); memcpy(p, item->string, len_path); p += len_path; *p++ = '\0'; if (len_rename_source) { memcpy(p, d->rename_source, len_rename_source); p += len_rename_source; } *p++ = '\0'; *p++ = '\n'; if (packet_write_gently(fd, begin, (p - begin))) BUG("cannot serialize '%s'", item->string); }