summaryrefslogtreecommitdiffabout
path: root/shared.c
Unidiff
Diffstat (limited to 'shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--shared.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/shared.c b/shared.c
index f20fb5c..f7f43b2 100644
--- a/shared.c
+++ b/shared.c
@@ -1,142 +1,144 @@
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 repolist cgit_repolist; 11struct repolist cgit_repolist;
12struct repoinfo *cgit_repo; 12struct repoinfo *cgit_repo;
13int cgit_cmd; 13int cgit_cmd;
14 14
15const char *cgit_version = CGIT_VERSION;
16
15char *cgit_root_title = "Git repository browser"; 17char *cgit_root_title = "Git repository browser";
16char *cgit_css = "/cgit.css"; 18char *cgit_css = "/cgit.css";
17char *cgit_logo = "/git-logo.png"; 19char *cgit_logo = "/git-logo.png";
18char *cgit_index_header = NULL; 20char *cgit_index_header = NULL;
19char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; 21char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/";
20char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; 22char *cgit_module_link = "./?repo=%s&page=commit&id=%s";
21char *cgit_agefile = "info/web/last-modified"; 23char *cgit_agefile = "info/web/last-modified";
22char *cgit_virtual_root = NULL; 24char *cgit_virtual_root = NULL;
23char *cgit_script_name = CGIT_SCRIPT_NAME; 25char *cgit_script_name = CGIT_SCRIPT_NAME;
24char *cgit_cache_root = "/var/cache/cgit"; 26char *cgit_cache_root = "/var/cache/cgit";
25char *cgit_repo_group = NULL; 27char *cgit_repo_group = NULL;
26 28
27int cgit_nocache = 0; 29int cgit_nocache = 0;
28int cgit_snapshots = 0; 30int cgit_snapshots = 0;
29int cgit_enable_log_filecount = 0; 31int cgit_enable_log_filecount = 0;
30int cgit_enable_log_linecount = 0; 32int cgit_enable_log_linecount = 0;
31int cgit_max_lock_attempts = 5; 33int cgit_max_lock_attempts = 5;
32int cgit_cache_root_ttl = 5; 34int cgit_cache_root_ttl = 5;
33int cgit_cache_repo_ttl = 5; 35int cgit_cache_repo_ttl = 5;
34int cgit_cache_dynamic_ttl = 5; 36int cgit_cache_dynamic_ttl = 5;
35int cgit_cache_static_ttl = -1; 37int cgit_cache_static_ttl = -1;
36int cgit_cache_max_create_time = 5; 38int cgit_cache_max_create_time = 5;
37int cgit_summary_log = 0; 39int cgit_summary_log = 0;
38 40
39int cgit_max_msg_len = 60; 41int cgit_max_msg_len = 60;
40int cgit_max_repodesc_len = 60; 42int cgit_max_repodesc_len = 60;
41int cgit_max_commit_count = 50; 43int cgit_max_commit_count = 50;
42 44
43int cgit_query_has_symref = 0; 45int cgit_query_has_symref = 0;
44int cgit_query_has_sha1 = 0; 46int cgit_query_has_sha1 = 0;
45 47
46char *cgit_querystring = NULL; 48char *cgit_querystring = NULL;
47char *cgit_query_repo = NULL; 49char *cgit_query_repo = NULL;
48char *cgit_query_page = NULL; 50char *cgit_query_page = NULL;
49char *cgit_query_head = NULL; 51char *cgit_query_head = NULL;
50char *cgit_query_search = NULL; 52char *cgit_query_search = NULL;
51char *cgit_query_sha1 = NULL; 53char *cgit_query_sha1 = NULL;
52char *cgit_query_sha2 = NULL; 54char *cgit_query_sha2 = NULL;
53char *cgit_query_path = NULL; 55char *cgit_query_path = NULL;
54char *cgit_query_name = NULL; 56char *cgit_query_name = NULL;
55int cgit_query_ofs = 0; 57int cgit_query_ofs = 0;
56 58
57int htmlfd = 0; 59int htmlfd = 0;
58 60
59 61
60int cgit_get_cmd_index(const char *cmd) 62int cgit_get_cmd_index(const char *cmd)
61{ 63{
62 static char *cmds[] = {"log", "commit", "diff", "tree", "blob", 64 static char *cmds[] = {"log", "commit", "diff", "tree", "blob",
63 "snapshot", NULL}; 65 "snapshot", NULL};
64 int i; 66 int i;
65 67
66 for(i = 0; cmds[i]; i++) 68 for(i = 0; cmds[i]; i++)
67 if (!strcmp(cmd, cmds[i])) 69 if (!strcmp(cmd, cmds[i]))
68 return i + 1; 70 return i + 1;
69 return 0; 71 return 0;
70} 72}
71 73
72int chk_zero(int result, char *msg) 74int chk_zero(int result, char *msg)
73{ 75{
74 if (result != 0) 76 if (result != 0)
75 die("%s: %s", msg, strerror(errno)); 77 die("%s: %s", msg, strerror(errno));
76 return result; 78 return result;
77} 79}
78 80
79int chk_positive(int result, char *msg) 81int chk_positive(int result, char *msg)
80{ 82{
81 if (result <= 0) 83 if (result <= 0)
82 die("%s: %s", msg, strerror(errno)); 84 die("%s: %s", msg, strerror(errno));
83 return result; 85 return result;
84} 86}
85 87
86struct repoinfo *add_repo(const char *url) 88struct repoinfo *add_repo(const char *url)
87{ 89{
88 struct repoinfo *ret; 90 struct repoinfo *ret;
89 91
90 if (++cgit_repolist.count > cgit_repolist.length) { 92 if (++cgit_repolist.count > cgit_repolist.length) {
91 if (cgit_repolist.length == 0) 93 if (cgit_repolist.length == 0)
92 cgit_repolist.length = 8; 94 cgit_repolist.length = 8;
93 else 95 else
94 cgit_repolist.length *= 2; 96 cgit_repolist.length *= 2;
95 cgit_repolist.repos = xrealloc(cgit_repolist.repos, 97 cgit_repolist.repos = xrealloc(cgit_repolist.repos,
96 cgit_repolist.length * 98 cgit_repolist.length *
97 sizeof(struct repoinfo)); 99 sizeof(struct repoinfo));
98 } 100 }
99 101
100 ret = &cgit_repolist.repos[cgit_repolist.count-1]; 102 ret = &cgit_repolist.repos[cgit_repolist.count-1];
101 ret->url = xstrdup(url); 103 ret->url = xstrdup(url);
102 ret->name = ret->url; 104 ret->name = ret->url;
103 ret->path = NULL; 105 ret->path = NULL;
104 ret->desc = NULL; 106 ret->desc = NULL;
105 ret->owner = NULL; 107 ret->owner = NULL;
106 ret->group = cgit_repo_group; 108 ret->group = cgit_repo_group;
107 ret->defbranch = "master"; 109 ret->defbranch = "master";
108 ret->snapshots = cgit_snapshots; 110 ret->snapshots = cgit_snapshots;
109 ret->enable_log_filecount = cgit_enable_log_filecount; 111 ret->enable_log_filecount = cgit_enable_log_filecount;
110 ret->enable_log_linecount = cgit_enable_log_linecount; 112 ret->enable_log_linecount = cgit_enable_log_linecount;
111 ret->module_link = cgit_module_link; 113 ret->module_link = cgit_module_link;
112 ret->readme = NULL; 114 ret->readme = NULL;
113 return ret; 115 return ret;
114} 116}
115 117
116struct repoinfo *cgit_get_repoinfo(const char *url) 118struct repoinfo *cgit_get_repoinfo(const char *url)
117{ 119{
118 int i; 120 int i;
119 struct repoinfo *repo; 121 struct repoinfo *repo;
120 122
121 for (i=0; i<cgit_repolist.count; i++) { 123 for (i=0; i<cgit_repolist.count; i++) {
122 repo = &cgit_repolist.repos[i]; 124 repo = &cgit_repolist.repos[i];
123 if (!strcmp(repo->url, url)) 125 if (!strcmp(repo->url, url))
124 return repo; 126 return repo;
125 } 127 }
126 return NULL; 128 return NULL;
127} 129}
128 130
129void cgit_global_config_cb(const char *name, const char *value) 131void cgit_global_config_cb(const char *name, const char *value)
130{ 132{
131 if (!strcmp(name, "root-title")) 133 if (!strcmp(name, "root-title"))
132 cgit_root_title = xstrdup(value); 134 cgit_root_title = xstrdup(value);
133 else if (!strcmp(name, "css")) 135 else if (!strcmp(name, "css"))
134 cgit_css = xstrdup(value); 136 cgit_css = xstrdup(value);
135 else if (!strcmp(name, "logo")) 137 else if (!strcmp(name, "logo"))
136 cgit_logo = xstrdup(value); 138 cgit_logo = xstrdup(value);
137 else if (!strcmp(name, "index-header")) 139 else if (!strcmp(name, "index-header"))
138 cgit_index_header = xstrdup(value); 140 cgit_index_header = xstrdup(value);
139 else if (!strcmp(name, "logo-link")) 141 else if (!strcmp(name, "logo-link"))
140 cgit_logo_link = xstrdup(value); 142 cgit_logo_link = xstrdup(value);
141 else if (!strcmp(name, "module-link")) 143 else if (!strcmp(name, "module-link"))
142 cgit_module_link = xstrdup(value); 144 cgit_module_link = xstrdup(value);