upload-pack: Use finish_{command,async}() instead of waitpid().
commit4c324c00501c2da41987498f8c966b022306b244
authorJohannes Sixt <johannes.sixt@telecom.at>
Sun, 4 Nov 2007 19:46:48 +0000 (4 20:46 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 6 Nov 2007 06:47:28 +0000 (5 22:47 -0800)
treeb9879484a7aa71bf54fcbc41377525ef4b855919
parentfe61935007b6803ce116e233316e4ff51de02be6
upload-pack: Use finish_{command,async}() instead of waitpid().

upload-pack spawns two processes, rev-list and pack-objects, and carefully
monitors their status so that it can report failure to the remote end.
This change removes the complicated procedures on the grounds of the
following observations:

- If everything is OK, rev-list closes its output pipe end, upon which
  pack-objects (which reads from the pipe) sees EOF and terminates itself,
  closing its output (and error) pipes. upload-pack reads from both until
  it sees EOF in both. It collects the exit codes of the child processes
  (which indicate success) and terminates successfully.

- If rev-list sees an error, it closes its output and terminates with
  failure. pack-objects sees EOF in its input and terminates successfully.
  Again upload-pack reads its inputs until EOF. When it now collects
  the exit codes of its child processes, it notices the failure of rev-list
  and signals failure to the remote end.

- If pack-objects sees an error, it terminates with failure. Since this
  breaks the pipe to rev-list, rev-list is killed with SIGPIPE.
  upload-pack reads its input until EOF, then collects the exit codes of
  the child processes, notices their failures, and signals failure to the
  remote end.

- If upload-pack itself dies unexpectedly, pack-objects is killed with
  SIGPIPE, and subsequently also rev-list.

The upshot of this is that precise monitoring of child processes is not
required because both terminate if either one of them dies unexpectedly.
This allows us to use finish_command() and finish_async() instead of
an explicit waitpid(2) call.

The change is smaller than it looks because most of it only reduces the
indentation of a large part of the inner loop.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5530-upload-pack-error.sh [new file with mode: 0755]
upload-pack.c