Skip to content

Commit fa6c383

Browse files
committed
unpack: replace xwrite() loop with write_in_full()
We have two packfile stream consumers, index-pack and unpack-objects, that allow excess payload after the packfile stream data. Their code to relay excess data hasn't changed significantly since their original implementation that appeared in 67e5a5e (git-unpack-objects: re-write to read from stdin, 2005-06-28) and 9bee247 (mimic unpack-objects when --stdin is used with index-pack, 2006-10-25). These code blocks contain hand-rolled loops using xwrite(), written before our write_in_full() helper existed. This helper now provides the same functionality. Replace these loops with write_in_full() for shorter, clearer code. Update related variables accordingly. Signed-off-by: Junio C Hamano <[email protected]>
1 parent b387623 commit fa6c383

File tree

2 files changed

+4
-21
lines changed

2 files changed

+4
-21
lines changed

builtin/index-pack.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,14 +1524,12 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
15241524
struct strbuf pack_name = STRBUF_INIT;
15251525
struct strbuf index_name = STRBUF_INIT;
15261526
struct strbuf rev_index_name = STRBUF_INIT;
1527-
int err;
15281527

15291528
if (!from_stdin) {
15301529
close(input_fd);
15311530
} else {
15321531
fsync_component_or_die(FSYNC_COMPONENT_PACK, output_fd, curr_pack_name);
1533-
err = close(output_fd);
1534-
if (err)
1532+
if (close(output_fd))
15351533
die_errno(_("error while closing pack file"));
15361534
}
15371535

@@ -1566,17 +1564,8 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
15661564
write_or_die(1, buf.buf, buf.len);
15671565
strbuf_release(&buf);
15681566

1569-
/*
1570-
* Let's just mimic git-unpack-objects here and write
1571-
* the last part of the input buffer to stdout.
1572-
*/
1573-
while (input_len) {
1574-
err = xwrite(1, input_buffer + input_offset, input_len);
1575-
if (err <= 0)
1576-
break;
1577-
input_len -= err;
1578-
input_offset += err;
1579-
}
1567+
/* Write the last part of the buffer to stdout */
1568+
write_in_full(1, input_buffer + input_offset, input_len);
15801569
}
15811570

15821571
strbuf_release(&rev_index_name);

builtin/unpack-objects.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -679,13 +679,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
679679
use(the_hash_algo->rawsz);
680680

681681
/* Write the last part of the buffer to stdout */
682-
while (len) {
683-
int ret = xwrite(1, buffer + offset, len);
684-
if (ret <= 0)
685-
break;
686-
len -= ret;
687-
offset += ret;
688-
}
682+
write_in_full(1, buffer + offset, len);
689683

690684
/* All done */
691685
return has_errors;

0 commit comments

Comments
 (0)