Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2022-05-16 14:02:20 +0300
committerJunio C Hamano <gitster@pobox.com>2022-05-16 19:11:12 +0300
commit7709acf7beca41be2e382eb0e6c13b5003a20c1a (patch)
treeab465b8bed2b50c3cb7feeb01223fcde3a57ecd7 /fetch-pack.c
parentd516b2db0af2221bd6b13e7347abdcb5830b2829 (diff)
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>
Diffstat (limited to 'fetch-pack.c')
-rw-r--r--fetch-pack.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/fetch-pack.c b/fetch-pack.c
index dd6ec449f2..948146b684 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -1357,17 +1357,20 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
static int process_section_header(struct packet_reader *reader,
const char *section, int peek)
{
- int ret;
-
- if (packet_reader_peek(reader) != PACKET_READ_NORMAL)
- die(_("error reading section header '%s'"), section);
+ int ret = 0;
- ret = !strcmp(reader->line, section);
+ if (packet_reader_peek(reader) == PACKET_READ_NORMAL &&
+ !strcmp(reader->line, section))
+ ret = 1;
if (!peek) {
- if (!ret)
- die(_("expected '%s', received '%s'"),
- section, reader->line);
+ if (!ret) {
+ if (reader->line)
+ die(_("expected '%s', received '%s'"),
+ section, reader->line);
+ else
+ die(_("expected '%s'"), section);
+ }
packet_reader_read(reader);
}