Skip to content

Commit 5ace994

Browse files
rctaygitster
authored andcommitted
http: create function end_url_with_slash
The logic to append a slash to the url if necessary in quote_ref_url (added in 113106e "http.c: use strbuf API in quote_ref_url") has been moved to a new function, end_url_with_slash. The method takes a strbuf, the URL, and the path to be appended to the URL. It first adds the URL to the strbuf. It then appends a slash if the URL does not end with a slash. The check on ref in quote_ref_url for a slash at the beginning has been removed as a result of using end_url_with_slash. This check is not needed, because slashes will be quoted anyway. Signed-off-by: Tay Ray Chuan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e917674 commit 5ace994

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

http.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ void finish_all_active_slots(void)
620620
}
621621
}
622622

623+
/* Helpers for modifying and creating URLs */
623624
static inline int needs_quote(int ch)
624625
{
625626
if (((ch >= 'A') && (ch <= 'Z'))
@@ -640,15 +641,20 @@ static inline int hex(int v)
640641
return 'A' + v - 10;
641642
}
642643

644+
static void end_url_with_slash(struct strbuf *buf, const char *url)
645+
{
646+
strbuf_addstr(buf, url);
647+
if (buf->len && buf->buf[buf->len - 1] != '/')
648+
strbuf_addstr(buf, "/");
649+
}
650+
643651
static char *quote_ref_url(const char *base, const char *ref)
644652
{
645653
struct strbuf buf = STRBUF_INIT;
646654
const char *cp;
647655
int ch;
648656

649-
strbuf_addstr(&buf, base);
650-
if (buf.len && buf.buf[buf.len - 1] != '/' && *ref != '/')
651-
strbuf_addstr(&buf, "/");
657+
end_url_with_slash(&buf, base);
652658

653659
for (cp = ref; (ch = *cp) != 0; cp++)
654660
if (needs_quote(ch))

0 commit comments

Comments
 (0)