]> git.ipfire.org Git - thirdparty/git.git/commit
send-pack: use buffered I/O to talk to pack-objects
authorJeff King <peff@peff.net>
Wed, 8 Jun 2016 19:42:16 +0000 (15:42 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 8 Jun 2016 23:02:40 +0000 (16:02 -0700)
commitf0bca72dc77f62d61fc355bd6fe6e32b194950b8
tree589fd55dff9a6068d5785ffd17de2d13110c94fa
parent0b65a8dbdb38962e700ee16776a3042beb489060
send-pack: use buffered I/O to talk to pack-objects

We start a pack-objects process and then write all of the
positive and negative sha1s to it over a pipe. We do so by
formatting each item into a fixed-size buffer and then
writing each individually. This has two drawbacks:

  1. There's some manual computation of the buffer size,
     which is not immediately obvious is correct (though it
     is).

  2. We write() once per sha1, which means a lot more system
     calls than are necessary.

We can solve both by wrapping the pipe descriptor in a stdio
handle; this is the same technique used by upload-pack when
serving fetches.

Note that we can also simplify and improve the error
handling here. The original detected a single write error
and broke out of the loop (presumably to avoid writing the
error message over and over), but never actually acted on
seeing an error; we just fed truncated input and took
whatever pack-objects returned.

In practice, this probably didn't matter, as the likely
errors would be caused by pack-objects dying (and we'd
probably just die with SIGPIPE anyway). But we can easily
make this simpler and more robust; the stdio handle keeps an
error flag, which we can check at the end.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
send-pack.c