-rw-r--r-- | cache.c | 6 | ||||
-rw-r--r-- | cgit.c | 31 | ||||
-rw-r--r-- | cgit.h | 12 | ||||
-rw-r--r-- | parsing.c | 16 | ||||
-rw-r--r-- | shared.c | 61 | ||||
-rw-r--r-- | ui-commit.c | 4 | ||||
-rw-r--r-- | ui-log.c | 10 | ||||
-rw-r--r-- | ui-repolist.c | 30 | ||||
-rw-r--r-- | ui-shared.c | 28 | ||||
-rw-r--r-- | ui-summary.c | 4 | ||||
-rw-r--r-- | ui-tree.c | 2 |
11 files changed, 101 insertions, 103 deletions
@@ -27,60 +27,60 @@ char *cache_safe_filename(const char *unsafe) | |||
27 | c = '_'; | 27 | c = '_'; |
28 | *s++ = c; | 28 | *s++ = c; |
29 | } | 29 | } |
30 | *s = '\0'; | 30 | *s = '\0'; |
31 | return buf[bufidx]; | 31 | return buf[bufidx]; |
32 | } | 32 | } |
33 | 33 | ||
34 | int cache_exist(struct cacheitem *item) | 34 | int cache_exist(struct cacheitem *item) |
35 | { | 35 | { |
36 | if (stat(item->name, &item->st)) { | 36 | if (stat(item->name, &item->st)) { |
37 | item->st.st_mtime = 0; | 37 | item->st.st_mtime = 0; |
38 | return 0; | 38 | return 0; |
39 | } | 39 | } |
40 | return 1; | 40 | return 1; |
41 | } | 41 | } |
42 | 42 | ||
43 | int cache_create_dirs() | 43 | int cache_create_dirs() |
44 | { | 44 | { |
45 | char *path; | 45 | char *path; |
46 | 46 | ||
47 | path = fmt("%s", ctx.cfg.cache_root); | 47 | path = fmt("%s", ctx.cfg.cache_root); |
48 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) | 48 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
49 | return 0; | 49 | return 0; |
50 | 50 | ||
51 | if (!cgit_repo) | 51 | if (!ctx.repo) |
52 | return 0; | 52 | return 0; |
53 | 53 | ||
54 | path = fmt("%s/%s", ctx.cfg.cache_root, | 54 | path = fmt("%s/%s", ctx.cfg.cache_root, |
55 | cache_safe_filename(cgit_repo->url)); | 55 | cache_safe_filename(ctx.repo->url)); |
56 | 56 | ||
57 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) | 57 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
58 | return 0; | 58 | return 0; |
59 | 59 | ||
60 | if (ctx.qry.page) { | 60 | if (ctx.qry.page) { |
61 | path = fmt("%s/%s/%s", ctx.cfg.cache_root, | 61 | path = fmt("%s/%s/%s", ctx.cfg.cache_root, |
62 | cache_safe_filename(cgit_repo->url), | 62 | cache_safe_filename(ctx.repo->url), |
63 | ctx.qry.page); | 63 | ctx.qry.page); |
64 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) | 64 | if (mkdir(path, S_IRWXU) && errno!=EEXIST) |
65 | return 0; | 65 | return 0; |
66 | } | 66 | } |
67 | return 1; | 67 | return 1; |
68 | } | 68 | } |
69 | 69 | ||
70 | int cache_refill_overdue(const char *lockfile) | 70 | int cache_refill_overdue(const char *lockfile) |
71 | { | 71 | { |
72 | struct stat st; | 72 | struct stat st; |
73 | 73 | ||
74 | if (stat(lockfile, &st)) | 74 | if (stat(lockfile, &st)) |
75 | return 0; | 75 | return 0; |
76 | else | 76 | else |
77 | return (time(NULL) - st.st_mtime > ctx.cfg.cache_max_create_time); | 77 | return (time(NULL) - st.st_mtime > ctx.cfg.cache_max_create_time); |
78 | } | 78 | } |
79 | 79 | ||
80 | int cache_lock(struct cacheitem *item) | 80 | int cache_lock(struct cacheitem *item) |
81 | { | 81 | { |
82 | int i = 0; | 82 | int i = 0; |
83 | char *lockfile = xstrdup(fmt("%s.lock", item->name)); | 83 | char *lockfile = xstrdup(fmt("%s.lock", item->name)); |
84 | 84 | ||
85 | top: | 85 | top: |
86 | if (++i > ctx.cfg.max_lock_attempts) | 86 | if (++i > ctx.cfg.max_lock_attempts) |
@@ -1,152 +1,152 @@ | |||
1 | /* cgit.c: cgi for the git scm | 1 | /* cgit.c: cgi for the git scm |
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 | ||
11 | static int cgit_prepare_cache(struct cacheitem *item) | 11 | static int cgit_prepare_cache(struct cacheitem *item) |
12 | { | 12 | { |
13 | if (!cgit_repo && ctx.qry.repo) { | 13 | if (!ctx.repo && ctx.qry.repo) { |
14 | char *title = fmt("%s - %s", ctx.cfg.root_title, "Bad request"); | 14 | char *title = fmt("%s - %s", ctx.cfg.root_title, "Bad request"); |
15 | cgit_print_docstart(title, item); | 15 | cgit_print_docstart(title, item); |
16 | cgit_print_pageheader(title, 0); | 16 | cgit_print_pageheader(title, 0); |
17 | cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo)); | 17 | cgit_print_error(fmt("Unknown repo: %s", ctx.qry.repo)); |
18 | cgit_print_docend(); | 18 | cgit_print_docend(); |
19 | return 0; | 19 | return 0; |
20 | } | 20 | } |
21 | 21 | ||
22 | if (!cgit_repo) { | 22 | if (!ctx.repo) { |
23 | item->name = xstrdup(fmt("%s/index.html", ctx.cfg.cache_root)); | 23 | item->name = xstrdup(fmt("%s/index.html", ctx.cfg.cache_root)); |
24 | item->ttl = ctx.cfg.cache_root_ttl; | 24 | item->ttl = ctx.cfg.cache_root_ttl; |
25 | return 1; | 25 | return 1; |
26 | } | 26 | } |
27 | 27 | ||
28 | if (!cgit_cmd) { | 28 | if (!cgit_cmd) { |
29 | item->name = xstrdup(fmt("%s/%s/index.%s.html", ctx.cfg.cache_root, | 29 | item->name = xstrdup(fmt("%s/%s/index.%s.html", ctx.cfg.cache_root, |
30 | cache_safe_filename(cgit_repo->url), | 30 | cache_safe_filename(ctx.repo->url), |
31 | cache_safe_filename(ctx.qry.raw))); | 31 | cache_safe_filename(ctx.qry.raw))); |
32 | item->ttl = ctx.cfg.cache_repo_ttl; | 32 | item->ttl = ctx.cfg.cache_repo_ttl; |
33 | } else { | 33 | } else { |
34 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", ctx.cfg.cache_root, | 34 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", ctx.cfg.cache_root, |
35 | cache_safe_filename(cgit_repo->url), | 35 | cache_safe_filename(ctx.repo->url), |
36 | ctx.qry.page, | 36 | ctx.qry.page, |
37 | cache_safe_filename(ctx.qry.raw))); | 37 | cache_safe_filename(ctx.qry.raw))); |
38 | if (ctx.qry.has_symref) | 38 | if (ctx.qry.has_symref) |
39 | item->ttl = ctx.cfg.cache_dynamic_ttl; | 39 | item->ttl = ctx.cfg.cache_dynamic_ttl; |
40 | else if (ctx.qry.has_sha1) | 40 | else if (ctx.qry.has_sha1) |
41 | item->ttl = ctx.cfg.cache_static_ttl; | 41 | item->ttl = ctx.cfg.cache_static_ttl; |
42 | else | 42 | else |
43 | item->ttl = ctx.cfg.cache_repo_ttl; | 43 | item->ttl = ctx.cfg.cache_repo_ttl; |
44 | } | 44 | } |
45 | return 1; | 45 | return 1; |
46 | } | 46 | } |
47 | 47 | ||
48 | struct refmatch { | 48 | struct refmatch { |
49 | char *req_ref; | 49 | char *req_ref; |
50 | char *first_ref; | 50 | char *first_ref; |
51 | int match; | 51 | int match; |
52 | }; | 52 | }; |
53 | 53 | ||
54 | int find_current_ref(const char *refname, const unsigned char *sha1, | 54 | int find_current_ref(const char *refname, const unsigned char *sha1, |
55 | int flags, void *cb_data) | 55 | int flags, void *cb_data) |
56 | { | 56 | { |
57 | struct refmatch *info; | 57 | struct refmatch *info; |
58 | 58 | ||
59 | info = (struct refmatch *)cb_data; | 59 | info = (struct refmatch *)cb_data; |
60 | if (!strcmp(refname, info->req_ref)) | 60 | if (!strcmp(refname, info->req_ref)) |
61 | info->match = 1; | 61 | info->match = 1; |
62 | if (!info->first_ref) | 62 | if (!info->first_ref) |
63 | info->first_ref = xstrdup(refname); | 63 | info->first_ref = xstrdup(refname); |
64 | return info->match; | 64 | return info->match; |
65 | } | 65 | } |
66 | 66 | ||
67 | char *find_default_branch(struct repoinfo *repo) | 67 | char *find_default_branch(struct cgit_repo *repo) |
68 | { | 68 | { |
69 | struct refmatch info; | 69 | struct refmatch info; |
70 | 70 | ||
71 | info.req_ref = repo->defbranch; | 71 | info.req_ref = repo->defbranch; |
72 | info.first_ref = NULL; | 72 | info.first_ref = NULL; |
73 | info.match = 0; | 73 | info.match = 0; |
74 | for_each_branch_ref(find_current_ref, &info); | 74 | for_each_branch_ref(find_current_ref, &info); |
75 | if (info.match) | 75 | if (info.match) |
76 | return info.req_ref; | 76 | return info.req_ref; |
77 | else | 77 | else |
78 | return info.first_ref; | 78 | return info.first_ref; |
79 | } | 79 | } |
80 | 80 | ||
81 | static void cgit_print_repo_page(struct cacheitem *item) | 81 | static void cgit_print_repo_page(struct cacheitem *item) |
82 | { | 82 | { |
83 | char *title, *tmp; | 83 | char *title, *tmp; |
84 | int show_search; | 84 | int show_search; |
85 | unsigned char sha1[20]; | 85 | unsigned char sha1[20]; |
86 | 86 | ||
87 | if (chdir(cgit_repo->path)) { | 87 | if (chdir(ctx.repo->path)) { |
88 | title = fmt("%s - %s", ctx.cfg.root_title, "Bad request"); | 88 | title = fmt("%s - %s", ctx.cfg.root_title, "Bad request"); |
89 | cgit_print_docstart(title, item); | 89 | cgit_print_docstart(title, item); |
90 | cgit_print_pageheader(title, 0); | 90 | cgit_print_pageheader(title, 0); |
91 | cgit_print_error(fmt("Unable to scan repository: %s", | 91 | cgit_print_error(fmt("Unable to scan repository: %s", |
92 | strerror(errno))); | 92 | strerror(errno))); |
93 | cgit_print_docend(); | 93 | cgit_print_docend(); |
94 | return; | 94 | return; |
95 | } | 95 | } |
96 | 96 | ||
97 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); | 97 | title = fmt("%s - %s", ctx.repo->name, ctx.repo->desc); |
98 | show_search = 0; | 98 | show_search = 0; |
99 | setenv("GIT_DIR", cgit_repo->path, 1); | 99 | setenv("GIT_DIR", ctx.repo->path, 1); |
100 | 100 | ||
101 | if (!ctx.qry.head) { | 101 | if (!ctx.qry.head) { |
102 | ctx.qry.head = xstrdup(find_default_branch(cgit_repo)); | 102 | ctx.qry.head = xstrdup(find_default_branch(ctx.repo)); |
103 | cgit_repo->defbranch = ctx.qry.head; | 103 | ctx.repo->defbranch = ctx.qry.head; |
104 | } | 104 | } |
105 | 105 | ||
106 | if (!ctx.qry.head) { | 106 | if (!ctx.qry.head) { |
107 | cgit_print_docstart(title, item); | 107 | cgit_print_docstart(title, item); |
108 | cgit_print_pageheader(title, 0); | 108 | cgit_print_pageheader(title, 0); |
109 | cgit_print_error("Repository seems to be empty"); | 109 | cgit_print_error("Repository seems to be empty"); |
110 | cgit_print_docend(); | 110 | cgit_print_docend(); |
111 | return; | 111 | return; |
112 | } | 112 | } |
113 | 113 | ||
114 | if (get_sha1(ctx.qry.head, sha1)) { | 114 | if (get_sha1(ctx.qry.head, sha1)) { |
115 | tmp = xstrdup(ctx.qry.head); | 115 | tmp = xstrdup(ctx.qry.head); |
116 | ctx.qry.head = cgit_repo->defbranch; | 116 | ctx.qry.head = ctx.repo->defbranch; |
117 | cgit_print_docstart(title, item); | 117 | cgit_print_docstart(title, item); |
118 | cgit_print_pageheader(title, 0); | 118 | cgit_print_pageheader(title, 0); |
119 | cgit_print_error(fmt("Invalid branch: %s", tmp)); | 119 | cgit_print_error(fmt("Invalid branch: %s", tmp)); |
120 | cgit_print_docend(); | 120 | cgit_print_docend(); |
121 | return; | 121 | return; |
122 | } | 122 | } |
123 | 123 | ||
124 | if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { | 124 | if ((cgit_cmd == CMD_SNAPSHOT) && ctx.repo->snapshots) { |
125 | cgit_print_snapshot(item, ctx.qry.head, ctx.qry.sha1, | 125 | cgit_print_snapshot(item, ctx.qry.head, ctx.qry.sha1, |
126 | cgit_repobasename(cgit_repo->url), | 126 | cgit_repobasename(ctx.repo->url), |
127 | ctx.qry.path, | 127 | ctx.qry.path, |
128 | cgit_repo->snapshots ); | 128 | ctx.repo->snapshots ); |
129 | return; | 129 | return; |
130 | } | 130 | } |
131 | 131 | ||
132 | if (cgit_cmd == CMD_PATCH) { | 132 | if (cgit_cmd == CMD_PATCH) { |
133 | cgit_print_patch(ctx.qry.sha1, item); | 133 | cgit_print_patch(ctx.qry.sha1, item); |
134 | return; | 134 | return; |
135 | } | 135 | } |
136 | 136 | ||
137 | if (cgit_cmd == CMD_BLOB) { | 137 | if (cgit_cmd == CMD_BLOB) { |
138 | cgit_print_blob(item, ctx.qry.sha1, ctx.qry.path); | 138 | cgit_print_blob(item, ctx.qry.sha1, ctx.qry.path); |
139 | return; | 139 | return; |
140 | } | 140 | } |
141 | 141 | ||
142 | show_search = (cgit_cmd == CMD_LOG); | 142 | show_search = (cgit_cmd == CMD_LOG); |
143 | cgit_print_docstart(title, item); | 143 | cgit_print_docstart(title, item); |
144 | if (!cgit_cmd) { | 144 | if (!cgit_cmd) { |
145 | cgit_print_pageheader("summary", show_search); | 145 | cgit_print_pageheader("summary", show_search); |
146 | cgit_print_summary(); | 146 | cgit_print_summary(); |
147 | cgit_print_docend(); | 147 | cgit_print_docend(); |
148 | return; | 148 | return; |
149 | } | 149 | } |
150 | 150 | ||
151 | cgit_print_pageheader(ctx.qry.page, show_search); | 151 | cgit_print_pageheader(ctx.qry.page, show_search); |
152 | 152 | ||
@@ -171,49 +171,49 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
171 | case CMD_DIFF: | 171 | case CMD_DIFF: |
172 | cgit_print_diff(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path); | 172 | cgit_print_diff(ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path); |
173 | break; | 173 | break; |
174 | default: | 174 | default: |
175 | cgit_print_error("Invalid request"); | 175 | cgit_print_error("Invalid request"); |
176 | } | 176 | } |
177 | cgit_print_docend(); | 177 | cgit_print_docend(); |
178 | } | 178 | } |
179 | 179 | ||
180 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) | 180 | static void cgit_fill_cache(struct cacheitem *item, int use_cache) |
181 | { | 181 | { |
182 | static char buf[PATH_MAX]; | 182 | static char buf[PATH_MAX]; |
183 | int stdout2; | 183 | int stdout2; |
184 | 184 | ||
185 | getcwd(buf, sizeof(buf)); | 185 | getcwd(buf, sizeof(buf)); |
186 | item->st.st_mtime = time(NULL); | 186 | item->st.st_mtime = time(NULL); |
187 | 187 | ||
188 | if (use_cache) { | 188 | if (use_cache) { |
189 | stdout2 = chk_positive(dup(STDOUT_FILENO), | 189 | stdout2 = chk_positive(dup(STDOUT_FILENO), |
190 | "Preserving STDOUT"); | 190 | "Preserving STDOUT"); |
191 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); | 191 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT"); |
192 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); | 192 | chk_positive(dup2(item->fd, STDOUT_FILENO), "Dup2(cachefile)"); |
193 | } | 193 | } |
194 | 194 | ||
195 | if (cgit_repo) | 195 | if (ctx.repo) |
196 | cgit_print_repo_page(item); | 196 | cgit_print_repo_page(item); |
197 | else | 197 | else |
198 | cgit_print_repolist(item); | 198 | cgit_print_repolist(item); |
199 | 199 | ||
200 | if (use_cache) { | 200 | if (use_cache) { |
201 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); | 201 | chk_zero(close(STDOUT_FILENO), "Close redirected STDOUT"); |
202 | chk_positive(dup2(stdout2, STDOUT_FILENO), | 202 | chk_positive(dup2(stdout2, STDOUT_FILENO), |
203 | "Restoring original STDOUT"); | 203 | "Restoring original STDOUT"); |
204 | chk_zero(close(stdout2), "Closing temporary STDOUT"); | 204 | chk_zero(close(stdout2), "Closing temporary STDOUT"); |
205 | } | 205 | } |
206 | 206 | ||
207 | chdir(buf); | 207 | chdir(buf); |
208 | } | 208 | } |
209 | 209 | ||
210 | static void cgit_check_cache(struct cacheitem *item) | 210 | static void cgit_check_cache(struct cacheitem *item) |
211 | { | 211 | { |
212 | int i = 0; | 212 | int i = 0; |
213 | 213 | ||
214 | top: | 214 | top: |
215 | if (++i > ctx.cfg.max_lock_attempts) { | 215 | if (++i > ctx.cfg.max_lock_attempts) { |
216 | die("cgit_refresh_cache: unable to lock %s: %s", | 216 | die("cgit_refresh_cache: unable to lock %s: %s", |
217 | item->name, strerror(errno)); | 217 | item->name, strerror(errno)); |
218 | } | 218 | } |
219 | if (!cache_exist(item)) { | 219 | if (!cache_exist(item)) { |
@@ -279,41 +279,40 @@ static void cgit_parse_args(int argc, const char **argv) | |||
279 | if (!strncmp(argv[i], "--sha1=", 7)) { | 279 | if (!strncmp(argv[i], "--sha1=", 7)) { |
280 | ctx.qry.sha1 = xstrdup(argv[i]+7); | 280 | ctx.qry.sha1 = xstrdup(argv[i]+7); |
281 | ctx.qry.has_sha1 = 1; | 281 | ctx.qry.has_sha1 = 1; |
282 | } | 282 | } |
283 | if (!strncmp(argv[i], "--ofs=", 6)) { | 283 | if (!strncmp(argv[i], "--ofs=", 6)) { |
284 | ctx.qry.ofs = atoi(argv[i]+6); | 284 | ctx.qry.ofs = atoi(argv[i]+6); |
285 | } | 285 | } |
286 | } | 286 | } |
287 | } | 287 | } |
288 | 288 | ||
289 | int main(int argc, const char **argv) | 289 | int main(int argc, const char **argv) |
290 | { | 290 | { |
291 | struct cacheitem item; | 291 | struct cacheitem item; |
292 | const char *cgit_config_env = getenv("CGIT_CONFIG"); | 292 | const char *cgit_config_env = getenv("CGIT_CONFIG"); |
293 | 293 | ||
294 | cgit_prepare_context(&ctx); | 294 | cgit_prepare_context(&ctx); |
295 | htmlfd = STDOUT_FILENO; | 295 | htmlfd = STDOUT_FILENO; |
296 | item.st.st_mtime = time(NULL); | 296 | item.st.st_mtime = time(NULL); |
297 | cgit_repolist.length = 0; | 297 | cgit_repolist.length = 0; |
298 | cgit_repolist.count = 0; | 298 | cgit_repolist.count = 0; |
299 | cgit_repolist.repos = NULL; | 299 | cgit_repolist.repos = NULL; |
300 | 300 | ||
301 | cgit_read_config(cgit_config_env ? cgit_config_env : CGIT_CONFIG, | 301 | cgit_read_config(cgit_config_env ? cgit_config_env : CGIT_CONFIG, |
302 | cgit_global_config_cb); | 302 | cgit_global_config_cb); |
303 | cgit_repo = NULL; | ||
304 | if (getenv("SCRIPT_NAME")) | 303 | if (getenv("SCRIPT_NAME")) |
305 | ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); | 304 | ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME")); |
306 | if (getenv("QUERY_STRING")) | 305 | if (getenv("QUERY_STRING")) |
307 | ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); | 306 | ctx.qry.raw = xstrdup(getenv("QUERY_STRING")); |
308 | cgit_parse_args(argc, argv); | 307 | cgit_parse_args(argc, argv); |
309 | cgit_parse_query(ctx.qry.raw, cgit_querystring_cb); | 308 | cgit_parse_query(ctx.qry.raw, cgit_querystring_cb); |
310 | if (!cgit_prepare_cache(&item)) | 309 | if (!cgit_prepare_cache(&item)) |
311 | return 0; | 310 | return 0; |
312 | if (ctx.cfg.nocache) { | 311 | if (ctx.cfg.nocache) { |
313 | cgit_fill_cache(&item, 0); | 312 | cgit_fill_cache(&item, 0); |
314 | } else { | 313 | } else { |
315 | cgit_check_cache(&item); | 314 | cgit_check_cache(&item); |
316 | cgit_print_cache(&item); | 315 | cgit_print_cache(&item); |
317 | } | 316 | } |
318 | return 0; | 317 | return 0; |
319 | } | 318 | } |
@@ -45,68 +45,68 @@ | |||
45 | #define TM_MIN 60 | 45 | #define TM_MIN 60 |
46 | #define TM_HOUR (TM_MIN * 60) | 46 | #define TM_HOUR (TM_MIN * 60) |
47 | #define TM_DAY (TM_HOUR * 24) | 47 | #define TM_DAY (TM_HOUR * 24) |
48 | #define TM_WEEK (TM_DAY * 7) | 48 | #define TM_WEEK (TM_DAY * 7) |
49 | #define TM_YEAR (TM_DAY * 365) | 49 | #define TM_YEAR (TM_DAY * 365) |
50 | #define TM_MONTH (TM_YEAR / 12.0) | 50 | #define TM_MONTH (TM_YEAR / 12.0) |
51 | 51 | ||
52 | 52 | ||
53 | /* | 53 | /* |
54 | * Default encoding | 54 | * Default encoding |
55 | */ | 55 | */ |
56 | #define PAGE_ENCODING "UTF-8" | 56 | #define PAGE_ENCODING "UTF-8" |
57 | 57 | ||
58 | typedef void (*configfn)(const char *name, const char *value); | 58 | typedef void (*configfn)(const char *name, const char *value); |
59 | typedef void (*filepair_fn)(struct diff_filepair *pair); | 59 | typedef void (*filepair_fn)(struct diff_filepair *pair); |
60 | typedef void (*linediff_fn)(char *line, int len); | 60 | typedef void (*linediff_fn)(char *line, int len); |
61 | 61 | ||
62 | struct cacheitem { | 62 | struct cacheitem { |
63 | char *name; | 63 | char *name; |
64 | struct stat st; | 64 | struct stat st; |
65 | int ttl; | 65 | int ttl; |
66 | int fd; | 66 | int fd; |
67 | }; | 67 | }; |
68 | 68 | ||
69 | struct repoinfo { | 69 | struct cgit_repo { |
70 | char *url; | 70 | char *url; |
71 | char *name; | 71 | char *name; |
72 | char *path; | 72 | char *path; |
73 | char *desc; | 73 | char *desc; |
74 | char *owner; | 74 | char *owner; |
75 | char *defbranch; | 75 | char *defbranch; |
76 | char *group; | 76 | char *group; |
77 | char *module_link; | 77 | char *module_link; |
78 | char *readme; | 78 | char *readme; |
79 | char *clone_url; | 79 | char *clone_url; |
80 | int snapshots; | 80 | int snapshots; |
81 | int enable_log_filecount; | 81 | int enable_log_filecount; |
82 | int enable_log_linecount; | 82 | int enable_log_linecount; |
83 | }; | 83 | }; |
84 | 84 | ||
85 | struct repolist { | 85 | struct cgit_repolist { |
86 | int length; | 86 | int length; |
87 | int count; | 87 | int count; |
88 | struct repoinfo *repos; | 88 | struct cgit_repo *repos; |
89 | }; | 89 | }; |
90 | 90 | ||
91 | struct commitinfo { | 91 | struct commitinfo { |
92 | struct commit *commit; | 92 | struct commit *commit; |
93 | char *author; | 93 | char *author; |
94 | char *author_email; | 94 | char *author_email; |
95 | unsigned long author_date; | 95 | unsigned long author_date; |
96 | char *committer; | 96 | char *committer; |
97 | char *committer_email; | 97 | char *committer_email; |
98 | unsigned long committer_date; | 98 | unsigned long committer_date; |
99 | char *subject; | 99 | char *subject; |
100 | char *msg; | 100 | char *msg; |
101 | char *msg_encoding; | 101 | char *msg_encoding; |
102 | }; | 102 | }; |
103 | 103 | ||
104 | struct taginfo { | 104 | struct taginfo { |
105 | char *tagger; | 105 | char *tagger; |
106 | char *tagger_email; | 106 | char *tagger_email; |
107 | int tagger_date; | 107 | int tagger_date; |
108 | char *msg; | 108 | char *msg; |
109 | }; | 109 | }; |
110 | 110 | ||
111 | struct refinfo { | 111 | struct refinfo { |
112 | const char *refname; | 112 | const char *refname; |
@@ -156,62 +156,62 @@ struct cgit_config { | |||
156 | char *virtual_root; | 156 | char *virtual_root; |
157 | int cache_dynamic_ttl; | 157 | int cache_dynamic_ttl; |
158 | int cache_max_create_time; | 158 | int cache_max_create_time; |
159 | int cache_repo_ttl; | 159 | int cache_repo_ttl; |
160 | int cache_root_ttl; | 160 | int cache_root_ttl; |
161 | int cache_static_ttl; | 161 | int cache_static_ttl; |
162 | int enable_index_links; | 162 | int enable_index_links; |
163 | int enable_log_filecount; | 163 | int enable_log_filecount; |
164 | int enable_log_linecount; | 164 | int enable_log_linecount; |
165 | int max_commit_count; | 165 | int max_commit_count; |
166 | int max_lock_attempts; | 166 | int max_lock_attempts; |
167 | int max_msg_len; | 167 | int max_msg_len; |
168 | int max_repodesc_len; | 168 | int max_repodesc_len; |
169 | int nocache; | 169 | int nocache; |
170 | int renamelimit; | 170 | int renamelimit; |
171 | int snapshots; | 171 | int snapshots; |
172 | int summary_branches; | 172 | int summary_branches; |
173 | int summary_log; | 173 | int summary_log; |
174 | int summary_tags; | 174 | int summary_tags; |
175 | }; | 175 | }; |
176 | 176 | ||
177 | struct cgit_context { | 177 | struct cgit_context { |
178 | struct cgit_query qry; | 178 | struct cgit_query qry; |
179 | struct cgit_config cfg; | 179 | struct cgit_config cfg; |
180 | struct cgit_repo *repo; | ||
180 | }; | 181 | }; |
181 | 182 | ||
182 | extern const char *cgit_version; | 183 | extern const char *cgit_version; |
183 | 184 | ||
184 | extern struct repolist cgit_repolist; | 185 | extern struct cgit_repolist cgit_repolist; |
185 | extern struct repoinfo *cgit_repo; | ||
186 | extern struct cgit_context ctx; | 186 | extern struct cgit_context ctx; |
187 | extern int cgit_cmd; | 187 | extern int cgit_cmd; |
188 | 188 | ||
189 | extern int htmlfd; | 189 | extern int htmlfd; |
190 | 190 | ||
191 | extern void cgit_prepare_context(struct cgit_context *ctx); | 191 | extern void cgit_prepare_context(struct cgit_context *ctx); |
192 | extern int cgit_get_cmd_index(const char *cmd); | 192 | extern int cgit_get_cmd_index(const char *cmd); |
193 | extern struct repoinfo *cgit_get_repoinfo(const char *url); | 193 | extern struct cgit_repo *cgit_get_repoinfo(const char *url); |
194 | extern void cgit_global_config_cb(const char *name, const char *value); | 194 | extern void cgit_global_config_cb(const char *name, const char *value); |
195 | extern void cgit_repo_config_cb(const char *name, const char *value); | 195 | extern void cgit_repo_config_cb(const char *name, const char *value); |
196 | extern void cgit_querystring_cb(const char *name, const char *value); | 196 | extern void cgit_querystring_cb(const char *name, const char *value); |
197 | 197 | ||
198 | extern int chk_zero(int result, char *msg); | 198 | extern int chk_zero(int result, char *msg); |
199 | extern int chk_positive(int result, char *msg); | 199 | extern int chk_positive(int result, char *msg); |
200 | extern int chk_non_negative(int result, char *msg); | 200 | extern int chk_non_negative(int result, char *msg); |
201 | 201 | ||
202 | extern int hextoint(char c); | 202 | extern int hextoint(char c); |
203 | extern char *trim_end(const char *str, char c); | 203 | extern char *trim_end(const char *str, char c); |
204 | extern char *strlpart(char *txt, int maxlen); | 204 | extern char *strlpart(char *txt, int maxlen); |
205 | extern char *strrpart(char *txt, int maxlen); | 205 | extern char *strrpart(char *txt, int maxlen); |
206 | 206 | ||
207 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); | 207 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); |
208 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, | 208 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, |
209 | int flags, void *cb_data); | 209 | int flags, void *cb_data); |
210 | 210 | ||
211 | extern void *cgit_free_commitinfo(struct commitinfo *info); | 211 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
212 | 212 | ||
213 | extern int cgit_diff_files(const unsigned char *old_sha1, | 213 | extern int cgit_diff_files(const unsigned char *old_sha1, |
214 | const unsigned char *new_sha1, | 214 | const unsigned char *new_sha1, |
215 | linediff_fn fn); | 215 | linediff_fn fn); |
216 | 216 | ||
217 | extern void cgit_diff_tree(const unsigned char *old_sha1, | 217 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
@@ -122,69 +122,69 @@ int cgit_parse_query(char *txt, configfn fn) | |||
122 | } else if (c=='&') { | 122 | } else if (c=='&') { |
123 | *t = '\0'; | 123 | *t = '\0'; |
124 | (*fn)(txt, value); | 124 | (*fn)(txt, value); |
125 | txt = t+1; | 125 | txt = t+1; |
126 | value = NULL; | 126 | value = NULL; |
127 | } | 127 | } |
128 | t++; | 128 | t++; |
129 | } | 129 | } |
130 | if (t!=txt) | 130 | if (t!=txt) |
131 | (*fn)(txt, value); | 131 | (*fn)(txt, value); |
132 | return 0; | 132 | return 0; |
133 | } | 133 | } |
134 | 134 | ||
135 | /* | 135 | /* |
136 | * url syntax: [repo ['/' cmd [ '/' path]]] | 136 | * url syntax: [repo ['/' cmd [ '/' path]]] |
137 | * repo: any valid repo url, may contain '/' | 137 | * repo: any valid repo url, may contain '/' |
138 | * cmd: log | commit | diff | tree | view | blob | snapshot | 138 | * cmd: log | commit | diff | tree | view | blob | snapshot |
139 | * path: any valid path, may contain '/' | 139 | * path: any valid path, may contain '/' |
140 | * | 140 | * |
141 | */ | 141 | */ |
142 | void cgit_parse_url(const char *url) | 142 | void cgit_parse_url(const char *url) |
143 | { | 143 | { |
144 | char *cmd, *p; | 144 | char *cmd, *p; |
145 | 145 | ||
146 | cgit_repo = NULL; | 146 | ctx.repo = NULL; |
147 | if (!url || url[0] == '\0') | 147 | if (!url || url[0] == '\0') |
148 | return; | 148 | return; |
149 | 149 | ||
150 | cgit_repo = cgit_get_repoinfo(url); | 150 | ctx.repo = cgit_get_repoinfo(url); |
151 | if (cgit_repo) { | 151 | if (ctx.repo) { |
152 | ctx.qry.repo = cgit_repo->url; | 152 | ctx.qry.repo = ctx.repo->url; |
153 | return; | 153 | return; |
154 | } | 154 | } |
155 | 155 | ||
156 | cmd = strchr(url, '/'); | 156 | cmd = strchr(url, '/'); |
157 | while (!cgit_repo && cmd) { | 157 | while (!ctx.repo && cmd) { |
158 | cmd[0] = '\0'; | 158 | cmd[0] = '\0'; |
159 | cgit_repo = cgit_get_repoinfo(url); | 159 | ctx.repo = cgit_get_repoinfo(url); |
160 | if (cgit_repo == NULL) { | 160 | if (ctx.repo == NULL) { |
161 | cmd[0] = '/'; | 161 | cmd[0] = '/'; |
162 | cmd = strchr(cmd + 1, '/'); | 162 | cmd = strchr(cmd + 1, '/'); |
163 | continue; | 163 | continue; |
164 | } | 164 | } |
165 | 165 | ||
166 | ctx.qry.repo = cgit_repo->url; | 166 | ctx.qry.repo = ctx.repo->url; |
167 | p = strchr(cmd + 1, '/'); | 167 | p = strchr(cmd + 1, '/'); |
168 | if (p) { | 168 | if (p) { |
169 | p[0] = '\0'; | 169 | p[0] = '\0'; |
170 | if (p[1]) | 170 | if (p[1]) |
171 | ctx.qry.path = trim_end(p + 1, '/'); | 171 | ctx.qry.path = trim_end(p + 1, '/'); |
172 | } | 172 | } |
173 | cgit_cmd = cgit_get_cmd_index(cmd + 1); | 173 | cgit_cmd = cgit_get_cmd_index(cmd + 1); |
174 | ctx.qry.page = xstrdup(cmd + 1); | 174 | ctx.qry.page = xstrdup(cmd + 1); |
175 | return; | 175 | return; |
176 | } | 176 | } |
177 | } | 177 | } |
178 | 178 | ||
179 | char *substr(const char *head, const char *tail) | 179 | char *substr(const char *head, const char *tail) |
180 | { | 180 | { |
181 | char *buf; | 181 | char *buf; |
182 | 182 | ||
183 | buf = xmalloc(tail - head + 1); | 183 | buf = xmalloc(tail - head + 1); |
184 | strncpy(buf, head, tail - head); | 184 | strncpy(buf, head, tail - head); |
185 | buf[tail - head] = '\0'; | 185 | buf[tail - head] = '\0'; |
186 | return buf; | 186 | return buf; |
187 | } | 187 | } |
188 | 188 | ||
189 | struct commitinfo *cgit_parse_commit(struct commit *commit) | 189 | struct commitinfo *cgit_parse_commit(struct commit *commit) |
190 | { | 190 | { |
@@ -1,36 +1,35 @@ | |||
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 | ||
11 | struct repolist cgit_repolist; | 11 | struct cgit_repolist cgit_repolist; |
12 | struct repoinfo *cgit_repo; | ||
13 | struct cgit_context ctx; | 12 | struct cgit_context ctx; |
14 | int cgit_cmd; | 13 | int cgit_cmd; |
15 | 14 | ||
16 | const char *cgit_version = CGIT_VERSION; | 15 | const char *cgit_version = CGIT_VERSION; |
17 | 16 | ||
18 | int htmlfd = 0; | 17 | int htmlfd = 0; |
19 | 18 | ||
20 | void cgit_prepare_context(struct cgit_context *ctx) | 19 | void cgit_prepare_context(struct cgit_context *ctx) |
21 | { | 20 | { |
22 | memset(ctx, 0, sizeof(ctx)); | 21 | memset(ctx, 0, sizeof(ctx)); |
23 | ctx->cfg.agefile = "info/web/last-modified"; | 22 | ctx->cfg.agefile = "info/web/last-modified"; |
24 | ctx->cfg.cache_dynamic_ttl = 5; | 23 | ctx->cfg.cache_dynamic_ttl = 5; |
25 | ctx->cfg.cache_max_create_time = 5; | 24 | ctx->cfg.cache_max_create_time = 5; |
26 | ctx->cfg.cache_repo_ttl = 5; | 25 | ctx->cfg.cache_repo_ttl = 5; |
27 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; | 26 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; |
28 | ctx->cfg.cache_root_ttl = 5; | 27 | ctx->cfg.cache_root_ttl = 5; |
29 | ctx->cfg.cache_static_ttl = -1; | 28 | ctx->cfg.cache_static_ttl = -1; |
30 | ctx->cfg.css = "/cgit.css"; | 29 | ctx->cfg.css = "/cgit.css"; |
31 | ctx->cfg.logo = "/git-logo.png"; | 30 | ctx->cfg.logo = "/git-logo.png"; |
32 | ctx->cfg.max_commit_count = 50; | 31 | ctx->cfg.max_commit_count = 50; |
33 | ctx->cfg.max_lock_attempts = 5; | 32 | ctx->cfg.max_lock_attempts = 5; |
34 | ctx->cfg.max_msg_len = 60; | 33 | ctx->cfg.max_msg_len = 60; |
35 | ctx->cfg.max_repodesc_len = 60; | 34 | ctx->cfg.max_repodesc_len = 60; |
36 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; | 35 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; |
@@ -52,82 +51,82 @@ int cgit_get_cmd_index(const char *cmd) | |||
52 | return 0; | 51 | return 0; |
53 | } | 52 | } |
54 | 53 | ||
55 | int chk_zero(int result, char *msg) | 54 | int chk_zero(int result, char *msg) |
56 | { | 55 | { |
57 | if (result != 0) | 56 | if (result != 0) |
58 | die("%s: %s", msg, strerror(errno)); | 57 | die("%s: %s", msg, strerror(errno)); |
59 | return result; | 58 | return result; |
60 | } | 59 | } |
61 | 60 | ||
62 | int chk_positive(int result, char *msg) | 61 | int chk_positive(int result, char *msg) |
63 | { | 62 | { |
64 | if (result <= 0) | 63 | if (result <= 0) |
65 | die("%s: %s", msg, strerror(errno)); | 64 | die("%s: %s", msg, strerror(errno)); |
66 | return result; | 65 | return result; |
67 | } | 66 | } |
68 | 67 | ||
69 | int chk_non_negative(int result, char *msg) | 68 | int chk_non_negative(int result, char *msg) |
70 | { | 69 | { |
71 | if (result < 0) | 70 | if (result < 0) |
72 | die("%s: %s",msg, strerror(errno)); | 71 | die("%s: %s",msg, strerror(errno)); |
73 | return result; | 72 | return result; |
74 | } | 73 | } |
75 | 74 | ||
76 | struct repoinfo *add_repo(const char *url) | 75 | struct cgit_repo *add_repo(const char *url) |
77 | { | 76 | { |
78 | struct repoinfo *ret; | 77 | struct cgit_repo *ret; |
79 | 78 | ||
80 | if (++cgit_repolist.count > cgit_repolist.length) { | 79 | if (++cgit_repolist.count > cgit_repolist.length) { |
81 | if (cgit_repolist.length == 0) | 80 | if (cgit_repolist.length == 0) |
82 | cgit_repolist.length = 8; | 81 | cgit_repolist.length = 8; |
83 | else | 82 | else |
84 | cgit_repolist.length *= 2; | 83 | cgit_repolist.length *= 2; |
85 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, | 84 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, |
86 | cgit_repolist.length * | 85 | cgit_repolist.length * |
87 | sizeof(struct repoinfo)); | 86 | sizeof(struct cgit_repo)); |
88 | } | 87 | } |
89 | 88 | ||
90 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; | 89 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; |
91 | ret->url = trim_end(url, '/'); | 90 | ret->url = trim_end(url, '/'); |
92 | ret->name = ret->url; | 91 | ret->name = ret->url; |
93 | ret->path = NULL; | 92 | ret->path = NULL; |
94 | ret->desc = "[no description]"; | 93 | ret->desc = "[no description]"; |
95 | ret->owner = NULL; | 94 | ret->owner = NULL; |
96 | ret->group = ctx.cfg.repo_group; | 95 | ret->group = ctx.cfg.repo_group; |
97 | ret->defbranch = "master"; | 96 | ret->defbranch = "master"; |
98 | ret->snapshots = ctx.cfg.snapshots; | 97 | ret->snapshots = ctx.cfg.snapshots; |
99 | ret->enable_log_filecount = ctx.cfg.enable_log_filecount; | 98 | ret->enable_log_filecount = ctx.cfg.enable_log_filecount; |
100 | ret->enable_log_linecount = ctx.cfg.enable_log_linecount; | 99 | ret->enable_log_linecount = ctx.cfg.enable_log_linecount; |
101 | ret->module_link = ctx.cfg.module_link; | 100 | ret->module_link = ctx.cfg.module_link; |
102 | ret->readme = NULL; | 101 | ret->readme = NULL; |
103 | return ret; | 102 | return ret; |
104 | } | 103 | } |
105 | 104 | ||
106 | struct repoinfo *cgit_get_repoinfo(const char *url) | 105 | struct cgit_repo *cgit_get_repoinfo(const char *url) |
107 | { | 106 | { |
108 | int i; | 107 | int i; |
109 | struct repoinfo *repo; | 108 | struct cgit_repo *repo; |
110 | 109 | ||
111 | for (i=0; i<cgit_repolist.count; i++) { | 110 | for (i=0; i<cgit_repolist.count; i++) { |
112 | repo = &cgit_repolist.repos[i]; | 111 | repo = &cgit_repolist.repos[i]; |
113 | if (!strcmp(repo->url, url)) | 112 | if (!strcmp(repo->url, url)) |
114 | return repo; | 113 | return repo; |
115 | } | 114 | } |
116 | return NULL; | 115 | return NULL; |
117 | } | 116 | } |
118 | 117 | ||
119 | void cgit_global_config_cb(const char *name, const char *value) | 118 | void cgit_global_config_cb(const char *name, const char *value) |
120 | { | 119 | { |
121 | if (!strcmp(name, "root-title")) | 120 | if (!strcmp(name, "root-title")) |
122 | ctx.cfg.root_title = xstrdup(value); | 121 | ctx.cfg.root_title = xstrdup(value); |
123 | else if (!strcmp(name, "css")) | 122 | else if (!strcmp(name, "css")) |
124 | ctx.cfg.css = xstrdup(value); | 123 | ctx.cfg.css = xstrdup(value); |
125 | else if (!strcmp(name, "logo")) | 124 | else if (!strcmp(name, "logo")) |
126 | ctx.cfg.logo = xstrdup(value); | 125 | ctx.cfg.logo = xstrdup(value); |
127 | else if (!strcmp(name, "index-header")) | 126 | else if (!strcmp(name, "index-header")) |
128 | ctx.cfg.index_header = xstrdup(value); | 127 | ctx.cfg.index_header = xstrdup(value); |
129 | else if (!strcmp(name, "index-info")) | 128 | else if (!strcmp(name, "index-info")) |
130 | ctx.cfg.index_info = xstrdup(value); | 129 | ctx.cfg.index_info = xstrdup(value); |
131 | else if (!strcmp(name, "logo-link")) | 130 | else if (!strcmp(name, "logo-link")) |
132 | ctx.cfg.logo_link = xstrdup(value); | 131 | ctx.cfg.logo_link = xstrdup(value); |
133 | else if (!strcmp(name, "module-link")) | 132 | else if (!strcmp(name, "module-link")) |
@@ -158,83 +157,83 @@ void cgit_global_config_cb(const char *name, const char *value) | |||
158 | ctx.cfg.cache_dynamic_ttl = atoi(value); | 157 | ctx.cfg.cache_dynamic_ttl = atoi(value); |
159 | else if (!strcmp(name, "max-message-length")) | 158 | else if (!strcmp(name, "max-message-length")) |
160 | ctx.cfg.max_msg_len = atoi(value); | 159 | ctx.cfg.max_msg_len = atoi(value); |
161 | else if (!strcmp(name, "max-repodesc-length")) | 160 | else if (!strcmp(name, "max-repodesc-length")) |
162 | ctx.cfg.max_repodesc_len = atoi(value); | 161 | ctx.cfg.max_repodesc_len = atoi(value); |
163 | else if (!strcmp(name, "max-commit-count")) | 162 | else if (!strcmp(name, "max-commit-count")) |
164 | ctx.cfg.max_commit_count = atoi(value); | 163 | ctx.cfg.max_commit_count = atoi(value); |
165 | else if (!strcmp(name, "summary-log")) | 164 | else if (!strcmp(name, "summary-log")) |
166 | ctx.cfg.summary_log = atoi(value); | 165 | ctx.cfg.summary_log = atoi(value); |
167 | else if (!strcmp(name, "summary-branches")) | 166 | else if (!strcmp(name, "summary-branches")) |
168 | ctx.cfg.summary_branches = atoi(value); | 167 | ctx.cfg.summary_branches = atoi(value); |
169 | else if (!strcmp(name, "summary-tags")) | 168 | else if (!strcmp(name, "summary-tags")) |
170 | ctx.cfg.summary_tags = atoi(value); | 169 | ctx.cfg.summary_tags = atoi(value); |
171 | else if (!strcmp(name, "agefile")) | 170 | else if (!strcmp(name, "agefile")) |
172 | ctx.cfg.agefile = xstrdup(value); | 171 | ctx.cfg.agefile = xstrdup(value); |
173 | else if (!strcmp(name, "renamelimit")) | 172 | else if (!strcmp(name, "renamelimit")) |
174 | ctx.cfg.renamelimit = atoi(value); | 173 | ctx.cfg.renamelimit = atoi(value); |
175 | else if (!strcmp(name, "robots")) | 174 | else if (!strcmp(name, "robots")) |
176 | ctx.cfg.robots = xstrdup(value); | 175 | ctx.cfg.robots = xstrdup(value); |
177 | else if (!strcmp(name, "clone-prefix")) | 176 | else if (!strcmp(name, "clone-prefix")) |
178 | ctx.cfg.clone_prefix = xstrdup(value); | 177 | ctx.cfg.clone_prefix = xstrdup(value); |
179 | else if (!strcmp(name, "repo.group")) | 178 | else if (!strcmp(name, "repo.group")) |
180 | ctx.cfg.repo_group = xstrdup(value); | 179 | ctx.cfg.repo_group = xstrdup(value); |
181 | else if (!strcmp(name, "repo.url")) | 180 | else if (!strcmp(name, "repo.url")) |
182 | cgit_repo = add_repo(value); | 181 | ctx.repo = add_repo(value); |
183 | else if (!strcmp(name, "repo.name")) | 182 | else if (!strcmp(name, "repo.name")) |
184 | cgit_repo->name = xstrdup(value); | 183 | ctx.repo->name = xstrdup(value); |
185 | else if (cgit_repo && !strcmp(name, "repo.path")) | 184 | else if (ctx.repo && !strcmp(name, "repo.path")) |
186 | cgit_repo->path = trim_end(value, '/'); | 185 | ctx.repo->path = trim_end(value, '/'); |
187 | else if (cgit_repo && !strcmp(name, "repo.clone-url")) | 186 | else if (ctx.repo && !strcmp(name, "repo.clone-url")) |
188 | cgit_repo->clone_url = xstrdup(value); | 187 | ctx.repo->clone_url = xstrdup(value); |
189 | else if (cgit_repo && !strcmp(name, "repo.desc")) | 188 | else if (ctx.repo && !strcmp(name, "repo.desc")) |
190 | cgit_repo->desc = xstrdup(value); | 189 | ctx.repo->desc = xstrdup(value); |
191 | else if (cgit_repo && !strcmp(name, "repo.owner")) | 190 | else if (ctx.repo && !strcmp(name, "repo.owner")) |
192 | cgit_repo->owner = xstrdup(value); | 191 | ctx.repo->owner = xstrdup(value); |
193 | else if (cgit_repo && !strcmp(name, "repo.defbranch")) | 192 | else if (ctx.repo && !strcmp(name, "repo.defbranch")) |
194 | cgit_repo->defbranch = xstrdup(value); | 193 | ctx.repo->defbranch = xstrdup(value); |
195 | else if (cgit_repo && !strcmp(name, "repo.snapshots")) | 194 | else if (ctx.repo && !strcmp(name, "repo.snapshots")) |
196 | cgit_repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ | 195 | ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ |
197 | else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount")) | 196 | else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount")) |
198 | cgit_repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); | 197 | ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); |
199 | else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount")) | 198 | else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount")) |
200 | cgit_repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); | 199 | ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); |
201 | else if (cgit_repo && !strcmp(name, "repo.module-link")) | 200 | else if (ctx.repo && !strcmp(name, "repo.module-link")) |
202 | cgit_repo->module_link= xstrdup(value); | 201 | ctx.repo->module_link= xstrdup(value); |
203 | else if (cgit_repo && !strcmp(name, "repo.readme") && value != NULL) { | 202 | else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { |
204 | if (*value == '/') | 203 | if (*value == '/') |
205 | cgit_repo->readme = xstrdup(value); | 204 | ctx.repo->readme = xstrdup(value); |
206 | else | 205 | else |
207 | cgit_repo->readme = xstrdup(fmt("%s/%s", cgit_repo->path, value)); | 206 | ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); |
208 | } else if (!strcmp(name, "include")) | 207 | } else if (!strcmp(name, "include")) |
209 | cgit_read_config(value, cgit_global_config_cb); | 208 | cgit_read_config(value, cgit_global_config_cb); |
210 | } | 209 | } |
211 | 210 | ||
212 | void cgit_querystring_cb(const char *name, const char *value) | 211 | void cgit_querystring_cb(const char *name, const char *value) |
213 | { | 212 | { |
214 | if (!strcmp(name,"r")) { | 213 | if (!strcmp(name,"r")) { |
215 | ctx.qry.repo = xstrdup(value); | 214 | ctx.qry.repo = xstrdup(value); |
216 | cgit_repo = cgit_get_repoinfo(value); | 215 | ctx.repo = cgit_get_repoinfo(value); |
217 | } else if (!strcmp(name, "p")) { | 216 | } else if (!strcmp(name, "p")) { |
218 | ctx.qry.page = xstrdup(value); | 217 | ctx.qry.page = xstrdup(value); |
219 | cgit_cmd = cgit_get_cmd_index(value); | 218 | cgit_cmd = cgit_get_cmd_index(value); |
220 | } else if (!strcmp(name, "url")) { | 219 | } else if (!strcmp(name, "url")) { |
221 | cgit_parse_url(value); | 220 | cgit_parse_url(value); |
222 | } else if (!strcmp(name, "qt")) { | 221 | } else if (!strcmp(name, "qt")) { |
223 | ctx.qry.grep = xstrdup(value); | 222 | ctx.qry.grep = xstrdup(value); |
224 | } else if (!strcmp(name, "q")) { | 223 | } else if (!strcmp(name, "q")) { |
225 | ctx.qry.search = xstrdup(value); | 224 | ctx.qry.search = xstrdup(value); |
226 | } else if (!strcmp(name, "h")) { | 225 | } else if (!strcmp(name, "h")) { |
227 | ctx.qry.head = xstrdup(value); | 226 | ctx.qry.head = xstrdup(value); |
228 | ctx.qry.has_symref = 1; | 227 | ctx.qry.has_symref = 1; |
229 | } else if (!strcmp(name, "id")) { | 228 | } else if (!strcmp(name, "id")) { |
230 | ctx.qry.sha1 = xstrdup(value); | 229 | ctx.qry.sha1 = xstrdup(value); |
231 | ctx.qry.has_sha1 = 1; | 230 | ctx.qry.has_sha1 = 1; |
232 | } else if (!strcmp(name, "id2")) { | 231 | } else if (!strcmp(name, "id2")) { |
233 | ctx.qry.sha2 = xstrdup(value); | 232 | ctx.qry.sha2 = xstrdup(value); |
234 | ctx.qry.has_sha1 = 1; | 233 | ctx.qry.has_sha1 = 1; |
235 | } else if (!strcmp(name, "ofs")) { | 234 | } else if (!strcmp(name, "ofs")) { |
236 | ctx.qry.ofs = atoi(value); | 235 | ctx.qry.ofs = atoi(value); |
237 | } else if (!strcmp(name, "path")) { | 236 | } else if (!strcmp(name, "path")) { |
238 | ctx.qry.path = trim_end(value, '/'); | 237 | ctx.qry.path = trim_end(value, '/'); |
239 | } else if (!strcmp(name, "name")) { | 238 | } else if (!strcmp(name, "name")) { |
240 | ctx.qry.name = xstrdup(value); | 239 | ctx.qry.name = xstrdup(value); |
diff --git a/ui-commit.c b/ui-commit.c index 3b0919b..25721ca 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -173,52 +173,52 @@ void cgit_print_commit(char *hex) | |||
173 | cgit_print_date(info->committer_date, FMT_LONGDATE); | 173 | cgit_print_date(info->committer_date, FMT_LONGDATE); |
174 | html("</td></tr>\n"); | 174 | html("</td></tr>\n"); |
175 | html("<tr><th>tree</th><td colspan='2' class='sha1'>"); | 175 | html("<tr><th>tree</th><td colspan='2' class='sha1'>"); |
176 | tmp = xstrdup(hex); | 176 | tmp = xstrdup(hex); |
177 | cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, | 177 | cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL, |
178 | ctx.qry.head, tmp, NULL); | 178 | ctx.qry.head, tmp, NULL); |
179 | html("</td></tr>\n"); | 179 | html("</td></tr>\n"); |
180 | for (p = commit->parents; p ; p = p->next) { | 180 | for (p = commit->parents; p ; p = p->next) { |
181 | parent = lookup_commit_reference(p->item->object.sha1); | 181 | parent = lookup_commit_reference(p->item->object.sha1); |
182 | if (!parent) { | 182 | if (!parent) { |
183 | html("<tr><td colspan='3'>"); | 183 | html("<tr><td colspan='3'>"); |
184 | cgit_print_error("Error reading parent commit"); | 184 | cgit_print_error("Error reading parent commit"); |
185 | html("</td></tr>"); | 185 | html("</td></tr>"); |
186 | continue; | 186 | continue; |
187 | } | 187 | } |
188 | html("<tr><th>parent</th>" | 188 | html("<tr><th>parent</th>" |
189 | "<td colspan='2' class='sha1'>"); | 189 | "<td colspan='2' class='sha1'>"); |
190 | cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, | 190 | cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, |
191 | ctx.qry.head, sha1_to_hex(p->item->object.sha1)); | 191 | ctx.qry.head, sha1_to_hex(p->item->object.sha1)); |
192 | html(" ("); | 192 | html(" ("); |
193 | cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex, | 193 | cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex, |
194 | sha1_to_hex(p->item->object.sha1), NULL); | 194 | sha1_to_hex(p->item->object.sha1), NULL); |
195 | html(")</td></tr>"); | 195 | html(")</td></tr>"); |
196 | } | 196 | } |
197 | if (cgit_repo->snapshots) { | 197 | if (ctx.repo->snapshots) { |
198 | html("<tr><th>download</th><td colspan='2' class='sha1'>"); | 198 | html("<tr><th>download</th><td colspan='2' class='sha1'>"); |
199 | cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head, | 199 | cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head, |
200 | hex, cgit_repo->snapshots); | 200 | hex, ctx.repo->snapshots); |
201 | html("</td></tr>"); | 201 | html("</td></tr>"); |
202 | } | 202 | } |
203 | html("</table>\n"); | 203 | html("</table>\n"); |
204 | html("<div class='commit-subject'>"); | 204 | html("<div class='commit-subject'>"); |
205 | html_txt(info->subject); | 205 | html_txt(info->subject); |
206 | html("</div>"); | 206 | html("</div>"); |
207 | html("<div class='commit-msg'>"); | 207 | html("<div class='commit-msg'>"); |
208 | html_txt(info->msg); | 208 | html_txt(info->msg); |
209 | html("</div>"); | 209 | html("</div>"); |
210 | if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { | 210 | if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { |
211 | html("<div class='diffstat-header'>Diffstat</div>"); | 211 | html("<div class='diffstat-header'>Diffstat</div>"); |
212 | html("<table summary='diffstat' class='diffstat'>"); | 212 | html("<table summary='diffstat' class='diffstat'>"); |
213 | max_changes = 0; | 213 | max_changes = 0; |
214 | cgit_diff_commit(commit, inspect_filepair); | 214 | cgit_diff_commit(commit, inspect_filepair); |
215 | for(i = 0; i<files; i++) | 215 | for(i = 0; i<files; i++) |
216 | print_fileinfo(&items[i]); | 216 | print_fileinfo(&items[i]); |
217 | html("</table>"); | 217 | html("</table>"); |
218 | html("<div class='diffstat-summary'>"); | 218 | html("<div class='diffstat-summary'>"); |
219 | htmlf("%d files changed, %d insertions, %d deletions (", | 219 | htmlf("%d files changed, %d insertions, %d deletions (", |
220 | files, total_adds, total_rems); | 220 | files, total_adds, total_rems); |
221 | cgit_diff_link("show diff", NULL, NULL, ctx.qry.head, hex, | 221 | cgit_diff_link("show diff", NULL, NULL, ctx.qry.head, hex, |
222 | NULL, NULL); | 222 | NULL, NULL); |
223 | html(")</div>"); | 223 | html(")</div>"); |
224 | } | 224 | } |
@@ -4,120 +4,120 @@ | |||
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 | ||
11 | int files, add_lines, rem_lines; | 11 | int files, add_lines, rem_lines; |
12 | 12 | ||
13 | void count_lines(char *line, int size) | 13 | void count_lines(char *line, int size) |
14 | { | 14 | { |
15 | if (size <= 0) | 15 | if (size <= 0) |
16 | return; | 16 | return; |
17 | 17 | ||
18 | if (line[0] == '+') | 18 | if (line[0] == '+') |
19 | add_lines++; | 19 | add_lines++; |
20 | 20 | ||
21 | else if (line[0] == '-') | 21 | else if (line[0] == '-') |
22 | rem_lines++; | 22 | rem_lines++; |
23 | } | 23 | } |
24 | 24 | ||
25 | void inspect_files(struct diff_filepair *pair) | 25 | void inspect_files(struct diff_filepair *pair) |
26 | { | 26 | { |
27 | files++; | 27 | files++; |
28 | if (cgit_repo->enable_log_linecount) | 28 | if (ctx.repo->enable_log_linecount) |
29 | cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); | 29 | cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); |
30 | } | 30 | } |
31 | 31 | ||
32 | void print_commit(struct commit *commit) | 32 | void print_commit(struct commit *commit) |
33 | { | 33 | { |
34 | struct commitinfo *info; | 34 | struct commitinfo *info; |
35 | 35 | ||
36 | info = cgit_parse_commit(commit); | 36 | info = cgit_parse_commit(commit); |
37 | html("<tr><td>"); | 37 | html("<tr><td>"); |
38 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); | 38 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); |
39 | html("</td><td>"); | 39 | html("</td><td>"); |
40 | cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, | 40 | cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, |
41 | sha1_to_hex(commit->object.sha1)); | 41 | sha1_to_hex(commit->object.sha1)); |
42 | if (cgit_repo->enable_log_filecount) { | 42 | if (ctx.repo->enable_log_filecount) { |
43 | files = 0; | 43 | files = 0; |
44 | add_lines = 0; | 44 | add_lines = 0; |
45 | rem_lines = 0; | 45 | rem_lines = 0; |
46 | cgit_diff_commit(commit, inspect_files); | 46 | cgit_diff_commit(commit, inspect_files); |
47 | html("</td><td class='right'>"); | 47 | html("</td><td class='right'>"); |
48 | htmlf("%d", files); | 48 | htmlf("%d", files); |
49 | if (cgit_repo->enable_log_linecount) { | 49 | if (ctx.repo->enable_log_linecount) { |
50 | html("</td><td class='right'>"); | 50 | html("</td><td class='right'>"); |
51 | htmlf("-%d/+%d", rem_lines, add_lines); | 51 | htmlf("-%d/+%d", rem_lines, add_lines); |
52 | } | 52 | } |
53 | } | 53 | } |
54 | html("</td><td>"); | 54 | html("</td><td>"); |
55 | html_txt(info->author); | 55 | html_txt(info->author); |
56 | html("</td></tr>\n"); | 56 | html("</td></tr>\n"); |
57 | cgit_free_commitinfo(info); | 57 | cgit_free_commitinfo(info); |
58 | } | 58 | } |
59 | 59 | ||
60 | 60 | ||
61 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, char *path, int pager) | 61 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, char *path, int pager) |
62 | { | 62 | { |
63 | struct rev_info rev; | 63 | struct rev_info rev; |
64 | struct commit *commit; | 64 | struct commit *commit; |
65 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; | 65 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; |
66 | int argc = 2; | 66 | int argc = 2; |
67 | int i; | 67 | int i; |
68 | 68 | ||
69 | if (!tip) | 69 | if (!tip) |
70 | argv[1] = ctx.qry.head; | 70 | argv[1] = ctx.qry.head; |
71 | 71 | ||
72 | if (grep && pattern && (!strcmp(grep, "grep") || | 72 | if (grep && pattern && (!strcmp(grep, "grep") || |
73 | !strcmp(grep, "author") || | 73 | !strcmp(grep, "author") || |
74 | !strcmp(grep, "committer"))) | 74 | !strcmp(grep, "committer"))) |
75 | argv[argc++] = fmt("--%s=%s", grep, pattern); | 75 | argv[argc++] = fmt("--%s=%s", grep, pattern); |
76 | 76 | ||
77 | if (path) { | 77 | if (path) { |
78 | argv[argc++] = "--"; | 78 | argv[argc++] = "--"; |
79 | argv[argc++] = path; | 79 | argv[argc++] = path; |
80 | } | 80 | } |
81 | init_revisions(&rev, NULL); | 81 | init_revisions(&rev, NULL); |
82 | rev.abbrev = DEFAULT_ABBREV; | 82 | rev.abbrev = DEFAULT_ABBREV; |
83 | rev.commit_format = CMIT_FMT_DEFAULT; | 83 | rev.commit_format = CMIT_FMT_DEFAULT; |
84 | rev.verbose_header = 1; | 84 | rev.verbose_header = 1; |
85 | rev.show_root_diff = 0; | 85 | rev.show_root_diff = 0; |
86 | setup_revisions(argc, argv, &rev, NULL); | 86 | setup_revisions(argc, argv, &rev, NULL); |
87 | if (rev.grep_filter) { | 87 | if (rev.grep_filter) { |
88 | rev.grep_filter->regflags |= REG_ICASE; | 88 | rev.grep_filter->regflags |= REG_ICASE; |
89 | compile_grep_patterns(rev.grep_filter); | 89 | compile_grep_patterns(rev.grep_filter); |
90 | } | 90 | } |
91 | prepare_revision_walk(&rev); | 91 | prepare_revision_walk(&rev); |
92 | 92 | ||
93 | html("<table summary='log' class='list nowrap'>"); | 93 | html("<table summary='log' class='list nowrap'>"); |
94 | html("<tr class='nohover'><th class='left'>Age</th>" | 94 | html("<tr class='nohover'><th class='left'>Age</th>" |
95 | "<th class='left'>Message</th>"); | 95 | "<th class='left'>Message</th>"); |
96 | 96 | ||
97 | if (cgit_repo->enable_log_filecount) { | 97 | if (ctx.repo->enable_log_filecount) { |
98 | html("<th class='right'>Files</th>"); | 98 | html("<th class='right'>Files</th>"); |
99 | if (cgit_repo->enable_log_linecount) | 99 | if (ctx.repo->enable_log_linecount) |
100 | html("<th class='right'>Lines</th>"); | 100 | html("<th class='right'>Lines</th>"); |
101 | } | 101 | } |
102 | html("<th class='left'>Author</th></tr>\n"); | 102 | html("<th class='left'>Author</th></tr>\n"); |
103 | 103 | ||
104 | if (ofs<0) | 104 | if (ofs<0) |
105 | ofs = 0; | 105 | ofs = 0; |
106 | 106 | ||
107 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { | 107 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { |
108 | free(commit->buffer); | 108 | free(commit->buffer); |
109 | commit->buffer = NULL; | 109 | commit->buffer = NULL; |
110 | free_commit_list(commit->parents); | 110 | free_commit_list(commit->parents); |
111 | commit->parents = NULL; | 111 | commit->parents = NULL; |
112 | } | 112 | } |
113 | 113 | ||
114 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { | 114 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { |
115 | print_commit(commit); | 115 | print_commit(commit); |
116 | free(commit->buffer); | 116 | free(commit->buffer); |
117 | commit->buffer = NULL; | 117 | commit->buffer = NULL; |
118 | free_commit_list(commit->parents); | 118 | free_commit_list(commit->parents); |
119 | commit->parents = NULL; | 119 | commit->parents = NULL; |
120 | } | 120 | } |
121 | html("</table>\n"); | 121 | html("</table>\n"); |
122 | 122 | ||
123 | if (pager) { | 123 | if (pager) { |
diff --git a/ui-repolist.c b/ui-repolist.c index a6cc2cc..5fde174 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
@@ -4,107 +4,107 @@ | |||
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 | #include <time.h> | 10 | #include <time.h> |
11 | 11 | ||
12 | 12 | ||
13 | time_t read_agefile(char *path) | 13 | time_t read_agefile(char *path) |
14 | { | 14 | { |
15 | FILE *f; | 15 | FILE *f; |
16 | static char buf[64], buf2[64]; | 16 | static char buf[64], buf2[64]; |
17 | 17 | ||
18 | if (!(f = fopen(path, "r"))) | 18 | if (!(f = fopen(path, "r"))) |
19 | return -1; | 19 | return -1; |
20 | fgets(buf, sizeof(buf), f); | 20 | fgets(buf, sizeof(buf), f); |
21 | fclose(f); | 21 | fclose(f); |
22 | if (parse_date(buf, buf2, sizeof(buf2))) | 22 | if (parse_date(buf, buf2, sizeof(buf2))) |
23 | return strtoul(buf2, NULL, 10); | 23 | return strtoul(buf2, NULL, 10); |
24 | else | 24 | else |
25 | return 0; | 25 | return 0; |
26 | } | 26 | } |
27 | 27 | ||
28 | static void print_modtime(struct repoinfo *repo) | 28 | static void print_modtime(struct cgit_repo *repo) |
29 | { | 29 | { |
30 | char *path; | 30 | char *path; |
31 | struct stat s; | 31 | struct stat s; |
32 | 32 | ||
33 | path = fmt("%s/%s", repo->path, ctx.cfg.agefile); | 33 | path = fmt("%s/%s", repo->path, ctx.cfg.agefile); |
34 | if (stat(path, &s) == 0) { | 34 | if (stat(path, &s) == 0) { |
35 | cgit_print_age(read_agefile(path), -1, NULL); | 35 | cgit_print_age(read_agefile(path), -1, NULL); |
36 | return; | 36 | return; |
37 | } | 37 | } |
38 | 38 | ||
39 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); | 39 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); |
40 | if (stat(path, &s) != 0) | 40 | if (stat(path, &s) != 0) |
41 | return; | 41 | return; |
42 | cgit_print_age(s.st_mtime, -1, NULL); | 42 | cgit_print_age(s.st_mtime, -1, NULL); |
43 | } | 43 | } |
44 | 44 | ||
45 | void cgit_print_repolist(struct cacheitem *item) | 45 | void cgit_print_repolist(struct cacheitem *item) |
46 | { | 46 | { |
47 | int i, columns = 4; | 47 | int i, columns = 4; |
48 | char *last_group = NULL; | 48 | char *last_group = NULL; |
49 | 49 | ||
50 | if (ctx.cfg.enable_index_links) | 50 | if (ctx.cfg.enable_index_links) |
51 | columns++; | 51 | columns++; |
52 | 52 | ||
53 | cgit_print_docstart(ctx.cfg.root_title, item); | 53 | cgit_print_docstart(ctx.cfg.root_title, item); |
54 | cgit_print_pageheader(ctx.cfg.root_title, 0); | 54 | cgit_print_pageheader(ctx.cfg.root_title, 0); |
55 | 55 | ||
56 | html("<table summary='repository list' class='list nowrap'>"); | 56 | html("<table summary='repository list' class='list nowrap'>"); |
57 | if (ctx.cfg.index_header) { | 57 | if (ctx.cfg.index_header) { |
58 | htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>", | 58 | htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>", |
59 | columns); | 59 | columns); |
60 | html_include(ctx.cfg.index_header); | 60 | html_include(ctx.cfg.index_header); |
61 | html("</td></tr>"); | 61 | html("</td></tr>"); |
62 | } | 62 | } |
63 | html("<tr class='nohover'>" | 63 | html("<tr class='nohover'>" |
64 | "<th class='left'>Name</th>" | 64 | "<th class='left'>Name</th>" |
65 | "<th class='left'>Description</th>" | 65 | "<th class='left'>Description</th>" |
66 | "<th class='left'>Owner</th>" | 66 | "<th class='left'>Owner</th>" |
67 | "<th class='left'>Idle</th>"); | 67 | "<th class='left'>Idle</th>"); |
68 | if (ctx.cfg.enable_index_links) | 68 | if (ctx.cfg.enable_index_links) |
69 | html("<th>Links</th>"); | 69 | html("<th>Links</th>"); |
70 | html("</tr>\n"); | 70 | html("</tr>\n"); |
71 | 71 | ||
72 | for (i=0; i<cgit_repolist.count; i++) { | 72 | for (i=0; i<cgit_repolist.count; i++) { |
73 | cgit_repo = &cgit_repolist.repos[i]; | 73 | ctx.repo = &cgit_repolist.repos[i]; |
74 | if ((last_group == NULL && cgit_repo->group != NULL) || | 74 | if ((last_group == NULL && ctx.repo->group != NULL) || |
75 | (last_group != NULL && cgit_repo->group == NULL) || | 75 | (last_group != NULL && ctx.repo->group == NULL) || |
76 | (last_group != NULL && cgit_repo->group != NULL && | 76 | (last_group != NULL && ctx.repo->group != NULL && |
77 | strcmp(cgit_repo->group, last_group))) { | 77 | strcmp(ctx.repo->group, last_group))) { |
78 | htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", | 78 | htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", |
79 | columns); | 79 | columns); |
80 | html_txt(cgit_repo->group); | 80 | html_txt(ctx.repo->group); |
81 | html("</td></tr>"); | 81 | html("</td></tr>"); |
82 | last_group = cgit_repo->group; | 82 | last_group = ctx.repo->group; |
83 | } | 83 | } |
84 | htmlf("<tr><td class='%s'>", | 84 | htmlf("<tr><td class='%s'>", |
85 | cgit_repo->group ? "sublevel-repo" : "toplevel-repo"); | 85 | ctx.repo->group ? "sublevel-repo" : "toplevel-repo"); |
86 | html_link_open(cgit_repourl(cgit_repo->url), NULL, NULL); | 86 | html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL); |
87 | html_txt(cgit_repo->name); | 87 | html_txt(ctx.repo->name); |
88 | html_link_close(); | 88 | html_link_close(); |
89 | html("</td><td>"); | 89 | html("</td><td>"); |
90 | html_ntxt(ctx.cfg.max_repodesc_len, cgit_repo->desc); | 90 | html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc); |
91 | html("</td><td>"); | 91 | html("</td><td>"); |
92 | html_txt(cgit_repo->owner); | 92 | html_txt(ctx.repo->owner); |
93 | html("</td><td>"); | 93 | html("</td><td>"); |
94 | print_modtime(cgit_repo); | 94 | print_modtime(ctx.repo); |
95 | html("</td>"); | 95 | html("</td>"); |
96 | if (ctx.cfg.enable_index_links) { | 96 | if (ctx.cfg.enable_index_links) { |
97 | html("<td>"); | 97 | html("<td>"); |
98 | html_link_open(cgit_repourl(cgit_repo->url), | 98 | html_link_open(cgit_repourl(ctx.repo->url), |
99 | NULL, "button"); | 99 | NULL, "button"); |
100 | html("summary</a>"); | 100 | html("summary</a>"); |
101 | cgit_log_link("log", NULL, "button", NULL, NULL, NULL, | 101 | cgit_log_link("log", NULL, "button", NULL, NULL, NULL, |
102 | 0, NULL, NULL); | 102 | 0, NULL, NULL); |
103 | cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); | 103 | cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); |
104 | html("</td>"); | 104 | html("</td>"); |
105 | } | 105 | } |
106 | html("</tr>\n"); | 106 | html("</tr>\n"); |
107 | } | 107 | } |
108 | html("</table>"); | 108 | html("</table>"); |
109 | cgit_print_docend(); | 109 | cgit_print_docend(); |
110 | } | 110 | } |
diff --git a/ui-shared.c b/ui-shared.c index b96237d..b9f487a 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -120,72 +120,72 @@ char *cgit_currurl() | |||
120 | return fmt("%s/", ctx.cfg.virtual_root); | 120 | return fmt("%s/", ctx.cfg.virtual_root); |
121 | } | 121 | } |
122 | 122 | ||
123 | static char *repolink(char *title, char *class, char *page, char *head, | 123 | static char *repolink(char *title, char *class, char *page, char *head, |
124 | char *path) | 124 | char *path) |
125 | { | 125 | { |
126 | char *delim = "?"; | 126 | char *delim = "?"; |
127 | 127 | ||
128 | html("<a"); | 128 | html("<a"); |
129 | if (title) { | 129 | if (title) { |
130 | html(" title='"); | 130 | html(" title='"); |
131 | html_attr(title); | 131 | html_attr(title); |
132 | html("'"); | 132 | html("'"); |
133 | } | 133 | } |
134 | if (class) { | 134 | if (class) { |
135 | html(" class='"); | 135 | html(" class='"); |
136 | html_attr(class); | 136 | html_attr(class); |
137 | html("'"); | 137 | html("'"); |
138 | } | 138 | } |
139 | html(" href='"); | 139 | html(" href='"); |
140 | if (ctx.cfg.virtual_root) { | 140 | if (ctx.cfg.virtual_root) { |
141 | html_attr(ctx.cfg.virtual_root); | 141 | html_attr(ctx.cfg.virtual_root); |
142 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') | 142 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') |
143 | html("/"); | 143 | html("/"); |
144 | html_attr(cgit_repo->url); | 144 | html_attr(ctx.repo->url); |
145 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 145 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
146 | html("/"); | 146 | html("/"); |
147 | if (page) { | 147 | if (page) { |
148 | html(page); | 148 | html(page); |
149 | html("/"); | 149 | html("/"); |
150 | if (path) | 150 | if (path) |
151 | html_attr(path); | 151 | html_attr(path); |
152 | } | 152 | } |
153 | } else { | 153 | } else { |
154 | html(ctx.cfg.script_name); | 154 | html(ctx.cfg.script_name); |
155 | html("?url="); | 155 | html("?url="); |
156 | html_attr(cgit_repo->url); | 156 | html_attr(ctx.repo->url); |
157 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 157 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
158 | html("/"); | 158 | html("/"); |
159 | if (page) { | 159 | if (page) { |
160 | html(page); | 160 | html(page); |
161 | html("/"); | 161 | html("/"); |
162 | if (path) | 162 | if (path) |
163 | html_attr(path); | 163 | html_attr(path); |
164 | } | 164 | } |
165 | delim = "&"; | 165 | delim = "&"; |
166 | } | 166 | } |
167 | if (head && strcmp(head, cgit_repo->defbranch)) { | 167 | if (head && strcmp(head, ctx.repo->defbranch)) { |
168 | html(delim); | 168 | html(delim); |
169 | html("h="); | 169 | html("h="); |
170 | html_attr(head); | 170 | html_attr(head); |
171 | delim = "&"; | 171 | delim = "&"; |
172 | } | 172 | } |
173 | return fmt("%s", delim); | 173 | return fmt("%s", delim); |
174 | } | 174 | } |
175 | 175 | ||
176 | static void reporevlink(char *page, char *name, char *title, char *class, | 176 | static void reporevlink(char *page, char *name, char *title, char *class, |
177 | char *head, char *rev, char *path) | 177 | char *head, char *rev, char *path) |
178 | { | 178 | { |
179 | char *delim; | 179 | char *delim; |
180 | 180 | ||
181 | delim = repolink(title, class, page, head, path); | 181 | delim = repolink(title, class, page, head, path); |
182 | if (rev && strcmp(rev, ctx.qry.head)) { | 182 | if (rev && strcmp(rev, ctx.qry.head)) { |
183 | html(delim); | 183 | html(delim); |
184 | html("id="); | 184 | html("id="); |
185 | html_attr(rev); | 185 | html_attr(rev); |
186 | } | 186 | } |
187 | html("'>"); | 187 | html("'>"); |
188 | html_txt(name); | 188 | html_txt(name); |
189 | html("</a>"); | 189 | html("</a>"); |
190 | } | 190 | } |
191 | 191 | ||
@@ -425,110 +425,110 @@ int print_archive_ref(const char *refname, const unsigned char *sha1, | |||
425 | if (!*header) { | 425 | if (!*header) { |
426 | html("<h1>download</h1>\n"); | 426 | html("<h1>download</h1>\n"); |
427 | *header = 1; | 427 | *header = 1; |
428 | } | 428 | } |
429 | url = cgit_pageurl(ctx.qry.repo, "blob", | 429 | url = cgit_pageurl(ctx.qry.repo, "blob", |
430 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 430 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
431 | buf)); | 431 | buf)); |
432 | html_link_open(url, NULL, "menu"); | 432 | html_link_open(url, NULL, "menu"); |
433 | html_txt(strlpart(buf, 20)); | 433 | html_txt(strlpart(buf, 20)); |
434 | html_link_close(); | 434 | html_link_close(); |
435 | return 0; | 435 | return 0; |
436 | } | 436 | } |
437 | 437 | ||
438 | void add_hidden_formfields(int incl_head, int incl_search, char *page) | 438 | void add_hidden_formfields(int incl_head, int incl_search, char *page) |
439 | { | 439 | { |
440 | char *url; | 440 | char *url; |
441 | 441 | ||
442 | if (!ctx.cfg.virtual_root) { | 442 | if (!ctx.cfg.virtual_root) { |
443 | url = fmt("%s/%s", ctx.qry.repo, page); | 443 | url = fmt("%s/%s", ctx.qry.repo, page); |
444 | if (ctx.qry.path) | 444 | if (ctx.qry.path) |
445 | url = fmt("%s/%s", url, ctx.qry.path); | 445 | url = fmt("%s/%s", url, ctx.qry.path); |
446 | html_hidden("url", url); | 446 | html_hidden("url", url); |
447 | } | 447 | } |
448 | 448 | ||
449 | if (incl_head && strcmp(ctx.qry.head, cgit_repo->defbranch)) | 449 | if (incl_head && strcmp(ctx.qry.head, ctx.repo->defbranch)) |
450 | html_hidden("h", ctx.qry.head); | 450 | html_hidden("h", ctx.qry.head); |
451 | 451 | ||
452 | if (ctx.qry.sha1) | 452 | if (ctx.qry.sha1) |
453 | html_hidden("id", ctx.qry.sha1); | 453 | html_hidden("id", ctx.qry.sha1); |
454 | if (ctx.qry.sha2) | 454 | if (ctx.qry.sha2) |
455 | html_hidden("id2", ctx.qry.sha2); | 455 | html_hidden("id2", ctx.qry.sha2); |
456 | 456 | ||
457 | if (incl_search) { | 457 | if (incl_search) { |
458 | if (ctx.qry.grep) | 458 | if (ctx.qry.grep) |
459 | html_hidden("qt", ctx.qry.grep); | 459 | html_hidden("qt", ctx.qry.grep); |
460 | if (ctx.qry.search) | 460 | if (ctx.qry.search) |
461 | html_hidden("q", ctx.qry.search); | 461 | html_hidden("q", ctx.qry.search); |
462 | } | 462 | } |
463 | } | 463 | } |
464 | 464 | ||
465 | void cgit_print_pageheader(char *title, int show_search) | 465 | void cgit_print_pageheader(char *title, int show_search) |
466 | { | 466 | { |
467 | static const char *default_info = "This is cgit, a fast webinterface for git repositories"; | 467 | static const char *default_info = "This is cgit, a fast webinterface for git repositories"; |
468 | int header = 0; | 468 | int header = 0; |
469 | char *url; | 469 | char *url; |
470 | 470 | ||
471 | html("<table id='layout' summary=''>\n"); | 471 | html("<table id='layout' summary=''>\n"); |
472 | html("<tr><td id='sidebar'>\n"); | 472 | html("<tr><td id='sidebar'>\n"); |
473 | html("<table class='sidebar' cellspacing='0' summary=''>\n"); | 473 | html("<table class='sidebar' cellspacing='0' summary=''>\n"); |
474 | html("<tr><td class='sidebar'>\n<a href='"); | 474 | html("<tr><td class='sidebar'>\n<a href='"); |
475 | html_attr(cgit_rooturl()); | 475 | html_attr(cgit_rooturl()); |
476 | htmlf("'><img src='%s' alt='cgit'/></a>\n", | 476 | htmlf("'><img src='%s' alt='cgit'/></a>\n", |
477 | ctx.cfg.logo); | 477 | ctx.cfg.logo); |
478 | html("</td></tr>\n<tr><td class='sidebar'>\n"); | 478 | html("</td></tr>\n<tr><td class='sidebar'>\n"); |
479 | if (ctx.qry.repo) { | 479 | if (ctx.qry.repo) { |
480 | html("<h1 class='first'>"); | 480 | html("<h1 class='first'>"); |
481 | html_txt(strrpart(cgit_repo->name, 20)); | 481 | html_txt(strrpart(ctx.repo->name, 20)); |
482 | html("</h1>\n"); | 482 | html("</h1>\n"); |
483 | html_txt(cgit_repo->desc); | 483 | html_txt(ctx.repo->desc); |
484 | if (cgit_repo->owner) { | 484 | if (ctx.repo->owner) { |
485 | html("<h1>owner</h1>\n"); | 485 | html("<h1>owner</h1>\n"); |
486 | html_txt(cgit_repo->owner); | 486 | html_txt(ctx.repo->owner); |
487 | } | 487 | } |
488 | html("<h1>navigate</h1>\n"); | 488 | html("<h1>navigate</h1>\n"); |
489 | reporevlink(NULL, "summary", NULL, "menu", ctx.qry.head, | 489 | reporevlink(NULL, "summary", NULL, "menu", ctx.qry.head, |
490 | NULL, NULL); | 490 | NULL, NULL); |
491 | cgit_log_link("log", NULL, "menu", ctx.qry.head, NULL, NULL, | 491 | cgit_log_link("log", NULL, "menu", ctx.qry.head, NULL, NULL, |
492 | 0, NULL, NULL); | 492 | 0, NULL, NULL); |
493 | cgit_tree_link("tree", NULL, "menu", ctx.qry.head, | 493 | cgit_tree_link("tree", NULL, "menu", ctx.qry.head, |
494 | ctx.qry.sha1, NULL); | 494 | ctx.qry.sha1, NULL); |
495 | cgit_commit_link("commit", NULL, "menu", ctx.qry.head, | 495 | cgit_commit_link("commit", NULL, "menu", ctx.qry.head, |
496 | ctx.qry.sha1); | 496 | ctx.qry.sha1); |
497 | cgit_diff_link("diff", NULL, "menu", ctx.qry.head, | 497 | cgit_diff_link("diff", NULL, "menu", ctx.qry.head, |
498 | ctx.qry.sha1, ctx.qry.sha2, NULL); | 498 | ctx.qry.sha1, ctx.qry.sha2, NULL); |
499 | cgit_patch_link("patch", NULL, "menu", ctx.qry.head, | 499 | cgit_patch_link("patch", NULL, "menu", ctx.qry.head, |
500 | ctx.qry.sha1); | 500 | ctx.qry.sha1); |
501 | 501 | ||
502 | for_each_ref(print_archive_ref, &header); | 502 | for_each_ref(print_archive_ref, &header); |
503 | 503 | ||
504 | if (cgit_repo->clone_url || ctx.cfg.clone_prefix) { | 504 | if (ctx.repo->clone_url || ctx.cfg.clone_prefix) { |
505 | html("<h1>clone</h1>\n"); | 505 | html("<h1>clone</h1>\n"); |
506 | if (cgit_repo->clone_url) | 506 | if (ctx.repo->clone_url) |
507 | url = cgit_repo->clone_url; | 507 | url = ctx.repo->clone_url; |
508 | else | 508 | else |
509 | url = fmt("%s%s", ctx.cfg.clone_prefix, | 509 | url = fmt("%s%s", ctx.cfg.clone_prefix, |
510 | cgit_repo->url); | 510 | ctx.repo->url); |
511 | html("<a class='menu' href='"); | 511 | html("<a class='menu' href='"); |
512 | html_attr(url); | 512 | html_attr(url); |
513 | html("' title='"); | 513 | html("' title='"); |
514 | html_attr(url); | 514 | html_attr(url); |
515 | html("'>\n"); | 515 | html("'>\n"); |
516 | html_txt(strrpart(url, 20)); | 516 | html_txt(strrpart(url, 20)); |
517 | html("</a>\n"); | 517 | html("</a>\n"); |
518 | } | 518 | } |
519 | 519 | ||
520 | html("<h1>branch</h1>\n"); | 520 | html("<h1>branch</h1>\n"); |
521 | html("<form method='get' action=''>\n"); | 521 | html("<form method='get' action=''>\n"); |
522 | add_hidden_formfields(0, 1, ctx.qry.page); | 522 | add_hidden_formfields(0, 1, ctx.qry.page); |
523 | // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>"); | 523 | // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>"); |
524 | html("<select name='h' onchange='this.form.submit();'>\n"); | 524 | html("<select name='h' onchange='this.form.submit();'>\n"); |
525 | for_each_branch_ref(print_branch_option, ctx.qry.head); | 525 | for_each_branch_ref(print_branch_option, ctx.qry.head); |
526 | html("</select>\n"); | 526 | html("</select>\n"); |
527 | // html("</td><td>"); | 527 | // html("</td><td>"); |
528 | html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n"); | 528 | html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n"); |
529 | // html("</td></tr></table>"); | 529 | // html("</td></tr></table>"); |
530 | html("</form>\n"); | 530 | html("</form>\n"); |
531 | 531 | ||
532 | html("<h1>search</h1>\n"); | 532 | html("<h1>search</h1>\n"); |
533 | html("<form method='get' action='"); | 533 | html("<form method='get' action='"); |
534 | if (ctx.cfg.virtual_root) | 534 | if (ctx.cfg.virtual_root) |
diff --git a/ui-summary.c b/ui-summary.c index 0a44994..3baac08 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -161,40 +161,40 @@ void cgit_print_tags(int maxcount) | |||
161 | struct reflist list; | 161 | struct reflist list; |
162 | int i; | 162 | int i; |
163 | 163 | ||
164 | header = 0; | 164 | header = 0; |
165 | list.refs = NULL; | 165 | list.refs = NULL; |
166 | list.alloc = list.count = 0; | 166 | list.alloc = list.count = 0; |
167 | for_each_tag_ref(cgit_refs_cb, &list); | 167 | for_each_tag_ref(cgit_refs_cb, &list); |
168 | if (list.count == 0) | 168 | if (list.count == 0) |
169 | return; | 169 | return; |
170 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); | 170 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); |
171 | if (!maxcount) | 171 | if (!maxcount) |
172 | maxcount = list.count; | 172 | maxcount = list.count; |
173 | else if (maxcount > list.count) | 173 | else if (maxcount > list.count) |
174 | maxcount = list.count; | 174 | maxcount = list.count; |
175 | print_tag_header(); | 175 | print_tag_header(); |
176 | for(i=0; i<maxcount; i++) | 176 | for(i=0; i<maxcount; i++) |
177 | print_tag(list.refs[i]); | 177 | print_tag(list.refs[i]); |
178 | 178 | ||
179 | if (maxcount < list.count) | 179 | if (maxcount < list.count) |
180 | print_refs_link("tags"); | 180 | print_refs_link("tags"); |
181 | } | 181 | } |
182 | 182 | ||
183 | void cgit_print_summary() | 183 | void cgit_print_summary() |
184 | { | 184 | { |
185 | if (cgit_repo->readme) { | 185 | if (ctx.repo->readme) { |
186 | html("<div id='summary'>"); | 186 | html("<div id='summary'>"); |
187 | html_include(cgit_repo->readme); | 187 | html_include(ctx.repo->readme); |
188 | html("</div>"); | 188 | html("</div>"); |
189 | } | 189 | } |
190 | if (ctx.cfg.summary_log > 0) | 190 | if (ctx.cfg.summary_log > 0) |
191 | cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL, | 191 | cgit_print_log(ctx.qry.head, 0, ctx.cfg.summary_log, NULL, |
192 | NULL, NULL, 0); | 192 | NULL, NULL, 0); |
193 | html("<table summary='repository info' class='list nowrap'>"); | 193 | html("<table summary='repository info' class='list nowrap'>"); |
194 | if (ctx.cfg.summary_log > 0) | 194 | if (ctx.cfg.summary_log > 0) |
195 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 195 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
196 | cgit_print_branches(ctx.cfg.summary_branches); | 196 | cgit_print_branches(ctx.cfg.summary_branches); |
197 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 197 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
198 | cgit_print_tags(ctx.cfg.summary_tags); | 198 | cgit_print_tags(ctx.cfg.summary_tags); |
199 | html("</table>"); | 199 | html("</table>"); |
200 | } | 200 | } |
@@ -62,49 +62,49 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen, | |||
62 | const char *pathname, unsigned int mode, int stage) | 62 | const char *pathname, unsigned int mode, int stage) |
63 | { | 63 | { |
64 | char *name; | 64 | char *name; |
65 | char *fullpath; | 65 | char *fullpath; |
66 | enum object_type type; | 66 | enum object_type type; |
67 | unsigned long size = 0; | 67 | unsigned long size = 0; |
68 | 68 | ||
69 | name = xstrdup(pathname); | 69 | name = xstrdup(pathname); |
70 | fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", | 70 | fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", |
71 | ctx.qry.path ? "/" : "", name); | 71 | ctx.qry.path ? "/" : "", name); |
72 | 72 | ||
73 | type = sha1_object_info(sha1, &size); | 73 | type = sha1_object_info(sha1, &size); |
74 | if (type == OBJ_BAD && !S_ISGITLINK(mode)) { | 74 | if (type == OBJ_BAD && !S_ISGITLINK(mode)) { |
75 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", | 75 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", |
76 | name, | 76 | name, |
77 | sha1_to_hex(sha1)); | 77 | sha1_to_hex(sha1)); |
78 | return 0; | 78 | return 0; |
79 | } | 79 | } |
80 | 80 | ||
81 | html("<tr><td class='ls-mode'>"); | 81 | html("<tr><td class='ls-mode'>"); |
82 | html_filemode(mode); | 82 | html_filemode(mode); |
83 | html("</td><td>"); | 83 | html("</td><td>"); |
84 | if (S_ISGITLINK(mode)) { | 84 | if (S_ISGITLINK(mode)) { |
85 | htmlf("<a class='ls-mod' href='"); | 85 | htmlf("<a class='ls-mod' href='"); |
86 | html_attr(fmt(cgit_repo->module_link, | 86 | html_attr(fmt(ctx.repo->module_link, |
87 | name, | 87 | name, |
88 | sha1_to_hex(sha1))); | 88 | sha1_to_hex(sha1))); |
89 | html("'>"); | 89 | html("'>"); |
90 | html_txt(name); | 90 | html_txt(name); |
91 | html("</a>"); | 91 | html("</a>"); |
92 | } else if (S_ISDIR(mode)) { | 92 | } else if (S_ISDIR(mode)) { |
93 | cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, | 93 | cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head, |
94 | curr_rev, fullpath); | 94 | curr_rev, fullpath); |
95 | } else { | 95 | } else { |
96 | cgit_tree_link(name, NULL, "ls-blob", ctx.qry.head, | 96 | cgit_tree_link(name, NULL, "ls-blob", ctx.qry.head, |
97 | curr_rev, fullpath); | 97 | curr_rev, fullpath); |
98 | } | 98 | } |
99 | htmlf("</td><td class='ls-size'>%li</td>", size); | 99 | htmlf("</td><td class='ls-size'>%li</td>", size); |
100 | 100 | ||
101 | html("<td>"); | 101 | html("<td>"); |
102 | cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev, | 102 | cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev, |
103 | fullpath, 0, NULL, NULL); | 103 | fullpath, 0, NULL, NULL); |
104 | html("</td></tr>\n"); | 104 | html("</td></tr>\n"); |
105 | free(name); | 105 | free(name); |
106 | return 0; | 106 | return 0; |
107 | } | 107 | } |
108 | 108 | ||
109 | static void ls_head() | 109 | static void ls_head() |
110 | { | 110 | { |