Skip to content

Commit 986d7f4

Browse files
peffgitster
authored andcommitted
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>
1 parent 0202c41 commit 986d7f4

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

http.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ static int update_url_from_redirect(struct strbuf *base,
15001500
const struct strbuf *got)
15011501
{
15021502
const char *tail;
1503-
size_t tail_len;
1503+
size_t new_len;
15041504

15051505
if (!strcmp(asked, got->buf))
15061506
return 0;
@@ -1509,14 +1509,12 @@ static int update_url_from_redirect(struct strbuf *base,
15091509
die("BUG: update_url_from_redirect: %s is not a superset of %s",
15101510
asked, base->buf);
15111511

1512-
tail_len = strlen(tail);
1513-
1514-
if (got->len < tail_len ||
1515-
strcmp(tail, got->buf + got->len - tail_len))
1512+
new_len = got->len;
1513+
if (!strip_suffix_mem(got->buf, &new_len, tail))
15161514
return 0; /* insane redirect scheme */
15171515

15181516
strbuf_reset(base);
1519-
strbuf_add(base, got->buf, got->len - tail_len);
1517+
strbuf_add(base, got->buf, new_len);
15201518
return 1;
15211519
}
15221520

0 commit comments

Comments
 (0)