]> git.cameronkatri.com Git - cgit.git/blobdiff - scan-tree.c
ui-repolist: fix resource leak: free allocation from cgit_currenturl
[cgit.git] / scan-tree.c
index 1a2ea87e5008afe396df231114fabb59df8ce1b2..b5a10ffa5cf491c6ec811413740db20ad0dfb583 100644 (file)
@@ -45,8 +45,8 @@ out:
        return result;
 }
 
-struct cgit_repo *repo;
-repo_config_fn config_fn;
+static struct cgit_repo *repo;
+static repo_config_fn config_fn;
 
 static void repo_config(const char *name, const char *value)
 {
@@ -61,7 +61,7 @@ static int gitconfig_config(const char *key, const char *value, void *cb)
                config_fn(repo, "desc", value);
        else if (!strcmp(key, "gitweb.category"))
                config_fn(repo, "section", value);
-       else if (!prefixcmp(key, "cgit."))
+       else if (starts_with(key, "cgit."))
                config_fn(repo, key + 5, value);
 
        return 0;
@@ -105,7 +105,7 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn)
                return;
        strbuf_setlen(path, pathlen);
 
-       if (strncmp(base, path->buf, strlen(base)))
+       if (!starts_with(path->buf, base))
                strbuf_addbuf(&rel, path);
        else
                strbuf_addstr(&rel, path->buf + strlen(base) + 1);
@@ -123,9 +123,12 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn)
                strbuf_setlen(path, pathlen);
        }
 
-       if (ctx.cfg.remove_suffix)
-               if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git"))
-                       *p = '\0';
+       if (ctx.cfg.remove_suffix) {
+               size_t urllen;
+               strip_suffix(repo->url, ".git", &urllen);
+               strip_suffix_mem(repo->url, &urllen, "/");
+               repo->url[urllen] = '\0';
+       }
        repo->path = xstrdup(path->buf);
        while (!repo->owner) {
                if ((pwd = getpwuid(st.st_uid)) == NULL) {
@@ -161,7 +164,7 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn)
                        *slash = '\0';
                        repo->section = xstrdup(rel.buf);
                        *slash = '/';
-                       if (!prefixcmp(repo->name, repo->section)) {
+                       if (starts_with(repo->name, repo->section)) {
                                repo->name += strlen(repo->section);
                                if (*repo->name == '/')
                                        repo->name++;
@@ -171,7 +174,7 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn)
 
        strbuf_addstr(path, "cgitrc");
        if (!stat(path->buf, &st))
-               parse_configfile(xstrdup(path->buf), &repo_config);
+               parse_configfile(path->buf, &repo_config);
 
        strbuf_release(&rel);
 }