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>
Jeff King committed
Dec 6, 2016 at 13:24 UTC
986d7f4d37124e1ab7dcc99587f0d6d1deeedd9c
1 file changed
+4
-6
http.c
+4
-6
@@ -1500,7 +1500,7 @@ static int update_url_from_redirect(struct strbuf *base,
1500
const struct strbuf *got)
1501
{
1502
const char *tail;
1503
- size_t tail_len;
1503
+ size_t new_len;
1504
1505
if (!strcmp(asked, got->buf))
1506
return 0;
@@ -1509,14 +1509,12 @@ static int update_url_from_redirect(struct strbuf *base,
1509
die("BUG: update_url_from_redirect: %s is not a superset of %s",
1510
asked, base->buf);
1511
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))
1514
return 0; /* insane redirect scheme */
1515
1516
strbuf_reset(base);
1519
- strbuf_add(base, got->buf, got->len - tail_len);
1517
+ strbuf_add(base, got->buf, new_len);
1518
return 1;
1519
}
1520