pkt-line: introduce packet_read_with_status
commit2153d478b74cfef58ee49ee0305cccf5e8a77b4f
authorBrandon Williams <bmwill@google.com>
Wed, 14 Mar 2018 18:31:38 +0000 (14 11:31 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Mar 2018 21:15:05 +0000 (14 14:15 -0700)
treeb389bd313f1de7152effc87cb4573999094eb253
parent1eaabe34fc6f486367a176207420378f587d3b48
pkt-line: introduce packet_read_with_status

The current pkt-line API encodes the status of a pkt-line read in the
length of the read content.  An error is indicated with '-1', a flush
with '0' (which can be confusing since a return value of '0' can also
indicate an empty pkt-line), and a positive integer for the length of
the read content otherwise.  This doesn't leave much room for allowing
the addition of additional special packets in the future.

To solve this introduce 'packet_read_with_status()' which reads a packet
and returns the status of the read encoded as an 'enum packet_status'
type.  This allows for easily identifying between special and normal
packets as well as errors.  It also enables easily adding a new special
packet in the future.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pkt-line.c
pkt-line.h