summaryrefslogtreecommitdiffabout
path: root/shared.c
Unidiff
Diffstat (limited to 'shared.c') (more/less context) (show whitespace changes)
-rw-r--r--shared.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/shared.c b/shared.c
index 76e10d0..539d533 100644
--- a/shared.c
+++ b/shared.c
@@ -1,85 +1,88 @@
1/* shared.c: global vars + some callback functions 1/* shared.c: global vars + some callback functions
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10 10
11struct cgit_repolist cgit_repolist; 11struct cgit_repolist cgit_repolist;
12struct cgit_context ctx; 12struct cgit_context ctx;
13int cgit_cmd; 13int cgit_cmd;
14 14
15const char *cgit_version = CGIT_VERSION; 15const char *cgit_version = CGIT_VERSION;
16 16
17void cgit_prepare_context(struct cgit_context *ctx) 17void cgit_prepare_context(struct cgit_context *ctx)
18{ 18{
19 memset(ctx, 0, sizeof(ctx)); 19 memset(ctx, 0, sizeof(ctx));
20 ctx->cfg.agefile = "info/web/last-modified"; 20 ctx->cfg.agefile = "info/web/last-modified";
21 ctx->cfg.cache_dynamic_ttl = 5; 21 ctx->cfg.cache_dynamic_ttl = 5;
22 ctx->cfg.cache_max_create_time = 5; 22 ctx->cfg.cache_max_create_time = 5;
23 ctx->cfg.cache_repo_ttl = 5; 23 ctx->cfg.cache_repo_ttl = 5;
24 ctx->cfg.cache_root = CGIT_CACHE_ROOT; 24 ctx->cfg.cache_root = CGIT_CACHE_ROOT;
25 ctx->cfg.cache_root_ttl = 5; 25 ctx->cfg.cache_root_ttl = 5;
26 ctx->cfg.cache_static_ttl = -1; 26 ctx->cfg.cache_static_ttl = -1;
27 ctx->cfg.css = "/cgit.css"; 27 ctx->cfg.css = "/cgit.css";
28 ctx->cfg.logo = "/git-logo.png"; 28 ctx->cfg.logo = "/git-logo.png";
29 ctx->cfg.max_commit_count = 50; 29 ctx->cfg.max_commit_count = 50;
30 ctx->cfg.max_lock_attempts = 5; 30 ctx->cfg.max_lock_attempts = 5;
31 ctx->cfg.max_msg_len = 60; 31 ctx->cfg.max_msg_len = 60;
32 ctx->cfg.max_repodesc_len = 60; 32 ctx->cfg.max_repodesc_len = 60;
33 ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; 33 ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s";
34 ctx->cfg.renamelimit = -1; 34 ctx->cfg.renamelimit = -1;
35 ctx->cfg.robots = "index, nofollow"; 35 ctx->cfg.robots = "index, nofollow";
36 ctx->cfg.root_title = "Git repository browser"; 36 ctx->cfg.root_title = "Git repository browser";
37 ctx->cfg.script_name = CGIT_SCRIPT_NAME; 37 ctx->cfg.script_name = CGIT_SCRIPT_NAME;
38 ctx->page.mimetype = "text/html";
39 ctx->page.charset = PAGE_ENCODING;
40 ctx->page.filename = NULL;
38} 41}
39 42
40int cgit_get_cmd_index(const char *cmd) 43int cgit_get_cmd_index(const char *cmd)
41{ 44{
42 static char *cmds[] = {"log", "commit", "diff", "tree", "blob", 45 static char *cmds[] = {"log", "commit", "diff", "tree", "blob",
43 "snapshot", "tag", "refs", "patch", NULL}; 46 "snapshot", "tag", "refs", "patch", NULL};
44 int i; 47 int i;
45 48
46 for(i = 0; cmds[i]; i++) 49 for(i = 0; cmds[i]; i++)
47 if (!strcmp(cmd, cmds[i])) 50 if (!strcmp(cmd, cmds[i]))
48 return i + 1; 51 return i + 1;
49 return 0; 52 return 0;
50} 53}
51 54
52int chk_zero(int result, char *msg) 55int chk_zero(int result, char *msg)
53{ 56{
54 if (result != 0) 57 if (result != 0)
55 die("%s: %s", msg, strerror(errno)); 58 die("%s: %s", msg, strerror(errno));
56 return result; 59 return result;
57} 60}
58 61
59int chk_positive(int result, char *msg) 62int chk_positive(int result, char *msg)
60{ 63{
61 if (result <= 0) 64 if (result <= 0)
62 die("%s: %s", msg, strerror(errno)); 65 die("%s: %s", msg, strerror(errno));
63 return result; 66 return result;
64} 67}
65 68
66int chk_non_negative(int result, char *msg) 69int chk_non_negative(int result, char *msg)
67{ 70{
68 if (result < 0) 71 if (result < 0)
69 die("%s: %s",msg, strerror(errno)); 72 die("%s: %s",msg, strerror(errno));
70 return result; 73 return result;
71} 74}
72 75
73struct cgit_repo *add_repo(const char *url) 76struct cgit_repo *add_repo(const char *url)
74{ 77{
75 struct cgit_repo *ret; 78 struct cgit_repo *ret;
76 79
77 if (++cgit_repolist.count > cgit_repolist.length) { 80 if (++cgit_repolist.count > cgit_repolist.length) {
78 if (cgit_repolist.length == 0) 81 if (cgit_repolist.length == 0)
79 cgit_repolist.length = 8; 82 cgit_repolist.length = 8;
80 else 83 else
81 cgit_repolist.length *= 2; 84 cgit_repolist.length *= 2;
82 cgit_repolist.repos = xrealloc(cgit_repolist.repos, 85 cgit_repolist.repos = xrealloc(cgit_repolist.repos,
83 cgit_repolist.length * 86 cgit_repolist.length *
84 sizeof(struct cgit_repo)); 87 sizeof(struct cgit_repo));
85 } 88 }