summaryrefslogtreecommitdiff
path: root/http.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-12-06 13:24:29 -0500
committerJunio C Hamano <gitster@pobox.com>2016-12-06 12:32:48 -0800
commit986d7f4d37124e1ab7dcc99587f0d6d1deeedd9c (patch)
treea3249c45837e57d317bb2ad1a3e7eaff5cabf090 /http.c
parent0202c411edc25940cc381bf317badcdf67670be4 (diff)
downloadgit-986d7f4d37124e1ab7dcc99587f0d6d1deeedd9c.tar.gz
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>
Diffstat (limited to 'http.c')
-rw-r--r--http.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/http.c b/http.c
index d8e427b69b..d4034a14ba 100644
--- a/http.c
+++ b/http.c
@@ -1500,7 +1500,7 @@ static int update_url_from_redirect(struct strbuf *base,
const struct strbuf *got)
{
const char *tail;
- size_t tail_len;
+ size_t new_len;
if (!strcmp(asked, got->buf))
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",
asked, base->buf);
- tail_len = strlen(tail);
-
- if (got->len < tail_len ||
- strcmp(tail, got->buf + got->len - tail_len))
+ new_len = got->len;
+ if (!strip_suffix_mem(got->buf, &new_len, tail))
return 0; /* insane redirect scheme */
strbuf_reset(base);
- strbuf_add(base, got->buf, got->len - tail_len);
+ strbuf_add(base, got->buf, new_len);
return 1;
}