diff options
context:
space:
mode:
Diffstat (limited to 'source/ui-shared.c')
-rw-r--r--source/ui-shared.c68
1 file changed, 35 insertions, 33 deletions
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);