Diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Trim trailing slashes with git's strbuf helper
-rw-r--r--source/ui-shared.c16
1 file changed, 4 insertions, 12 deletions
diff --git a/source/ui-shared.c b/source/ui-shared.c
index c658435..1cf53d4 100644
--- a/source/ui-shared.c
+++ b/source/ui-shared.c
@@ -1028,13 +1028,6 @@ static const struct object_id *page_treeish(void)
return state > 0 ? &oid : NULL;
}
-static void strip_git_suffix(struct strbuf *sb)
-{
- while (sb->len && sb->buf[sb->len - 1] == '/')
- strbuf_setlen(sb, sb->len - 1);
- strbuf_strip_suffix(sb, ".git");
-}
-
/*
* Reduces a submodule url to the path it names on its host, so the tail can
* be compared against the urls this instance serves. A relative url points
@@ -1071,7 +1064,8 @@ static char *submodule_url_path(const char *url)
strbuf_addstr(&sb, url);
}
- strip_git_suffix(&sb);
+ strbuf_trim_trailing_dir_sep(&sb);
+ strbuf_strip_suffix(&sb, ".git");
while (sb.len && sb.buf[0] == '/')
strbuf_remove(&sb, 0, 1);
if (!sb.len) {
@@ -1182,8 +1176,7 @@ static void gitmodules_link(const char *path, const char *rev, char **module,
forge = forge_for_host(rest, strcspn(rest, "/"));
if (forge) {
strbuf_addstr(&sb, url);
- while (sb.len && sb.buf[sb.len - 1] == '/')
- strbuf_setlen(&sb, sb.len - 1);
+ strbuf_trim_trailing_dir_sep(&sb);
if (!forge->keep_dot_git)
strbuf_strip_suffix(&sb, ".git");
strbuf_addstr(&sb, forge->commit_seg);
@@ -1205,8 +1198,7 @@ static void gitmodules_link(const char *path, const char *rev, char **module,
while (*rest == '/')
rest++;
strbuf_addf(&sb, "https://%.*s/%s", (int)(colon - host), host, rest);
- while (sb.len && sb.buf[sb.len - 1] == '/')
- strbuf_setlen(&sb, sb.len - 1);
+ strbuf_trim_trailing_dir_sep(&sb);
if (!forge->keep_dot_git)
strbuf_strip_suffix(&sb, ".git");
*module = xstrdup(sb.buf);