]> git.ipfire.org Git - thirdparty/git.git/commit - pkt-line.c
pkt-line: allow writing of LARGE_PACKET_MAX buffers
authorJeff King <peff@peff.net>
Wed, 10 Dec 2014 09:47:02 +0000 (04:47 -0500)
committerJunio C Hamano <gitster@pobox.com>
Wed, 10 Dec 2014 21:09:21 +0000 (13:09 -0800)
commit8e9faf27c11d515b2eef526f2a15c1c2a4ac8d4e
tree427de550a374b15eee32c18f87a34d745fbf7c3b
parentc18b86734113ee2aeb0e140c922c8fbd4accc860
pkt-line: allow writing of LARGE_PACKET_MAX buffers

When we send out pkt-lines with refnames, we use a static
1000-byte buffer. This means that the maximum size of a ref
over the git protocol is around 950 bytes (the exact size
depends on the protocol line being written, but figure on a sha1
plus some boilerplate).

This is enough for any sane workflow, but occasionally odd
things happen (e.g., a bug may create a ref "foo/foo/foo/..."
accidentally).  With the current code, you cannot even use
"push" to delete such a ref from a remote.

Let's switch to using a strbuf, with a hard-limit of
LARGE_PACKET_MAX (which is specified by the protocol).  This
matches the size of the readers, as of 74543a0 (pkt-line:
provide a LARGE_PACKET_MAX static buffer, 2013-02-20).
Versions of git older than that will complain about our
large packets, but it's really no worse than the current
behavior. Right now the sender barfs with "impossibly long
line" trying to send the packet, and afterwards the reader
will barf with "protocol error: bad line length %d", which
is arguably better anyway.

Note that we're not really _solving_ the problem here, but
just bumping the limits. In theory, the length of a ref is
unbounded, and pkt-line can only represent sizes up to
65531 bytes. So we are just bumping the limit, not removing
it.  But hopefully 64K should be enough for anyone.

As a bonus, by using a strbuf for the formatting we can
eliminate an unnecessary copy in format_buf_write.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pkt-line.c
t/t5527-fetch-odd-refs.sh