http: simplify update_url_from_redirect
This function looks for a common tail between what we asked for and where we were redirected to, but it open-codes the comparison. We can avoid some confusing subtractions by using strip_suffix_mem(). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
0202c411ed
commit
986d7f4d37
10
http.c
10
http.c
|
@ -1500,7 +1500,7 @@ static int update_url_from_redirect(struct strbuf *base,
|
||||||
const struct strbuf *got)
|
const struct strbuf *got)
|
||||||
{
|
{
|
||||||
const char *tail;
|
const char *tail;
|
||||||
size_t tail_len;
|
size_t new_len;
|
||||||
|
|
||||||
if (!strcmp(asked, got->buf))
|
if (!strcmp(asked, got->buf))
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1509,14 +1509,12 @@ static int update_url_from_redirect(struct strbuf *base,
|
||||||
die("BUG: update_url_from_redirect: %s is not a superset of %s",
|
die("BUG: update_url_from_redirect: %s is not a superset of %s",
|
||||||
asked, base->buf);
|
asked, base->buf);
|
||||||
|
|
||||||
tail_len = strlen(tail);
|
new_len = got->len;
|
||||||
|
if (!strip_suffix_mem(got->buf, &new_len, tail))
|
||||||
if (got->len < tail_len ||
|
|
||||||
strcmp(tail, got->buf + got->len - tail_len))
|
|
||||||
return 0; /* insane redirect scheme */
|
return 0; /* insane redirect scheme */
|
||||||
|
|
||||||
strbuf_reset(base);
|
strbuf_reset(base);
|
||||||
strbuf_add(base, got->buf, got->len - tail_len);
|
strbuf_add(base, got->buf, new_len);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue