diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--assets/cgit.css64
-rw-r--r--source/cache.c19
-rw-r--r--source/cache.h2
-rw-r--r--source/cgit.c118
-rw-r--r--source/cgit.h24
-rw-r--r--source/cmd.c13
-rw-r--r--source/filter.c18
-rw-r--r--source/html.c6
-rw-r--r--source/parsing.c2
-rw-r--r--source/scan-tree.c21
-rw-r--r--source/shared.c70
-rw-r--r--source/ui-blame.c11
-rw-r--r--source/ui-commit.c4
-rw-r--r--source/ui-diff.c12
-rw-r--r--source/ui-log.c8
-rw-r--r--source/ui-log.h2
-rw-r--r--source/ui-patch.c4
-rw-r--r--source/ui-plain.c10
-rw-r--r--source/ui-refs.c8
-rw-r--r--source/ui-repolist.c4
-rw-r--r--source/ui-shared.c68
-rw-r--r--source/ui-shared.h2
-rw-r--r--source/ui-snapshot.c2
-rw-r--r--source/ui-ssdiff.c10
-rw-r--r--source/ui-stats.c21
-rw-r--r--source/ui-summary.c4
-rw-r--r--source/ui-tree.c14
27 files changed, 260 insertions, 281 deletions
diff --git a/assets/cgit.css b/assets/cgit.css
index 235baa1..4b793cf 100644
--- a/assets/cgit.css
+++ b/assets/cgit.css
@@ -146,8 +146,7 @@ div#cgit table {
border-collapse: collapse;
}
-
-/* ---- Form controls ---------------------------------------------------- */
+/* Form controls */
div#cgit select,
div#cgit input,
@@ -198,8 +197,7 @@ div#cgit button:focus-visible {
outline-offset: 1px;
}
-
-/* ---- Masthead --------------------------------------------------------- */
+/* Masthead */
div#cgit #header {
display: grid;
@@ -256,9 +254,6 @@ div#cgit #header .theme-toggle svg {
stroke-linejoin: round;
}
-/* Reserve the logo column. The image carries no width attribute, since the
- * logo is configurable and its size is not known here, so without this the
- * column collapses to nothing and the masthead jumps sideways on load. */
/* The toggle starts hidden and is revealed once the script has run, so its
* column is reserved up front to keep the header from jumping. Only when
* scripting is on, otherwise the space would sit empty forever. */
@@ -327,8 +322,7 @@ div#cgit #header .owner {
text-align: right;
}
-
-/* ---- Tab bar ---------------------------------------------------------- */
+/* Tab bar */
div#cgit .tabs {
display: flex;
@@ -398,8 +392,7 @@ div#cgit input.txt {
max-width: 12em;
}
-
-/* ---- Page frame ------------------------------------------------------- */
+/* Page frame */
div#cgit .path {
margin: 0px;
@@ -416,8 +409,7 @@ div#cgit .content {
overflow-x: auto;
}
-
-/* ---- Listing tables --------------------------------------------------- */
+/* Listing tables */
div#cgit table.list {
width: 100%;
@@ -508,8 +500,7 @@ div#cgit table.list td a:hover {
color: var(--link);
}
-
-/* ---- Repository index ------------------------------------------------- */
+/* Repository index */
div#cgit div#summary {
vertical-align: top;
@@ -644,8 +635,7 @@ div#cgit table.list td.sublevel-repo {
padding-left: 1.5em;
}
-
-/* ---- Directory / blob listings --------------------------------------- */
+/* Directory / blob listings */
div#cgit a.ls-blob, div#cgit a.ls-dir, div#cgit .ls-mod {
font-family: var(--font-mono);
@@ -662,8 +652,7 @@ div#cgit td.ls-mode {
width: 10em;
}
-
-/* ---- Source blob ------------------------------------------------------ */
+/* Source blob */
div#cgit table.blob {
margin-top: 0.5em;
@@ -741,8 +730,7 @@ div#cgit .hl-number { color: light-dark(#0550ae, #79c0ff); }
div#cgit .hl-type { color: light-dark(#953800, #ffa657); }
div#cgit .hl-func { color: light-dark(#6639ba, #d2a8ff); }
-
-/* ---- Blame ------------------------------------------------------------ */
+/* Blame */
div#cgit table.blame {
display: block;
@@ -789,8 +777,7 @@ div#cgit table.blame .oid {
font-size: 100%;
}
-
-/* ---- Binary blob ------------------------------------------------------ */
+/* Binary blob */
div#cgit table.bin-blob {
margin-top: 0.5em;
@@ -815,8 +802,7 @@ div#cgit table.bin-blob td {
padding: 0em 1em;
}
-
-/* ---- Commit / tag ----------------------------------------------------- */
+/* Commit / tag */
div#cgit table.nowrap td {
white-space: nowrap;
@@ -900,8 +886,7 @@ div#cgit div.notes-footer {
clear: left;
}
-
-/* ---- Diffstat --------------------------------------------------------- */
+/* Diffstat */
div#cgit div.diffstat-header {
font-weight: bold;
@@ -978,8 +963,7 @@ div#cgit div.diffstat-summary {
padding-top: 0.5em;
}
-
-/* ---- Unified diff ----------------------------------------------------- */
+/* Unified diff */
div#cgit table.diff {
width: 100%;
@@ -1034,8 +1018,7 @@ div#cgit .right {
text-align: right;
}
-
-/* ---- Buttons / pager -------------------------------------------------- */
+/* Buttons / pager */
div#cgit a.button {
font-size: 90%;
@@ -1062,8 +1045,7 @@ div#cgit ul.pager .current {
font-weight: bold;
}
-
-/* ---- Ages / line counts ----------------------------------------------- */
+/* Ages / line counts */
div#cgit span.age-mins,
div#cgit span.age-hours,
@@ -1107,8 +1089,7 @@ div#cgit span.deletions {
color: var(--del);
}
-
-/* ---- Footer ----------------------------------------------------------- */
+/* Footer */
div#cgit .footer {
padding: 0.85rem var(--gutter);
@@ -1126,8 +1107,7 @@ div#cgit .footer a:hover {
text-decoration: underline;
}
-
-/* ---- Ref decorations -------------------------------------------------- */
+/* Ref decorations */
div#cgit a.branch-deco,
div#cgit a.tag-deco,
@@ -1191,8 +1171,7 @@ div#cgit div.commit-subject a.deco {
font-size: 80%;
}
-
-/* ---- Statistics ------------------------------------------------------- */
+/* Statistics */
div#cgit table.stats {
border: solid 1px var(--border-strong);
@@ -1230,8 +1209,7 @@ div#cgit table.stats td.left {
text-align: left;
}
-
-/* ---- Side-by-side diff ------------------------------------------------ */
+/* Side-by-side diff */
div#cgit table.ssdiff {
width: 100%;
@@ -1332,9 +1310,7 @@ div#cgit table.ssdiff td.space div {
min-height: 3em;
}
-
-/* ---- Responsive tiers --------------------------------------------------
- * Three tiers around the default layout. Wide screens get a roomier
+/* Three tiers around the default layout. Wide screens get a roomier
* gutter and a slightly larger base size, phones trade chrome for
* content, and the smallest phones tighten the masthead further. */
diff --git a/source/cache.c b/source/cache.c
index aff0f4d..105ecfe 100644
--- a/source/cache.c
+++ b/source/cache.c
@@ -21,6 +21,12 @@
#endif
#define CACHE_BUFSIZE (1024 * 4)
+/* Crude implementation of 32-bit FNV-1 hash algorithm,
+ * see http://www.isthe.com/chongo/tech/comp/fnv/ for details
+ * about the magic numbers.
+ */
+#define FNV_OFFSET 0x811c9dc5
+#define FNV_PRIME 0x01000193
struct cache_slot {
const char *key;
@@ -63,7 +69,7 @@ static int open_slot(struct cache_slot *slot)
bufkeylen = bufz - slot->buf;
if (slot->key)
- slot->match = bufkeylen == slot->keylen &&
+ slot->match = bufkeylen >= 0 && (size_t)bufkeylen == slot->keylen &&
!memcmp(slot->key, slot->buf, bufkeylen + 1);
return 0;
@@ -246,14 +252,7 @@ static int fill_slot(struct cache_slot *slot)
return 0;
}
-/* Crude implementation of 32-bit FNV-1 hash algorithm,
- * see http://www.isthe.com/chongo/tech/comp/fnv/ for details
- * about the magic numbers.
- */
-#define FNV_OFFSET 0x811c9dc5
-#define FNV_PRIME 0x01000193
-
-unsigned long hash_str(const char *str)
+unsigned long cache_hash_str(const char *str)
{
unsigned long h = FNV_OFFSET;
unsigned char *s = (unsigned char *)str;
@@ -379,7 +378,7 @@ int cache_process(int size, const char *path, const char *key, int ttl,
}
if (!key)
key = "";
- hash = hash_str(key) % size;
+ hash = cache_hash_str(key) % size;
strbuf_addstr(&filename, path);
strbuf_ensure_end(&filename, '/');
for (i = 0; i < 8; i++) {
diff --git a/source/cache.h b/source/cache.h
index 470da4f..f8018be 100644
--- a/source/cache.h
+++ b/source/cache.h
@@ -32,6 +32,6 @@ extern int cache_ls(const char *path);
__attribute__((format (printf,1,2)))
extern void cache_log(const char *format, ...);
-extern unsigned long hash_str(const char *str);
+extern unsigned long cache_hash_str(const char *str);
#endif /* CGIT_CACHE_H */
diff --git a/source/cgit.c b/source/cgit.c
index c2c488d..5cb52fd 100644
--- a/source/cgit.c
+++ b/source/cgit.c
@@ -20,6 +20,12 @@
#include "ui-summary.h"
#include "scan-tree.h"
+/* We intentionally keep this rather small, instead of looping and
+ * feeding it to the filter a couple bytes at a time. This way, the
+ * filter itself does not need to handle any denial of service or
+ * buffer bloat issues. If this winds up being too small, people
+ * will complain on the mailing list, and we'll increase it as needed. */
+#define MAX_AUTHENTICATION_POST_BYTES 4096
const char *cgit_version = CGIT_VERSION;
/*
@@ -58,19 +64,19 @@ void cgit_repo_config(struct cgit_repo *repo, const char *name, const char *valu
struct string_list_item *item;
if (!strcmp(name, "name"))
- repo->name = strdup_first_line(value);
+ repo->name = cgit_strdup_first_line(value);
else if (!strcmp(name, "clone-url"))
- repo->clone_url = strdup_first_line(value);
+ repo->clone_url = cgit_strdup_first_line(value);
else if (!strcmp(name, "desc"))
- repo->desc = strdup_first_line(value);
+ repo->desc = cgit_strdup_first_line(value);
else if (!strcmp(name, "owner"))
- repo->owner = strdup_first_line(value);
+ repo->owner = cgit_strdup_first_line(value);
else if (!strcmp(name, "homepage"))
- repo->homepage = strdup_first_line(value);
+ repo->homepage = cgit_strdup_first_line(value);
else if (!strcmp(name, "defbranch"))
- repo->defbranch = strdup_first_line(value);
+ repo->defbranch = cgit_strdup_first_line(value);
else if (!strcmp(name, "extra-head-content"))
- repo->extra_head_content = strdup_first_line(value);
+ repo->extra_head_content = cgit_strdup_first_line(value);
else if (!strcmp(name, "snapshots"))
repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value);
else if (!strcmp(name, "enable-blame"))
@@ -104,22 +110,22 @@ void cgit_repo_config(struct cgit_repo *repo, const char *name, const char *valu
} else if (!strcmp(name, "max-stats"))
repo->max_stats = cgit_find_stats_period(value, NULL);
else if (!strcmp(name, "module-link"))
- repo->module_link= strdup_first_line(value);
+ repo->module_link= cgit_strdup_first_line(value);
else if (skip_prefix(name, "module-link.", &path)) {
- item = string_list_append(&repo->submodules, strdup_first_line(path));
- item->util = strdup_first_line(value);
+ item = string_list_append(&repo->submodules, cgit_strdup_first_line(path));
+ item->util = cgit_strdup_first_line(value);
} else if (!strcmp(name, "section"))
- repo->section = strdup_first_line(value);
+ repo->section = cgit_strdup_first_line(value);
else if (!strcmp(name, "snapshot-prefix"))
- repo->snapshot_prefix = strdup_first_line(value);
+ repo->snapshot_prefix = cgit_strdup_first_line(value);
else if (!strcmp(name, "readme") && value != NULL) {
if (repo->readme.items == ctx.cfg.readme.items)
memset(&repo->readme, 0, sizeof(repo->readme));
- string_list_append(&repo->readme, strdup_first_line(value));
+ string_list_append(&repo->readme, cgit_strdup_first_line(value));
} else if (!strcmp(name, "logo") && value != NULL)
- repo->logo = strdup_first_line(value);
+ repo->logo = cgit_strdup_first_line(value);
else if (!strcmp(name, "logo-link") && value != NULL)
- repo->logo_link = strdup_first_line(value);
+ repo->logo_link = cgit_strdup_first_line(value);
else if (!strcmp(name, "hide"))
repo->hide = atoi(value);
else if (!strcmp(name, "ignore"))
@@ -141,43 +147,43 @@ static void config_cb(const char *name, const char *value)
const char *arg;
if (!strcmp(name, "section"))
- ctx.cfg.section = strdup_first_line(value);
+ ctx.cfg.section = cgit_strdup_first_line(value);
else if (!strcmp(name, "repo.url"))
ctx.repo = cgit_add_repo(value);
else if (ctx.repo && !strcmp(name, "repo.path"))
- ctx.repo->path = trim_end(value, '/');
+ ctx.repo->path = cgit_trim_end(value, '/');
else if (ctx.repo && skip_prefix(name, "repo.", &arg))
cgit_repo_config(ctx.repo, arg, value);
else if (!strcmp(name, "readme"))
- string_list_append(&ctx.cfg.readme, strdup_first_line(value));
+ string_list_append(&ctx.cfg.readme, cgit_strdup_first_line(value));
else if (!strcmp(name, "root-title"))
- ctx.cfg.root_title = strdup_first_line(value);
+ ctx.cfg.root_title = cgit_strdup_first_line(value);
else if (!strcmp(name, "root-desc"))
- ctx.cfg.root_desc = strdup_first_line(value);
+ ctx.cfg.root_desc = cgit_strdup_first_line(value);
else if (!strcmp(name, "root-readme"))
- ctx.cfg.root_readme = strdup_first_line(value);
+ ctx.cfg.root_readme = cgit_strdup_first_line(value);
else if (!strcmp(name, "css"))
- string_list_append(&ctx.cfg.css, strdup_first_line(value));
+ string_list_append(&ctx.cfg.css, cgit_strdup_first_line(value));
else if (!strcmp(name, "js"))
- string_list_append(&ctx.cfg.js, strdup_first_line(value));
+ string_list_append(&ctx.cfg.js, cgit_strdup_first_line(value));
else if (!strcmp(name, "favicon"))
- ctx.cfg.favicon = strdup_first_line(value);
+ ctx.cfg.favicon = cgit_strdup_first_line(value);
else if (!strcmp(name, "footer"))
- ctx.cfg.footer = strdup_first_line(value);
+ ctx.cfg.footer = cgit_strdup_first_line(value);
else if (!strcmp(name, "head-include"))
- ctx.cfg.head_include = strdup_first_line(value);
+ ctx.cfg.head_include = cgit_strdup_first_line(value);
else if (!strcmp(name, "header"))
- ctx.cfg.header = strdup_first_line(value);
+ ctx.cfg.header = cgit_strdup_first_line(value);
else if (!strcmp(name, "logo"))
- ctx.cfg.logo = strdup_first_line(value);
+ ctx.cfg.logo = cgit_strdup_first_line(value);
else if (!strcmp(name, "logo-link"))
- ctx.cfg.logo_link = strdup_first_line(value);
+ ctx.cfg.logo_link = cgit_strdup_first_line(value);
else if (!strcmp(name, "module-link"))
- ctx.cfg.module_link = strdup_first_line(value);
+ ctx.cfg.module_link = cgit_strdup_first_line(value);
else if (!strcmp(name, "strict-export"))
- ctx.cfg.strict_export = strdup_first_line(value);
+ ctx.cfg.strict_export = cgit_strdup_first_line(value);
else if (!strcmp(name, "virtual-root"))
- ctx.cfg.virtual_root = ensure_end(value, '/');
+ ctx.cfg.virtual_root = cgit_ensure_end(value, '/');
else if (!strcmp(name, "noplainemail"))
ctx.cfg.noplainemail = atoi(value);
else if (!strcmp(name, "noheader"))
@@ -225,7 +231,7 @@ static void config_cb(const char *name, const char *value)
else if (!strcmp(name, "cache-size"))
ctx.cfg.cache_size = atoi(value);
else if (!strcmp(name, "cache-root"))
- ctx.cfg.cache_root = strdup_first_line(expand_macros(value));
+ ctx.cfg.cache_root = cgit_strdup_first_line(cgit_expand_macros(value));
else if (!strcmp(name, "cache-root-ttl"))
ctx.cfg.cache_root_ttl = atoi(value);
else if (!strcmp(name, "cache-repo-ttl"))
@@ -275,21 +281,21 @@ static void config_cb(const char *name, const char *value)
else if (!strcmp(name, "max-patch-count"))
ctx.cfg.max_patch_count = atoi(value);
else if (!strcmp(name, "project-list"))
- ctx.cfg.project_list = strdup_first_line(expand_macros(value));
+ ctx.cfg.project_list = cgit_strdup_first_line(cgit_expand_macros(value));
else if (!strcmp(name, "scan-path"))
if (ctx.cfg.cache_size)
- process_cached_repolist(expand_macros(value));
+ process_cached_repolist(cgit_expand_macros(value));
else if (ctx.cfg.project_list)
- scan_projects(expand_macros(value),
+ scan_projects(cgit_expand_macros(value),
ctx.cfg.project_list);
else
- scan_tree(expand_macros(value));
+ scan_tree(cgit_expand_macros(value));
else if (!strcmp(name, "scan-hidden-path"))
ctx.cfg.scan_hidden_path = atoi(value);
else if (!strcmp(name, "section-from-path"))
ctx.cfg.section_from_path = atoi(value);
else if (!strcmp(name, "repository-sort"))
- ctx.cfg.repository_sort = strdup_first_line(value);
+ ctx.cfg.repository_sort = cgit_strdup_first_line(value);
else if (!strcmp(name, "section-sort"))
ctx.cfg.section_sort = atoi(value);
else if (!strcmp(name, "source-filter"))
@@ -303,19 +309,19 @@ static void config_cb(const char *name, const char *value)
else if (!strcmp(name, "side-by-side-diffs"))
ctx.cfg.difftype = atoi(value) ? DIFF_SSDIFF : DIFF_UNIFIED;
else if (!strcmp(name, "agefile"))
- ctx.cfg.agefile = strdup_first_line(value);
+ ctx.cfg.agefile = cgit_strdup_first_line(value);
else if (!strcmp(name, "mimetype-file"))
- ctx.cfg.mimetype_file = strdup_first_line(value);
+ ctx.cfg.mimetype_file = cgit_strdup_first_line(value);
else if (!strcmp(name, "renamelimit"))
ctx.cfg.renamelimit = atoi(value);
else if (!strcmp(name, "remove-suffix"))
ctx.cfg.remove_suffix = atoi(value);
else if (!strcmp(name, "robots"))
- ctx.cfg.robots = strdup_first_line(value);
+ ctx.cfg.robots = cgit_strdup_first_line(value);
else if (!strcmp(name, "clone-prefix"))
- ctx.cfg.clone_prefix = strdup_first_line(value);
+ ctx.cfg.clone_prefix = cgit_strdup_first_line(value);
else if (!strcmp(name, "clone-url"))
- ctx.cfg.clone_url = strdup_first_line(value);
+ ctx.cfg.clone_url = cgit_strdup_first_line(value);
else if (!strcmp(name, "local-time"))
ctx.cfg.local_time = atoi(value);
else if (!strcmp(name, "date-format"))
@@ -333,7 +339,7 @@ static void config_cb(const char *name, const char *value)
} else if (skip_prefix(name, "mimetype.", &arg))
add_mimetype(arg, value);
else if (!strcmp(name, "include"))
- parse_configfile(expand_macros(value), config_cb);
+ parse_configfile(cgit_expand_macros(value), config_cb);
}
static void querystring_cb(const char *name, const char *value)
@@ -377,7 +383,7 @@ static void querystring_cb(const char *name, const char *value)
ofs = -1;
ctx.qry.ofs = ofs;
} else if (!strcmp(name, "path")) {
- ctx.qry.path = trim_end(value, '/');
+ ctx.qry.path = cgit_trim_end(value, '/');
} else if (!strcmp(name, "s")) {
ctx.qry.sort = xstrdup(value);
} else if (!strcmp(name, "showmsg")) {
@@ -567,7 +573,7 @@ static inline void parse_readme(const char *readme, char **filename, char **ref,
/* Prepend repo path to relative readme path unless tracked. */
if (!(*ref) && readme[0] != '/')
- *filename = fmtalloc("%s/%s", repo->path, readme);
+ *filename = cgit_fmtalloc("%s/%s", repo->path, readme);
else
*filename = xstrdup(readme);
}
@@ -628,7 +634,7 @@ static int prepare_repo_cmd(int nongit)
if (nongit) {
const char *name = ctx.repo->name;
rc = errno;
- ctx.page.title = fmtalloc("%s - %s", ctx.cfg.root_title,
+ ctx.page.title = cgit_fmtalloc("%s - %s", ctx.cfg.root_title,
"config error");
ctx.repo = NULL;
cgit_print_http_headers();
@@ -639,7 +645,7 @@ static int prepare_repo_cmd(int nongit)
cgit_print_docend();
return 1;
}
- ctx.page.title = fmtalloc("%s - %s", ctx.repo->name, ctx.repo->desc);
+ ctx.page.title = cgit_fmtalloc("%s - %s", ctx.repo->name, ctx.repo->desc);
if (!ctx.repo->defbranch)
ctx.repo->defbranch = guess_defbranch();
@@ -693,12 +699,6 @@ static inline void open_auth_filter(const char *function)
cgit_loginurl());
}
-/* We intentionally keep this rather small, instead of looping and
- * feeding it to the filter a couple bytes at a time. This way, the
- * filter itself does not need to handle any denial of service or
- * buffer bloat issues. If this winds up being too small, people
- * will complain on the mailing list, and we'll increase it as needed. */
-#define MAX_AUTHENTICATION_POST_BYTES 4096
/* The filter is expected to spit out "Status: " and all headers. */
static inline void authenticate_post(void)
{
@@ -944,9 +944,9 @@ static void process_cached_repolist(const char *path)
time_t age;
unsigned long hash;
- hash = hash_str(path);
+ hash = cache_hash_str(path);
if (ctx.cfg.project_list)
- hash += hash_str(ctx.cfg.project_list);
+ hash += cache_hash_str(ctx.cfg.project_list);
strbuf_addf(&cached_rc, "%s/rc-%8lx", ctx.cfg.cache_root, hash);
if (stat(cached_rc.buf, &st)) {
@@ -1095,7 +1095,7 @@ int cmd_main(int argc, const char **argv)
cgit_repolist.repos = NULL;
cgit_parse_args(argc, argv);
- parse_configfile(expand_macros(ctx.env.cgit_config), config_cb);
+ parse_configfile(cgit_expand_macros(ctx.env.cgit_config), config_cb);
ctx.repo = NULL;
http_parse_querystring(ctx.qry.raw, querystring_cb);
@@ -1104,7 +1104,7 @@ int cmd_main(int argc, const char **argv)
* trailing slashes.
*/
if (!ctx.cfg.virtual_root && ctx.cfg.script_name)
- ctx.cfg.virtual_root = ensure_end(ctx.cfg.script_name, '/');
+ ctx.cfg.virtual_root = cgit_ensure_end(ctx.cfg.script_name, '/');
/* If no url parameter is specified on the querystring, lets
* use PATH_INFO as url. This allows cgit to work with virtual
@@ -1117,7 +1117,7 @@ int cmd_main(int argc, const char **argv)
path++;
ctx.qry.url = xstrdup(path);
if (ctx.qry.raw) {
- char *newqry = fmtalloc("%s?%s", path, ctx.qry.raw);
+ char *newqry = cgit_fmtalloc("%s?%s", path, ctx.qry.raw);
free(ctx.qry.raw);
ctx.qry.raw = newqry;
} else
diff --git a/source/cgit.h b/source/cgit.h
index d33a46b..8f10068 100644
--- a/source/cgit.h
+++ b/source/cgit.h
@@ -343,12 +343,12 @@ extern struct cgit_repo *cgit_get_repoinfo(const char *url);
extern void cgit_repo_config(struct cgit_repo *repo, const char *name,
const char *value);
-extern int chk_zero(int result, char *msg);
-extern int chk_positive(int result, char *msg);
-extern int chk_non_negative(int result, char *msg);
+extern int cgit_die_unless_zero(int result, const char *msg);
+extern int cgit_die_unless_positive(int result, const char *msg);
+extern int cgit_die_unless_non_negative(int result, const char *msg);
-extern char *trim_end(const char *str, char c);
-extern char *ensure_end(const char *str, char c);
+extern char *cgit_trim_end(const char *str, char c);
+extern char *cgit_ensure_end(const char *str, char c);
extern void strbuf_ensure_end(struct strbuf *sb, char c);
@@ -376,10 +376,10 @@ extern void cgit_diff_commit(struct commit *commit, filepair_fn fn,
const char *prefix);
__attribute__((format (printf,1,2)))
-extern char *fmt(const char *format,...);
+extern char *cgit_fmt(const char *format,...);
__attribute__((format (printf,1,2)))
-extern char *fmtalloc(const char *format,...);
+extern char *cgit_fmtalloc(const char *format,...);
extern struct commitinfo *cgit_parse_commit(struct commit *commit);
extern struct taginfo *cgit_parse_tag(struct tag *tag);
@@ -391,7 +391,7 @@ extern int cgit_parse_snapshots_mask(const char *str);
extern void cgit_parse_date_format(const char *format, struct date_mode *mode);
extern const struct object_id *cgit_snapshot_get_sig(const char *ref,
const struct cgit_snapshot_format *f);
-extern const unsigned cgit_snapshot_format_bit(const struct cgit_snapshot_format *f);
+extern unsigned cgit_snapshot_format_bit(const struct cgit_snapshot_format *f);
extern int cgit_open_filter(struct cgit_filter *filter, ...);
extern int cgit_close_filter(struct cgit_filter *filter);
@@ -403,12 +403,12 @@ extern void cgit_init_filters(void);
extern void cgit_prepare_repo_env(struct cgit_repo * repo);
-extern int read_first_line(const char *path, char **buf, size_t *size);
+extern int cgit_read_first_line(const char *path, char **buf, size_t *size);
-extern char *strdup_first_line(const char *txt);
+extern char *cgit_strdup_first_line(const char *txt);
-extern char *expand_macros(const char *txt);
+extern char *cgit_expand_macros(const char *txt);
-extern char *get_mimetype_for_filename(const char *filename);
+extern char *cgit_get_mimetype_for_filename(const char *filename);
#endif /* CGIT_H */
diff --git a/source/cmd.c b/source/cmd.c
index 510c957..c17d8d9 100644
--- a/source/cmd.c
+++ b/source/cmd.c
@@ -26,6 +26,8 @@
#include "ui-summary.h"
#include "ui-tag.h"
#include "ui-tree.h"
+#define def_cmd(name, want_repo, want_vpath, is_clone) \
+ {#name, name##_fn, want_repo, want_vpath, is_clone}
static void HEAD_fn(void)
{
@@ -46,7 +48,7 @@ static void about_fn(void)
ctx.qry.url[strlen(ctx.qry.url) - 1] != '/') &&
(!path_info_len || ctx.env.path_info[path_info_len - 1] != '/')) {
char *currenturl = cgit_currenturl();
- char *redirect = fmtalloc("%s/", currenturl);
+ char *redirect = cgit_fmtalloc("%s/", currenturl);
cgit_redirect(redirect, true);
free(currenturl);
free(redirect);
@@ -56,7 +58,7 @@ static void about_fn(void)
cgit_redirect(ctx.repo->homepage, false);
else {
char *currenturl = cgit_currenturl();
- char *redirect = fmtalloc("%s../", currenturl);
+ char *redirect = cgit_fmtalloc("%s../", currenturl);
cgit_redirect(redirect, false);
free(currenturl);
free(redirect);
@@ -174,9 +176,6 @@ static void tree_fn(void)
cgit_print_tree(ctx.qry.oid, ctx.qry.path);
}
-#define def_cmd(name, want_repo, want_vpath, is_clone) \
- {#name, name##_fn, want_repo, want_vpath, is_clone}
-
struct cgit_cmd *cgit_get_cmd(void)
{
static struct cgit_cmd cmds[] = {
@@ -202,7 +201,7 @@ struct cgit_cmd *cgit_get_cmd(void)
def_cmd(tag, 1, 0, 0),
def_cmd(tree, 1, 1, 0),
};
- int i;
+ size_t i;
if (ctx.qry.page == NULL) {
if (ctx.repo)
@@ -211,7 +210,7 @@ struct cgit_cmd *cgit_get_cmd(void)
ctx.qry.page = "repolist";
}
- for (i = 0; i < sizeof(cmds)/sizeof(*cmds); i++)
+ for (i = 0; i < ARRAY_SIZE(cmds); i++)
if (!strcmp(ctx.qry.page, cmds[i].name))
return &cmds[i];
return NULL;
diff --git a/source/filter.c b/source/filter.c
index 7f7942d..e15a5e9 100644
--- a/source/filter.c
+++ b/source/filter.c
@@ -46,19 +46,19 @@ static int open_exec_filter(struct cgit_filter *base, va_list ap)
for (i = 0; i < filter->base.argument_count; i++)
filter->argv[i + 1] = va_arg(ap, char *);
- filter->old_stdout = chk_positive(dup(STDOUT_FILENO),
+ filter->old_stdout = cgit_die_unless_positive(dup(STDOUT_FILENO),
"Unable to duplicate STDOUT");
- chk_zero(pipe(pipe_fh), "Unable to create pipe to subprocess");
- filter->pid = chk_non_negative(fork(), "Unable to create subprocess");
+ cgit_die_unless_zero(pipe(pipe_fh), "Unable to create pipe to subprocess");
+ filter->pid = cgit_die_unless_non_negative(fork(), "Unable to create subprocess");
if (filter->pid == 0) {
close(pipe_fh[1]);
- chk_non_negative(dup2(pipe_fh[0], STDIN_FILENO),
+ cgit_die_unless_non_negative(dup2(pipe_fh[0], STDIN_FILENO),
"Unable to use pipe as STDIN");
execvp(filter->cmd, filter->argv);
die_errno("Unable to exec subprocess %s", filter->cmd);
}
close(pipe_fh[0]);
- chk_non_negative(dup2(pipe_fh[1], STDOUT_FILENO),
+ cgit_die_unless_non_negative(dup2(pipe_fh[1], STDOUT_FILENO),
"Unable to use pipe as STDOUT");
close(pipe_fh[1]);
return 0;
@@ -69,7 +69,7 @@ static int close_exec_filter(struct cgit_filter *base)
struct cgit_exec_filter *filter = (struct cgit_exec_filter *)base;
int i, exit_status = 0;
- chk_non_negative(dup2(filter->old_stdout, STDOUT_FILENO),
+ cgit_die_unless_non_negative(dup2(filter->old_stdout, STDOUT_FILENO),
"Unable to restore STDOUT");
close(filter->old_stdout);
if (filter->pid < 0)
@@ -112,7 +112,7 @@ static struct cgit_filter *new_exec_filter(const char *cmd, int argument_count)
f = xmalloc(sizeof(*f));
/* We leave argv for now and assign it below. */
- cgit_exec_filter_init(f, strdup_first_line(cmd), NULL);
+ cgit_exec_filter_init(f, cgit_strdup_first_line(cmd), NULL);
f->base.argument_count = argument_count;
args_size = (2 + argument_count) * sizeof(char *);
f->argv = xmalloc(args_size);
@@ -354,7 +354,7 @@ static struct cgit_filter *new_lua_filter(const char *cmd, int argument_count)
filter->base.fprintfp = fprintf_lua_filter;
filter->base.cleanup = cleanup_lua_filter;
filter->base.argument_count = argument_count;
- filter->script_file = strdup_first_line(cmd);
+ filter->script_file = cgit_strdup_first_line(cmd);
return &filter->base;
}
@@ -401,7 +401,7 @@ static const struct {
struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
{
const char *colon;
- int i;
+ size_t i;
size_t len;
int argument_count;
diff --git a/source/html.c b/source/html.c
index 700f033..c3ab696 100644
--- a/source/html.c
+++ b/source/html.c
@@ -46,7 +46,7 @@ static const char* url_escape_table[256] = {
"%f8", "%f9", "%fa", "%fb", "%fc", "%fd", "%fe", "%ff"
};
-char *fmt(const char *format, ...)
+char *cgit_fmt(const char *format, ...)
{
static char buf[8][1024];
static int bufidx;
@@ -59,14 +59,14 @@ char *fmt(const char *format, ...)
va_start(args, format);
len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args);
va_end(args);
- if (len >= sizeof(buf[bufidx])) {
+ if (len < 0 || (size_t)len >= sizeof(buf[bufidx])) {
fprintf(stderr, "[html.c] string truncated: %s\n", format);
exit(1);
}
return buf[bufidx];
}
-char *fmtalloc(const char *format, ...)
+char *cgit_fmtalloc(const char *format, ...)
{
struct strbuf sb = STRBUF_INIT;
va_list args;
diff --git a/source/parsing.c b/source/parsing.c
index a7e46de..f6b1a02 100644
--- a/source/parsing.c
+++ b/source/parsing.c
@@ -52,7 +52,7 @@ void cgit_parse_url(const char *url)
if (p) {
p[0] = '\0';
if (p[1])
- ctx.qry.path = trim_end(p + 1, '/');
+ ctx.qry.path = cgit_trim_end(p + 1, '/');
}
if (cmd[1])
ctx.qry.page = xstrdup(cmd + 1);
diff --git a/source/scan-tree.c b/source/scan-tree.c
index 7e626bf..89f65c9 100644
--- a/source/scan-tree.c
+++ b/source/scan-tree.c
@@ -12,6 +12,11 @@
#include "html.h"
#include <config.h>
+// The description git puts in every freshly created repository.
+static const char *default_git_desc = "Unnamed repository; edit this file 'description' to name the repository.";
+
+static struct cgit_repo *repo;
+
/* return 1 if path contains a objects/ directory and a HEAD file */
static int is_git_dir(const char *path)
{
@@ -46,18 +51,14 @@ out:
return result;
}
-// The description git puts in every freshly created repository.
-static const char *default_git_desc = "Unnamed repository; edit this file 'description' to name the repository.";
-
-static struct cgit_repo *repo;
-
static void scan_tree_repo_config(const char *name, const char *value)
{
cgit_repo_config(repo, name, value);
}
static int gitconfig_config(const char *key, const char *value,
- const __attribute__((unused)) struct config_context *ctx, void *cb)
+ const __attribute__((unused)) struct config_context *cfg_ctx,
+ void *cb)
{
const char *name;
@@ -139,7 +140,7 @@ static void add_repo(const char *base, struct strbuf *path)
strip_suffix_mem(repo->url, &urllen, "/");
repo->url[urllen] = '\0';
}
- repo->path = strdup_first_line(path->buf);
+ repo->path = cgit_strdup_first_line(path->buf);
while (!repo->owner) {
if ((pwd = getpwuid(st.st_uid)) == NULL) {
fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n",
@@ -149,13 +150,13 @@ static void add_repo(const char *base, struct strbuf *path)
if (pwd->pw_gecos)
if ((p = strchr(pwd->pw_gecos, ',')))
*p = '\0';
- repo->owner = strdup_first_line(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name);
+ repo->owner = cgit_strdup_first_line(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name);
}
if (repo->desc == cgit_default_repo_desc || !repo->desc) {
strbuf_addstr(path, "description");
if (!stat(path->buf, &st))
- read_first_line(path->buf, &repo->desc, &size);
+ cgit_read_first_line(path->buf, &repo->desc, &size);
strbuf_setlen(path, pathlen);
// Git writes this line into every repository it creates, so it
// describes nothing. Treat it as no description at all rather
@@ -179,7 +180,7 @@ static void add_repo(const char *base, struct strbuf *path)
}
if (slash && !n) {
*slash = '\0';
- repo->section = strdup_first_line(rel.buf);
+ repo->section = cgit_strdup_first_line(rel.buf);
*slash = '/';
if (starts_with(repo->name, repo->section)) {
repo->name += strlen(repo->section);
diff --git a/source/shared.c b/source/shared.c
index 058d938..259802a 100644
--- a/source/shared.c
+++ b/source/shared.c
@@ -10,24 +10,31 @@
#include "cgit.h"
+/* Longest result cgit_expand_macros can return. */
+#define MACRO_EXPANSION_BUFSIZE (1024 * 8)
+
+/* Partial line carried between xdiff callbacks, see filediff_cb. */
+static char *diffbuf;
+static int diffbuf_len;
+
struct cgit_repolist cgit_repolist;
struct cgit_context ctx;
-int chk_zero(int result, char *msg)
+int cgit_die_unless_zero(int result, const char *msg)
{
if (result != 0)
die_errno("%s", msg);
return result;
}
-int chk_positive(int result, char *msg)
+int cgit_die_unless_positive(int result, const char *msg)
{
if (result <= 0)
die_errno("%s", msg);
return result;
}
-int chk_non_negative(int result, char *msg)
+int cgit_die_unless_non_negative(int result, const char *msg)
{
if (result < 0)
die_errno("%s", msg);
@@ -51,7 +58,7 @@ struct cgit_repo *cgit_add_repo(const char *url)
ret = &cgit_repolist.repos[cgit_repolist.count-1];
memset(ret, 0, sizeof(struct cgit_repo));
- ret->url = trim_end(url, '/');
+ ret->url = cgit_trim_end(url, '/');
if (ret->url)
*strchrnul(ret->url, '\n') = '\0';
ret->name = ret->url;
@@ -114,7 +121,7 @@ void cgit_free_commitinfo(struct commitinfo *info)
free(info);
}
-char *trim_end(const char *str, char c)
+char *cgit_trim_end(const char *str, char c)
{
int len;
@@ -128,7 +135,7 @@ char *trim_end(const char *str, char c)
return xstrndup(str, len);
}
-char *ensure_end(const char *str, char c)
+char *cgit_ensure_end(const char *str, char c)
{
size_t len = strlen(str);
char *result;
@@ -265,9 +272,6 @@ static int load_mmfile(mmfile_t *file, const struct object_id *oid)
* ripped from git and modified to use globals instead of
* a special callback-struct.
*/
-static char *diffbuf = NULL;
-static int buflen = 0;
-
static int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf)
{
int i;
@@ -275,9 +279,9 @@ static int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf)
for (i = 0; i < nbuf; i++) {
if (mb[i].ptr[mb[i].size-1] != '\n') {
/* Incomplete line */
- diffbuf = xrealloc(diffbuf, buflen + mb[i].size);
- memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size);
- buflen += mb[i].size;
+ diffbuf = xrealloc(diffbuf, diffbuf_len + mb[i].size);
+ memcpy(diffbuf + diffbuf_len, mb[i].ptr, mb[i].size);
+ diffbuf_len += mb[i].size;
continue;
}
@@ -286,18 +290,18 @@ static int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf)
((linediff_fn)priv)(mb[i].ptr, mb[i].size);
continue;
}
- diffbuf = xrealloc(diffbuf, buflen + mb[i].size);
- memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size);
- ((linediff_fn)priv)(diffbuf, buflen + mb[i].size);
+ diffbuf = xrealloc(diffbuf, diffbuf_len + mb[i].size);
+ memcpy(diffbuf + diffbuf_len, mb[i].ptr, mb[i].size);
+ ((linediff_fn)priv)(diffbuf, diffbuf_len + mb[i].size);
free(diffbuf);
diffbuf = NULL;
- buflen = 0;
+ diffbuf_len = 0;
}
if (diffbuf) {
- ((linediff_fn)priv)(diffbuf, buflen);
+ ((linediff_fn)priv)(diffbuf, diffbuf_len);
free(diffbuf);
diffbuf = NULL;
- buflen = 0;
+ diffbuf_len = 0;
}
return 0;
}
@@ -473,8 +477,8 @@ void cgit_parse_date_format(const char *format, struct date_mode *mode)
}
typedef struct {
- char * name;
- char * value;
+ const char *name;
+ const char *value;
} cgit_env_var;
void cgit_prepare_repo_env(struct cgit_repo * repo)
@@ -490,7 +494,7 @@ void cgit_prepare_repo_env(struct cgit_repo * repo)
};
int env_var_count = ARRAY_SIZE(env_vars);
cgit_env_var *p, *q;
- static char *warn = "cgit warning: failed to set env: %s=%s\n";
+ static const char *warn = "cgit warning: failed to set env: %s=%s\n";
p = env_vars;
q = p + env_var_count;
@@ -503,7 +507,7 @@ void cgit_prepare_repo_env(struct cgit_repo * repo)
* zeroterminate the buffer, truncate at a new line, and return 0 on success,
* errno otherwise.
*/
-int read_first_line(const char *path, char **buf, size_t *size)
+int cgit_read_first_line(const char *path, char **buf, size_t *size)
{
int fd, e;
ssize_t got;
@@ -538,7 +542,7 @@ int read_first_line(const char *path, char **buf, size_t *size)
return (*size == (size_t)st.st_size ? 0 : e);
}
-char *strdup_first_line(const char *txt)
+char *cgit_strdup_first_line(const char *txt)
{
char *t = xstrdup(txt);
*strchrnul(t, '\n') = '\0';
@@ -552,7 +556,7 @@ static int is_token_char(char c)
/* Replace name with getenv(name), return pointer to zero-terminating char
*/
-static char *expand_macro(char *name, int maxlength)
+static char *expand_macro(char *name, size_t maxlength)
{
char *value;
size_t len;
@@ -569,28 +573,26 @@ static char *expand_macro(char *name, int maxlength)
return name + len;
}
-#define EXPBUFSIZE (1024 * 8)
-
/* Replace all tokens prefixed by '$' in the specified text with the
* value of the named environment variable.
* NB: the return value is a static buffer, i.e. it must be strdup'd
* by the caller.
*/
-char *expand_macros(const char *txt)
+char *cgit_expand_macros(const char *txt)
{
- static char result[EXPBUFSIZE];
+ static char result[MACRO_EXPANSION_BUFSIZE];
char *p, *start;
- int len;
+ size_t len;
p = result;
start = NULL;
- while (p < result + EXPBUFSIZE - 1 && txt && *txt) {
+ while (p < result + MACRO_EXPANSION_BUFSIZE - 1 && txt && *txt) {
*p = *txt;
if (start) {
if (!is_token_char(*txt)) {
if (p - start > 0) {
*p = '\0';
- len = result + EXPBUFSIZE - start - 1;
+ len = result + MACRO_EXPANSION_BUFSIZE - start - 1;
p = expand_macro(start, len) - 1;
}
start = NULL;
@@ -610,19 +612,19 @@ char *expand_macros(const char *txt)
}
*p = '\0';
if (start && p - start > 0) {
- len = result + EXPBUFSIZE - start - 1;
+ len = result + MACRO_EXPANSION_BUFSIZE - start - 1;
p = expand_macro(start, len);
*p = '\0';
}
return result;
}
-char *get_mimetype_for_filename(const char *filename)
+char *cgit_get_mimetype_for_filename(const char *filename)
{
const char *ext;
char *mimetype, line[1024];
struct string_list list = STRING_LIST_INIT_NODUP;
- int i;
+ size_t i;
FILE *file;
struct string_list_item *mime;
diff --git a/source/ui-blame.c b/source/ui-blame.c
index 1132f43..418e3ae 100644
--- a/source/ui-blame.c
+++ b/source/ui-blame.c
@@ -173,13 +173,6 @@ static void print_object(const struct object_id *oid, const char *path,
html("<div class='error'>blob is binary.</div>");
goto cleanup;
}
- if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) {
- htmlf("<div class='error'>blob size (%ldKB)"
- " exceeds display size limit (%dKB).</div>",
- size / 1024, ctx.cfg.max_blob_size);
- goto cleanup;
- }
-
html("<table class='blame blob'>\n<tr>\n");
/* Commit hashes */
@@ -247,7 +240,9 @@ static int walk_tree(const struct object_id *oid, struct strbuf *base,
{
struct walk_tree_context *walk_tree_ctx = cbdata;
- if (base->len == walk_tree_ctx->match_baselen) {
+ // match_baselen is -1 when no path was given, which no length equals.
+ if (walk_tree_ctx->match_baselen >= 0 &&
+ base->len == (size_t)walk_tree_ctx->match_baselen) {
if (S_ISREG(mode)) {
struct strbuf buffer = STRBUF_INIT;
strbuf_addbuf(&buffer, base);
diff --git a/source/ui-commit.c b/source/ui-commit.c
index 57dc717..4d6d4da 100644
--- a/source/ui-commit.c
+++ b/source/ui-commit.c
@@ -45,7 +45,7 @@ void cgit_print_commit(char *hex, const char *prefix)
load_ref_decorations(NULL, DECORATE_FULL_REFS);
- ctx.page.title = fmtalloc("%s - %s", info->subject, ctx.page.title);
+ ctx.page.title = cgit_fmtalloc("%s - %s", info->subject, ctx.page.title);
cgit_print_layout_start();
cgit_print_diff_ctrls();
html("<table summary='commit info' class='commit-info'>\n");
@@ -121,7 +121,7 @@ void cgit_print_commit(char *hex, const char *prefix)
cgit_open_filter(ctx.repo->commit_filter);
html_txt(info->subject);
cgit_close_filter(ctx.repo->commit_filter);
- show_commit_decorations(commit);
+ cgit_print_commit_decorations(commit);
html("</div>");
html("<div class='commit-msg'>");
cgit_open_filter(ctx.repo->commit_filter);
diff --git a/source/ui-diff.c b/source/ui-diff.c
index ab40566..ebf9425 100644
--- a/source/ui-diff.c
+++ b/source/ui-diff.c
@@ -57,7 +57,7 @@ struct diff_filespec *cgit_get_current_new_file(void)
static void print_fileinfo(struct fileinfo *info)
{
- char *class;
+ const char *class;
switch (info->status) {
case DIFF_STATUS_ADDED:
@@ -228,7 +228,7 @@ static void cgit_print_diffstat(const struct object_id *old_oid,
*/
static void print_line(char *line, int len)
{
- char *class = "ctx";
+ const char *class = "ctx";
char c = line[len-1];
if (line[0] == '+')
@@ -345,11 +345,11 @@ static void filepair_cb(struct diff_filepair *pair)
}
if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) {
if (S_ISGITLINK(pair->one->mode)) {
- char *l = fmt("-Subproject %s", oid_to_hex(&pair->one->oid));
+ char *l = cgit_fmt("-Subproject %s", oid_to_hex(&pair->one->oid));
print_line_fn(l, strlen(l) + 1);
}
if (S_ISGITLINK(pair->two->mode)) {
- char *l = fmt("+Subproject %s", oid_to_hex(&pair->two->oid));
+ char *l = cgit_fmt("+Subproject %s", oid_to_hex(&pair->two->oid));
print_line_fn(l, strlen(l) + 1);
}
if (use_ssdiff)
@@ -388,9 +388,9 @@ void cgit_print_diff_ctrls(void)
if (!curr)
curr = 3;
for (i = 1; i <= 10; i++)
- html_intoption(i, fmt("%d", i), curr);
+ html_intoption(i, cgit_fmt("%d", i), curr);
for (i = 15; i <= 40; i += 5)
- html_intoption(i, fmt("%d", i), curr);
+ html_intoption(i, cgit_fmt("%d", i), curr);
html("</select>");
html("</td>");
html("</tr><tr>");
diff --git a/source/ui-log.c b/source/ui-log.c
index ff02d9a..5eb9a74 100644
--- a/source/ui-log.c
+++ b/source/ui-log.c
@@ -56,7 +56,7 @@ static void inspect_files(struct diff_filepair *pair)
count_lines);
}
-void show_commit_decorations(struct commit *commit)
+void cgit_print_commit_decorations(struct commit *commit)
{
const struct name_decoration *deco;
static char buf[1024];
@@ -221,8 +221,8 @@ static void print_commit(struct commit *commit, struct rev_info *revs)
/* line-wrap long commit subjects instead of truncating them */
size_t subject_len = strlen(info->subject);
- if (subject_len > ctx.cfg.max_msg_len &&
- ctx.cfg.max_msg_len >= 15) {
+ if (ctx.cfg.max_msg_len >= 15 &&
+ subject_len > (size_t)ctx.cfg.max_msg_len) {
/* symbol for signaling line-wrap (in PAGE_ENCODING) */
const char wrap_symbol[] = { ' ', 0xE2, 0x86, 0xB5, 0 };
int i = ctx.cfg.max_msg_len - strlen(wrap_symbol);
@@ -244,7 +244,7 @@ static void print_commit(struct commit *commit, struct rev_info *revs)
}
cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
oid_to_hex(&commit->object.oid), ctx.qry.vpath);
- show_commit_decorations(commit);
+ cgit_print_commit_decorations(commit);
html("</td><td class='col-author'>");
cgit_open_filter(ctx.repo->email_filter, info->author_email, "log");
html_txt(info->author);
diff --git a/source/ui-log.h b/source/ui-log.h
index 325607c..562524b 100644
--- a/source/ui-log.h
+++ b/source/ui-log.h
@@ -4,6 +4,6 @@
extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep,
char *pattern, const char *path, int pager,
int commit_graph, int commit_sort);
-extern void show_commit_decorations(struct commit *commit);
+extern void cgit_print_commit_decorations(struct commit *commit);
#endif /* UI_LOG_H */
diff --git a/source/ui-patch.c b/source/ui-patch.c
index 6d8a8ad..29432ac 100644
--- a/source/ui-patch.c
+++ b/source/ui-patch.c
@@ -69,7 +69,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev,
oid_to_hex(&new_rev_oid));
}
- patchname = fmt("%s.patch", rev_range);
+ patchname = cgit_fmt("%s.patch", rev_range);
ctx.page.mimetype = "text/plain";
ctx.page.filename = patchname;
cgit_print_http_headers();
@@ -89,7 +89,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev,
rev.diffopt.output_format |= DIFF_FORMAT_DIFFSTAT |
DIFF_FORMAT_PATCH | DIFF_FORMAT_SUMMARY;
if (prefix)
- rev.diffopt.stat_sep = fmt("(limited to '%s')\n\n", prefix);
+ rev.diffopt.stat_sep = cgit_fmt("(limited to '%s')\n\n", prefix);
setup_revisions(rev_argc, rev_argv, &rev, NULL);
// A single commit resolves to a parent..commit range, so this only
// bounds an explicit id/id2 range and keeps one request from
diff --git a/source/ui-plain.c b/source/ui-plain.c
index e58849c..8085382 100644
--- a/source/ui-plain.c
+++ b/source/ui-plain.c
@@ -44,7 +44,7 @@ static int print_object(const struct object_id *oid, const char *path)
return 1;
}
- mimetype = get_mimetype_for_filename(path);
+ mimetype = cgit_get_mimetype_for_filename(path);
ctx.page.mimetype = mimetype;
if (!ctx.repo->enable_html_serving) {
@@ -78,9 +78,9 @@ static int print_object(const struct object_id *oid, const char *path)
static char *buildpath(const char *base, int baselen, const char *path)
{
if (path[0])
- return fmtalloc("%.*s%s/", baselen, base, path);
+ return cgit_fmtalloc("%.*s%s/", baselen, base, path);
else
- return fmtalloc("%.*s/", baselen, base);
+ return cgit_fmtalloc("%.*s/", baselen, base);
}
static void print_dir(const struct object_id *oid, const char *base,
@@ -144,7 +144,9 @@ static int walk_tree(const struct object_id *oid, struct strbuf *base,
{
struct walk_tree_context *walk_tree_ctx = cbdata;
- if (base->len == walk_tree_ctx->match_baselen) {
+ // match_baselen is -1 when no path was given, which no length equals.
+ if (walk_tree_ctx->match_baselen >= 0 &&
+ base->len == (size_t)walk_tree_ctx->match_baselen) {
if (S_ISREG(mode) || S_ISLNK(mode)) {
if (print_object(oid, pathname))
walk_tree_ctx->match = 1;
diff --git a/source/ui-refs.c b/source/ui-refs.c
index c64b344..932ba6d 100644
--- a/source/ui-refs.c
+++ b/source/ui-refs.c
@@ -153,8 +153,8 @@ static void print_ref_pager(int ofs, int pagesize, int count, const char *path)
html("<tr class='nohover'><td colspan='5' class='refs-pager'>");
if (ofs > 0) {
- url = cgit_pageurl(ctx.qry.repo, fmt("refs/%s", path),
- fmt("ofs=%d", ofs > pagesize ? ofs - pagesize : 0));
+ url = cgit_pageurl(ctx.qry.repo, cgit_fmt("refs/%s", path),
+ cgit_fmt("ofs=%d", ofs > pagesize ? ofs - pagesize : 0));
html("<a href='");
html_attr(url);
html("'>[prev]</a> ");
@@ -163,8 +163,8 @@ static void print_ref_pager(int ofs, int pagesize, int count, const char *path)
htmlf("%d - %d of %d", ofs + 1,
ofs + pagesize < count ? ofs + pagesize : count, count);
if (ofs + pagesize < count) {
- url = cgit_pageurl(ctx.qry.repo, fmt("refs/%s", path),
- fmt("ofs=%d", ofs + pagesize));
+ url = cgit_pageurl(ctx.qry.repo, cgit_fmt("refs/%s", path),
+ cgit_fmt("ofs=%d", ofs + pagesize));
html(" <a href='");
html_attr(url);
html("'>[next]</a>");
diff --git a/source/ui-repolist.c b/source/ui-repolist.c
index c54ca32..e18e46e 100644
--- a/source/ui-repolist.c
+++ b/source/ui-repolist.c
@@ -18,7 +18,7 @@ static time_t read_agefile(const char *path)
char *buf = NULL;
struct strbuf date_buf = STRBUF_INIT;
- if (read_first_line(path, &buf, &size)) {
+ if (cgit_read_first_line(path, &buf, &size)) {
free(buf);
return 0;
}
@@ -187,7 +187,7 @@ static void print_pager(int items, int pagelen, char *search, char *sort)
for (i = 0, ofs = 0; ofs < items; i++, ofs = i * pagelen) {
class = (ctx.qry.ofs == ofs) ? "current" : NULL;
html("<li>");
- cgit_index_link(fmt("[%d]", i + 1), fmt("Page %d", i + 1),
+ cgit_index_link(cgit_fmt("[%d]", i + 1), cgit_fmt("Page %d", i + 1),
class, search, sort, ofs, 0);
html("</li>");
}
diff --git a/source/ui-shared.c b/source/ui-shared.c
index e53d1e5..1b65a7f 100644
--- a/source/ui-shared.c
+++ b/source/ui-shared.c
@@ -26,7 +26,7 @@ static char *http_date(time_t t)
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
struct tm tm;
gmtime_r(&t, &tm);
- return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm.tm_wday],
+ return cgit_fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm.tm_wday],
tm.tm_mday, month[tm.tm_mon], 1900 + tm.tm_year,
tm.tm_hour, tm.tm_min, tm.tm_sec);
}
@@ -65,7 +65,7 @@ char *cgit_hosturl(void)
return NULL;
if (!ctx.env.server_port || atoi(ctx.env.server_port) == 80)
return xstrdup(ctx.env.server_name);
- return fmtalloc("%s:%s", ctx.env.server_name, ctx.env.server_port);
+ return cgit_fmtalloc("%s:%s", ctx.env.server_name, ctx.env.server_port);
}
char *cgit_currenturl(void)
@@ -75,8 +75,8 @@ char *cgit_currenturl(void)
if (!ctx.qry.url)
return xstrdup(root);
if (root[0] && root[strlen(root) - 1] == '/')
- return fmtalloc("%s%s", root, ctx.qry.url);
- return fmtalloc("%s/%s", root, ctx.qry.url);
+ return cgit_fmtalloc("%s%s", root, ctx.qry.url);
+ return cgit_fmtalloc("%s/%s", root, ctx.qry.url);
}
char *cgit_currentfullurl(void)
@@ -104,11 +104,11 @@ char *cgit_currentfullurl(void)
query[0] = '\0';
if (!ctx.qry.url)
- ret = fmtalloc("%s%s", root, query);
+ ret = cgit_fmtalloc("%s%s", root, query);
else if (root[0] && root[strlen(root) - 1] == '/')
- ret = fmtalloc("%s%s%s", root, ctx.qry.url, query);
+ ret = cgit_fmtalloc("%s%s%s", root, ctx.qry.url, query);
else
- ret = fmtalloc("%s/%s%s", root, ctx.qry.url, query);
+ ret = cgit_fmtalloc("%s/%s%s", root, ctx.qry.url, query);
free(query);
return ret;
}
@@ -125,23 +125,23 @@ const char *cgit_loginurl(void)
{
static const char *login_url;
if (!login_url)
- login_url = fmtalloc("%s?p=login", cgit_rooturl());
+ login_url = cgit_fmtalloc("%s?p=login", cgit_rooturl());
return login_url;
}
char *cgit_repourl(const char *reponame)
{
if (ctx.cfg.virtual_root)
- return fmtalloc("%s%s/", ctx.cfg.virtual_root, reponame);
+ return cgit_fmtalloc("%s%s/", ctx.cfg.virtual_root, reponame);
else
- return fmtalloc("?r=%s", reponame);
+ return cgit_fmtalloc("?r=%s", reponame);
}
char *cgit_fileurl(const char *reponame, const char *pagename,
const char *filename, const char *query)
{
struct strbuf sb = STRBUF_INIT;
- char *delim;
+ const char *delim;
if (ctx.cfg.virtual_root) {
strbuf_addf(&sb, "%s%s/%s/%s", ctx.cfg.virtual_root, reponame,
@@ -203,7 +203,7 @@ const char *cgit_snapshot_prefix(const struct cgit_repo *repo)
static void site_url(const char *page, const char *search, const char *sort, int ofs, int always_root)
{
- char *delim = "?";
+ const char *delim = "?";
if (always_root || page)
html_attr(cgit_rooturl());
@@ -262,10 +262,10 @@ void cgit_index_link(const char *name, const char *title, const char *class,
site_link(NULL, name, title, class, pattern, sort, ofs, always_root);
}
-static char *repolink(const char *title, const char *class, const char *page,
+static const char *repolink(const char *title, const char *class, const char *page,
const char *head, const char *path)
{
- char *delim = "?";
+ const char *delim = "?";
html("<a");
if (title) {
@@ -310,14 +310,14 @@ static char *repolink(const char *title, const char *class, const char *page,
html_url_arg(head);
delim = "&amp;";
}
- return fmt("%s", delim);
+ return cgit_fmt("%s", delim);
}
static void reporevlink(const char *page, const char *name, const char *title,
const char *class, const char *head, const char *rev,
const char *path)
{
- char *delim;
+ const char *delim;
delim = repolink(title, class, page, head, path);
if (rev && ctx.qry.head != NULL && strcmp(rev, ctx.qry.head)) {
@@ -365,7 +365,7 @@ void cgit_log_link(const char *name, const char *title, const char *class,
int ofs, const char *grep, const char *pattern, int showmsg,
int follow)
{
- char *delim;
+ const char *delim;
delim = repolink(title, class, "log", head, path);
if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) {
@@ -406,7 +406,7 @@ void cgit_log_link(const char *name, const char *title, const char *class,
void cgit_commit_link(const char *name, const char *title, const char *class,
const char *head, const char *rev, const char *path)
{
- char *delim;
+ const char *delim;
delim = repolink(title, class, "commit", head, path);
if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) {
@@ -437,7 +437,8 @@ void cgit_commit_link(const char *name, const char *title, const char *class,
}
html("'>");
if (name && name[0] != '\0') {
- if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) {
+ if (ctx.cfg.max_msg_len >= 15 &&
+ strlen(name) > (size_t)ctx.cfg.max_msg_len) {
html_ntxt(name, ctx.cfg.max_msg_len - 3);
html("...");
} else
@@ -464,7 +465,7 @@ void cgit_diff_link(const char *name, const char *title, const char *class,
const char *head, const char *new_rev, const char *old_rev,
const char *path)
{
- char *delim;
+ const char *delim;
delim = repolink(title, class, "diff", head, path);
if (new_rev && ctx.qry.head != NULL && strcmp(new_rev, ctx.qry.head)) {
@@ -580,13 +581,14 @@ static void cgit_self_link(char *name, const char *title, const char *class)
void cgit_object_link(struct object *obj)
{
- char *page, *shortrev, *fullrev, *name;
+ const char *page;
+ char *shortrev, *fullrev, *name;
fullrev = oid_to_hex(&obj->oid);
shortrev = xstrdup(fullrev);
shortrev[10] = '\0';
if (obj->type == OBJ_COMMIT) {
- cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
+ cgit_commit_link(cgit_fmt("commit %s...", shortrev), NULL, NULL,
ctx.qry.head, fullrev, NULL);
return;
} else if (obj->type == OBJ_TREE)
@@ -595,7 +597,7 @@ void cgit_object_link(struct object *obj)
page = "tag";
else
page = "blob";
- name = fmt("%s %s...", type_name(obj->type), shortrev);
+ name = cgit_fmt("%s %s...", type_name(obj->type), shortrev);
reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
}
@@ -664,7 +666,7 @@ void cgit_submodule_link(const char *class, char *path, const char *rev)
path[len - 1] = tail;
}
-const struct date_mode cgit_date_mode(enum date_mode_type type)
+struct date_mode cgit_date_mode(enum date_mode_type type)
{
static struct date_mode mode;
mode.type = type;
@@ -676,7 +678,7 @@ const struct date_mode cgit_date_mode(enum date_mode_type type)
* The mode date-format selects, used wherever an age column falls back to a
* calendar date. local-time still forces local rendering on top of it.
*/
-static const struct date_mode cgit_configured_date_mode(void)
+static struct date_mode cgit_configured_date_mode(void)
{
struct date_mode mode = ctx.cfg.date_mode;
@@ -960,7 +962,7 @@ static void add_clone_urls(void (*fn)(const char *), char *txt, char *suffix)
void cgit_add_clone_urls(void (*fn)(const char *))
{
if (ctx.repo->clone_url)
- add_clone_urls(fn, expand_macros(ctx.repo->clone_url), NULL);
+ add_clone_urls(fn, cgit_expand_macros(ctx.repo->clone_url), NULL);
else if (ctx.cfg.clone_prefix)
add_clone_urls(fn, ctx.cfg.clone_prefix, ctx.repo->url);
}
@@ -1019,14 +1021,14 @@ static const char *hc(const char *page)
}
/* Build a context-sensitive tab title such as "Commit history of <path>".
- * fmt() aborts the request rather than truncate, so fall back to the plain
+ * cgit_fmt() aborts the request rather than truncate, so fall back to the plain
* label when the path is long enough to risk overflowing its buffer. */
static const char *tab_title(const char *format, const char *generic,
const char *vpath)
{
if (!vpath || !*vpath || strlen(vpath) > 256)
return generic;
- return fmt(format, vpath);
+ return cgit_fmt(format, vpath);
}
static void cgit_print_path_crumbs(char *path)
@@ -1054,7 +1056,7 @@ static void cgit_print_path_crumbs(char *path)
static void print_header(void)
{
- char *logo = NULL, *logo_link = NULL;
+ const char *logo = NULL, *logo_link = NULL;
if (ctx.repo && ctx.repo->logo && *ctx.repo->logo)
logo = ctx.repo->logo;
@@ -1277,11 +1279,11 @@ void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base,
* name starts with {v,V}[0-9] and the prettify mapping is injective,
* i.e. each stripped tag can be inverted without ambiguities.
*/
- if (repo_get_oid(the_repository, fmt("refs/tags/%s", ref), &oid) == 0 &&
+ if (repo_get_oid(the_repository, cgit_fmt("refs/tags/%s", ref), &oid) == 0 &&
(ref[0] == 'v' || ref[0] == 'V') && isdigit((unsigned char)ref[1]) &&
- ((repo_get_oid(the_repository, fmt("refs/tags/%s", ref + 1), &oid) == 0) +
- (repo_get_oid(the_repository, fmt("refs/tags/v%s", ref + 1), &oid) == 0) +
- (repo_get_oid(the_repository, fmt("refs/tags/V%s", ref + 1), &oid) == 0) == 1))
+ ((repo_get_oid(the_repository, cgit_fmt("refs/tags/%s", ref + 1), &oid) == 0) +
+ (repo_get_oid(the_repository, cgit_fmt("refs/tags/v%s", ref + 1), &oid) == 0) +
+ (repo_get_oid(the_repository, cgit_fmt("refs/tags/V%s", ref + 1), &oid) == 0) == 1))
ref++;
strbuf_addf(filename, "%s-%s", base, ref);
diff --git a/source/ui-shared.h b/source/ui-shared.h
index 2a3a7f5..b6f2797 100644
--- a/source/ui-shared.h
+++ b/source/ui-shared.h
@@ -65,7 +65,7 @@ __attribute__((format (printf,1,2)))
extern void cgit_print_error(const char *fmt, ...);
__attribute__((format (printf,1,0)))
extern void cgit_vprint_error(const char *fmt, va_list ap);
-extern const struct date_mode cgit_date_mode(enum date_mode_type type);
+extern struct date_mode cgit_date_mode(enum date_mode_type type);
extern void cgit_print_age(time_t t, int tz, time_t max_relative);
extern void cgit_print_http_headers(void);
extern void cgit_redirect(const char *url, bool permanent);
diff --git a/source/ui-snapshot.c b/source/ui-snapshot.c
index 5dc4fec..97472c5 100644
--- a/source/ui-snapshot.c
+++ b/source/ui-snapshot.c
@@ -149,7 +149,7 @@ static const struct cgit_snapshot_format *get_format(const char *filename)
return NULL;
}
-const unsigned cgit_snapshot_format_bit(const struct cgit_snapshot_format *f)
+unsigned cgit_snapshot_format_bit(const struct cgit_snapshot_format *f)
{
return BIT(f - &cgit_snapshot_formats[0]);
}
diff --git a/source/ui-ssdiff.c b/source/ui-ssdiff.c
index ed5a2f4..750dc3d 100644
--- a/source/ui-ssdiff.c
+++ b/source/ui-ssdiff.c
@@ -218,7 +218,7 @@ static void print_part_with_lcs(char *class, char *line, char *lcs)
html("</span>");
}
-static void print_ssdiff_line(char *class,
+static void print_ssdiff_line(const char *class,
int old_line_no,
char *old_line,
int new_line_no,
@@ -235,8 +235,8 @@ static void print_ssdiff_line(char *class,
html("<tr>\n");
if (old_line_no > 0) {
struct diff_filespec *old_file = cgit_get_current_old_file();
- char *lineno_str = fmt("n%d", old_line_no);
- char *id_str = fmt("id=%s#%s", is_null_oid(&old_file->oid)?"HEAD":oid_to_hex(old_rev_oid), lineno_str);
+ char *lineno_str = cgit_fmt("n%d", old_line_no);
+ char *id_str = cgit_fmt("id=%s#%s", is_null_oid(&old_file->oid)?"HEAD":oid_to_hex(old_rev_oid), lineno_str);
struct strbuf path = STRBUF_INIT;
char *fileurl;
// The file path is repository content, so percent-encode it
@@ -265,8 +265,8 @@ static void print_ssdiff_line(char *class,
html("</td>\n");
if (new_line_no > 0) {
struct diff_filespec *new_file = cgit_get_current_new_file();
- char *lineno_str = fmt("n%d", new_line_no);
- char *id_str = fmt("id=%s#%s", is_null_oid(&new_file->oid)?"HEAD":oid_to_hex(new_rev_oid), lineno_str);
+ char *lineno_str = cgit_fmt("n%d", new_line_no);
+ char *id_str = cgit_fmt("id=%s#%s", is_null_oid(&new_file->oid)?"HEAD":oid_to_hex(new_rev_oid), lineno_str);
struct strbuf path = STRBUF_INIT;
char *fileurl;
// The file path is repository content, so percent-encode it
diff --git a/source/ui-stats.c b/source/ui-stats.c
index 3ae3034..4c83cf3 100644
--- a/source/ui-stats.c
+++ b/source/ui-stats.c
@@ -79,7 +79,7 @@ static char *pretty_month(struct tm *tm)
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
- return fmt("%s %d", months[tm->tm_mon], tm->tm_year + 1900);
+ return cgit_fmt("%s %d", months[tm->tm_mon], tm->tm_year + 1900);
}
static void trunc_quarter(struct tm *tm)
@@ -105,7 +105,7 @@ static void inc_quarter(struct tm *tm)
static char *pretty_quarter(struct tm *tm)
{
- return fmt("Q%d %d", tm->tm_mon / 3 + 1, tm->tm_year + 1900);
+ return cgit_fmt("Q%d %d", tm->tm_mon / 3 + 1, tm->tm_year + 1900);
}
static void trunc_year(struct tm *tm)
@@ -126,7 +126,7 @@ static void inc_year(struct tm *tm)
static char *pretty_year(struct tm *tm)
{
- return fmt("%d", tm->tm_year + 1900);
+ return cgit_fmt("%d", tm->tm_year + 1900);
}
static const struct cgit_period periods[] = {
@@ -142,7 +142,7 @@ static const struct cgit_period periods[] = {
*/
int cgit_find_stats_period(const char *expr, const struct cgit_period **period)
{
- int i;
+ size_t i;
char code = '\0';
if (!expr)
@@ -151,7 +151,7 @@ int cgit_find_stats_period(const char *expr, const struct cgit_period **period)
if (strlen(expr) == 1)
code = expr[0];
- for (i = 0; i < sizeof(periods) / sizeof(periods[0]); i++)
+ for (i = 0; i < ARRAY_SIZE(periods); i++)
if (periods[i].code == code || !strcmp(periods[i].name, expr)) {
if (period)
*period = &periods[i];
@@ -259,7 +259,7 @@ static struct string_list collect_stats(const struct cgit_period *period)
while ((commit = get_revision(&rev)) != NULL) {
struct commitinfo *info = cgit_parse_commit(commit);
- if (info->committer_date >= since)
+ if ((time_t)info->committer_date >= since)
add_commit(&authors, info, period);
cgit_free_commitinfo(info);
@@ -293,7 +293,7 @@ static void print_combined_authorrow(struct string_list *authors, int from,
total = 0;
htmlf("<tr><td class='%s'>%s</td>", leftclass,
- fmt(name, to - from + 1));
+ cgit_fmt(name, to - from + 1));
for (j = 0; j < period->count; j++) {
tmp = period->pretty(&tm);
period->inc(&tm);
@@ -484,7 +484,8 @@ static void print_language_row(const char *label, unsigned long bytes,
static void print_languages(struct lang_walk_ctx *lw)
{
unsigned long other;
- int i, shown;
+ size_t i;
+ int shown;
if (!lw->total)
return;
@@ -574,8 +575,8 @@ void cgit_show_stats(void)
html("<tr><td class='label'>Period:</td>");
html("<td class='ctrl'><select name='period' data-autosubmit='1'>");
for (i = 0; i < nperiods; i++)
- html_option(fmt("%c", periods[i].code),
- periods[i].name, fmt("%c", period->code));
+ html_option(cgit_fmt("%c", periods[i].code),
+ periods[i].name, cgit_fmt("%c", period->code));
html("</select></td></tr>");
}
html("<tr><td class='label'>Authors:</td>");
diff --git a/source/ui-summary.c b/source/ui-summary.c
index 80d1e5b..2169048 100644
--- a/source/ui-summary.c
+++ b/source/ui-summary.c
@@ -81,7 +81,7 @@ static char* append_readme_path(const char *filename, const char *ref, const cha
}
full_path = xstrdup(path);
} else
- full_path = fmtalloc("%s/%s", base_dir, path);
+ full_path = cgit_fmtalloc("%s/%s", base_dir, path);
if (!ref) {
resolved_base = realpath(base_dir, NULL);
@@ -110,7 +110,7 @@ void cgit_print_repo_readme(const char *path)
char *filename, *ref, *mimetype;
int free_filename = 0;
- mimetype = get_mimetype_for_filename(path);
+ mimetype = cgit_get_mimetype_for_filename(path);
if (mimetype && (!strncmp(mimetype, "image/", 6) || !strncmp(mimetype, "video/", 6))) {
ctx.page.mimetype = mimetype;
ctx.page.charset = NULL;
diff --git a/source/ui-tree.c b/source/ui-tree.c
index 870ace2..b5a5556 100644
--- a/source/ui-tree.c
+++ b/source/ui-tree.c
@@ -161,19 +161,21 @@ struct single_tree_ctx {
static int single_tree_cb(const struct object_id *oid, struct strbuf *base,
const char *pathname, unsigned mode, void *cbdata)
{
- struct single_tree_ctx *ctx = cbdata;
+ // Not named ctx: that is the global request context, and shadowing it
+ // here would hide it from anything added to this function later.
+ struct single_tree_ctx *tree_ctx = cbdata;
- if (++ctx->count > 1)
+ if (++tree_ctx->count > 1)
return -1;
if (!S_ISDIR(mode)) {
- ctx->count = 2;
+ tree_ctx->count = 2;
return -1;
}
- ctx->name = xstrdup(pathname);
- oidcpy(&ctx->oid, oid);
- strbuf_addf(ctx->path, "/%s", pathname);
+ tree_ctx->name = xstrdup(pathname);
+ oidcpy(&tree_ctx->oid, oid);
+ strbuf_addf(tree_ctx->path, "/%s", pathname);
return 0;
}