http.c: use strbuf API in quote_ref_url
In addition, ''quote_ref_url'' inserts a slash between the base URL and remote ref path only if needed. Previously, this insertion wasn't contingent on the lack of a separating slash. Signed-off-by: Tay Ray Chuan <rctay89@gmail.com> Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
fd13b21f52
commit
113106e06c
30
http.c
30
http.c
@ -573,31 +573,21 @@ static inline int hex(int v)
|
|||||||
|
|
||||||
static char *quote_ref_url(const char *base, const char *ref)
|
static char *quote_ref_url(const char *base, const char *ref)
|
||||||
{
|
{
|
||||||
|
struct strbuf buf = STRBUF_INIT;
|
||||||
const char *cp;
|
const char *cp;
|
||||||
char *dp, *qref;
|
int ch;
|
||||||
int len, baselen, ch;
|
|
||||||
|
|
||||||
baselen = strlen(base);
|
strbuf_addstr(&buf, base);
|
||||||
len = baselen + 2; /* '/' after base and terminating NUL */
|
if (buf.len && buf.buf[buf.len - 1] != '/' && *ref != '/')
|
||||||
for (cp = ref; (ch = *cp) != 0; cp++, len++)
|
strbuf_addstr(&buf, "/");
|
||||||
|
|
||||||
|
for (cp = ref; (ch = *cp) != 0; cp++)
|
||||||
if (needs_quote(ch))
|
if (needs_quote(ch))
|
||||||
len += 2; /* extra two hex plus replacement % */
|
strbuf_addf(&buf, "%%%02x", ch);
|
||||||
qref = xmalloc(len);
|
|
||||||
memcpy(qref, base, baselen);
|
|
||||||
dp = qref + baselen;
|
|
||||||
*(dp++) = '/';
|
|
||||||
for (cp = ref; (ch = *cp) != 0; cp++) {
|
|
||||||
if (needs_quote(ch)) {
|
|
||||||
*dp++ = '%';
|
|
||||||
*dp++ = hex((ch >> 4) & 0xF);
|
|
||||||
*dp++ = hex(ch & 0xF);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
*dp++ = ch;
|
strbuf_addch(&buf, *cp);
|
||||||
}
|
|
||||||
*dp = 0;
|
|
||||||
|
|
||||||
return qref;
|
return strbuf_detach(&buf, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int http_fetch_ref(const char *base, struct ref *ref)
|
int http_fetch_ref(const char *base, struct ref *ref)
|
||||||
|
Loading…
Reference in New Issue
Block a user