]> git.ipfire.org Git - thirdparty/git.git/commit - fetch-pack.c
fetch-pack: make unexpected peek result non-fatal
authorJonathan Tan <jonathantanmy@google.com>
Mon, 16 May 2022 11:02:20 +0000 (04:02 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 May 2022 16:11:12 +0000 (09:11 -0700)
commit7709acf7beca41be2e382eb0e6c13b5003a20c1a
treeab465b8bed2b50c3cb7feeb01223fcde3a57ecd7
parentd516b2db0af2221bd6b13e7347abdcb5830b2829
fetch-pack: make unexpected peek result non-fatal

When a Git server responds to a fetch request, it may send optional
sections before the packfile section. To handle this, the Git client
calls packet_reader_peek() (see process_section_header()) in order to
see what's next without consuming the line.

However, as implemented, Git errors out whenever what's peeked is not an
ordinary line. This is not only unexpected (here, we only need to know
whether the upcoming line is the section header we want) but causes
errors to include the name of a section header that is irrelevant to the
cause of the error. For example, at $DAYJOB, we have seen "fatal: error
reading section header 'shallow-info'" error messages when none of the
repositories involved are shallow.

Therefore, fix this so that the peek returns 1 if the upcoming line is
the wanted section header and nothing else. Because of this change,
reader->line may now be NULL later in the function, so update the error
message printing code accordingly.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
fetch-pack.c