aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cache.c2
-rw-r--r--cgit.c34
-rw-r--r--cgit.h1
-rw-r--r--configfile.c6
-rw-r--r--html.c6
-rw-r--r--parsing.c6
-rw-r--r--shared.c48
-rw-r--r--ui-atom.c2
-rw-r--r--ui-commit.c1
-rw-r--r--ui-diff.c5
-rw-r--r--ui-log.c6
-rw-r--r--ui-refs.c12
-rw-r--r--ui-repolist.c14
-rw-r--r--ui-shared.c64
-rw-r--r--ui-snapshot.c2
-rw-r--r--ui-stats.c17
-rw-r--r--ui-tag.c2
-rw-r--r--ui-tree.c8
18 files changed, 125 insertions, 111 deletions
diff --git a/cache.c b/cache.c
index 47cdcb4..3127fc2 100644
--- a/cache.c
+++ b/cache.c
@@ -363,7 +363,7 @@ int cache_process(int size, const char *path, const char *key, int ttl,
363/* Return a strftime formatted date/time 363/* Return a strftime formatted date/time
364 * NB: the result from this function is to shared memory 364 * NB: the result from this function is to shared memory
365 */ 365 */
366char *sprintftime(const char *format, time_t time) 366static char *sprintftime(const char *format, time_t time)
367{ 367{
368 static char buf[64]; 368 static char buf[64];
369 struct tm *tm; 369 struct tm *tm;
diff --git a/cgit.c b/cgit.c
index 2ccf864..afafcce 100644
--- a/cgit.c
+++ b/cgit.c
@@ -18,7 +18,7 @@
18 18
19const char *cgit_version = CGIT_VERSION; 19const char *cgit_version = CGIT_VERSION;
20 20
21void add_mimetype(const char *name, const char *value) 21static void add_mimetype(const char *name, const char *value)
22{ 22{
23 struct string_list_item *item; 23 struct string_list_item *item;
24 24
@@ -26,7 +26,7 @@ void add_mimetype(const char *name, const char *value)
26 item->util = xstrdup(value); 26 item->util = xstrdup(value);
27} 27}
28 28
29struct cgit_filter *new_filter(const char *cmd, filter_type filtertype) 29static struct cgit_filter *new_filter(const char *cmd, filter_type filtertype)
30{ 30{
31 struct cgit_filter *f; 31 struct cgit_filter *f;
32 int args_size = 0; 32 int args_size = 0;
@@ -58,7 +58,7 @@ struct cgit_filter *new_filter(const char *cmd, filter_type filtertype)
58 58
59static void process_cached_repolist(const char *path); 59static void process_cached_repolist(const char *path);
60 60
61void repo_config(struct cgit_repo *repo, const char *name, const char *value) 61static void repo_config(struct cgit_repo *repo, const char *name, const char *value)
62{ 62{
63 struct string_list_item *item; 63 struct string_list_item *item;
64 64
@@ -114,7 +114,7 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value)
114 } 114 }
115} 115}
116 116
117void config_cb(const char *name, const char *value) 117static void config_cb(const char *name, const char *value)
118{ 118{
119 if (!strcmp(name, "section") || !strcmp(name, "repo.group")) 119 if (!strcmp(name, "section") || !strcmp(name, "repo.group"))
120 ctx.cfg.section = xstrdup(value); 120 ctx.cfg.section = xstrdup(value);
@@ -333,7 +333,7 @@ static void querystring_cb(const char *name, const char *value)
333 } 333 }
334} 334}
335 335
336char *xstrdupn(const char *str) 336static char *xstrdupn(const char *str)
337{ 337{
338 return (str ? xstrdup(str) : NULL); 338 return (str ? xstrdup(str) : NULL);
339} 339}
@@ -414,8 +414,8 @@ struct refmatch {
414 int match; 414 int match;
415}; 415};
416 416
417int find_current_ref(const char *refname, const unsigned char *sha1, 417static int find_current_ref(const char *refname, const unsigned char *sha1,
418 int flags, void *cb_data) 418 int flags, void *cb_data)
419{ 419{
420 struct refmatch *info; 420 struct refmatch *info;
421 421
@@ -427,7 +427,13 @@ int find_current_ref(const char *refname, const unsigned char *sha1,
427 return info->match; 427 return info->match;
428} 428}
429 429
430char *find_default_branch(struct cgit_repo *repo) 430static void free_refmatch_inner(struct refmatch *info)
431{
432 if (info->first_ref)
433 free(info->first_ref);
434}
435
436static char *find_default_branch(struct cgit_repo *repo)
431{ 437{
432 struct refmatch info; 438 struct refmatch info;
433 char *ref; 439 char *ref;
@@ -442,6 +448,8 @@ char *find_default_branch(struct cgit_repo *repo)
442 ref = info.first_ref; 448 ref = info.first_ref;
443 if (ref) 449 if (ref)
444 ref = xstrdup(ref); 450 ref = xstrdup(ref);
451 free_refmatch_inner(&info);
452
445 return ref; 453 return ref;
446} 454}
447 455
@@ -569,13 +577,13 @@ static void process_request(void *cbdata)
569 cgit_print_docend(); 577 cgit_print_docend();
570} 578}
571 579
572int cmp_repos(const void *a, const void *b) 580static int cmp_repos(const void *a, const void *b)
573{ 581{
574 const struct cgit_repo *ra = a, *rb = b; 582 const struct cgit_repo *ra = a, *rb = b;
575 return strcmp(ra->url, rb->url); 583 return strcmp(ra->url, rb->url);
576} 584}
577 585
578char *build_snapshot_setting(int bitmap) 586static char *build_snapshot_setting(int bitmap)
579{ 587{
580 const struct cgit_snapshot_format *f; 588 const struct cgit_snapshot_format *f;
581 char *result = xstrdup(""); 589 char *result = xstrdup("");
@@ -595,7 +603,7 @@ char *build_snapshot_setting(int bitmap)
595 return result; 603 return result;
596} 604}
597 605
598char *get_first_line(char *txt) 606static char *get_first_line(char *txt)
599{ 607{
600 char *t = xstrdup(txt); 608 char *t = xstrdup(txt);
601 char *p = strchr(t, '\n'); 609 char *p = strchr(t, '\n');
@@ -604,7 +612,7 @@ char *get_first_line(char *txt)
604 return t; 612 return t;
605} 613}
606 614
607void print_repo(FILE *f, struct cgit_repo *repo) 615static void print_repo(FILE *f, struct cgit_repo *repo)
608{ 616{
609 fprintf(f, "repo.url=%s\n", repo->url); 617 fprintf(f, "repo.url=%s\n", repo->url);
610 fprintf(f, "repo.name=%s\n", repo->name); 618 fprintf(f, "repo.name=%s\n", repo->name);
@@ -649,7 +657,7 @@ void print_repo(FILE *f, struct cgit_repo *repo)
649 fprintf(f, "\n"); 657 fprintf(f, "\n");
650} 658}
651 659
652void print_repolist(FILE *f, struct cgit_repolist *list, int start) 660static void print_repolist(FILE *f, struct cgit_repolist *list, int start)
653{ 661{
654 int i; 662 int i;
655 663
diff --git a/cgit.h b/cgit.h
index c655bd8..ed5cf14 100644
--- a/cgit.h
+++ b/cgit.h
@@ -304,6 +304,7 @@ extern char *strlpart(char *txt, int maxlen);
304extern char *strrpart(char *txt, int maxlen); 304extern char *strrpart(char *txt, int maxlen);
305 305
306extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); 306extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
307extern void cgit_free_reflist_inner(struct reflist *list);
307extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, 308extern int cgit_refs_cb(const char *refname, const unsigned char *sha1,
308 int flags, void *cb_data); 309 int flags, void *cb_data);
309 310
diff --git a/configfile.c b/configfile.c
index 3fa217f..d98989c 100644
--- a/configfile.c
+++ b/configfile.c
@@ -10,7 +10,7 @@
10#include <stdio.h> 10#include <stdio.h>
11#include "configfile.h" 11#include "configfile.h"
12 12
13int next_char(FILE *f) 13static int next_char(FILE *f)
14{ 14{
15 int c = fgetc(f); 15 int c = fgetc(f);
16 if (c == '\r') { 16 if (c == '\r') {
@@ -23,7 +23,7 @@ int next_char(FILE *f)
23 return c; 23 return c;
24} 24}
25 25
26void skip_line(FILE *f) 26static void skip_line(FILE *f)
27{ 27{
28 int c; 28 int c;
29 29
@@ -31,7 +31,7 @@ void skip_line(FILE *f)
31 ; 31 ;
32} 32}
33 33
34int read_config_line(FILE *f, char *line, const char **value, int bufsize) 34static int read_config_line(FILE *f, char *line, const char **value, int bufsize)
35{ 35{
36 int i = 0, isname = 0; 36 int i = 0, isname = 0;
37 37
diff --git a/html.c b/html.c
index 90cc1c0..b5c6903 100644
--- a/html.c
+++ b/html.c
@@ -39,7 +39,7 @@ static const char* url_escape_table[256] = {
39 "%fe", "%ff" 39 "%fe", "%ff"
40}; 40};
41 41
42int htmlfd = STDOUT_FILENO; 42static int htmlfd = STDOUT_FILENO;
43 43
44char *fmt(const char *format, ...) 44char *fmt(const char *format, ...)
45{ 45{
@@ -266,7 +266,7 @@ int html_include(const char *filename)
266 return 0; 266 return 0;
267} 267}
268 268
269int hextoint(char c) 269static int hextoint(char c)
270{ 270{
271 if (c >= 'a' && c <= 'f') 271 if (c >= 'a' && c <= 'f')
272 return 10 + c - 'a'; 272 return 10 + c - 'a';
@@ -278,7 +278,7 @@ int hextoint(char c)
278 return -1; 278 return -1;
279} 279}
280 280
281char *convert_query_hexchar(char *txt) 281static char *convert_query_hexchar(char *txt)
282{ 282{
283 int d1, d2, n; 283 int d1, d2, n;
284 n = strlen(txt); 284 n = strlen(txt);
diff --git a/parsing.c b/parsing.c
index 9b7efb3..658621d 100644
--- a/parsing.c
+++ b/parsing.c
@@ -52,7 +52,7 @@ void cgit_parse_url(const char *url)
52 } 52 }
53} 53}
54 54
55char *substr(const char *head, const char *tail) 55static char *substr(const char *head, const char *tail)
56{ 56{
57 char *buf; 57 char *buf;
58 58
@@ -64,7 +64,7 @@ char *substr(const char *head, const char *tail)
64 return buf; 64 return buf;
65} 65}
66 66
67char *parse_user(char *t, char **name, char **email, unsigned long *date) 67static char *parse_user(char *t, char **name, char **email, unsigned long *date)
68{ 68{
69 char *p = t; 69 char *p = t;
70 int mode = 1; 70 int mode = 1;
@@ -101,7 +101,7 @@ char *parse_user(char *t, char **name, char **email, unsigned long *date)
101#ifdef NO_ICONV 101#ifdef NO_ICONV
102#define reencode(a, b, c) 102#define reencode(a, b, c)
103#else 103#else
104const char *reencode(char **txt, const char *src_enc, const char *dst_enc) 104static const char *reencode(char **txt, const char *src_enc, const char *dst_enc)
105{ 105{
106 char *tmp; 106 char *tmp;
107 107
diff --git a/shared.c b/shared.c
index e732064..cc06930 100644
--- a/shared.c
+++ b/shared.c
@@ -158,7 +158,7 @@ void cgit_add_ref(struct reflist *list, struct refinfo *ref)
158 list->refs[list->count++] = ref; 158 list->refs[list->count++] = ref;
159} 159}
160 160
161struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char *sha1) 161static struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char *sha1)
162{ 162{
163 struct refinfo *ref; 163 struct refinfo *ref;
164 164
@@ -176,6 +176,42 @@ struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char *sha1)
176 return ref; 176 return ref;
177} 177}
178 178
179static void cgit_free_taginfo(struct taginfo *tag)
180{
181 if (tag->tagger)
182 free(tag->tagger);
183 if (tag->tagger_email)
184 free(tag->tagger_email);
185 if (tag->msg)
186 free(tag->msg);
187 free(tag);
188}
189
190static void cgit_free_refinfo(struct refinfo *ref)
191{
192 if (ref->refname)
193 free((char *)ref->refname);
194 switch (ref->object->type) {
195 case OBJ_TAG:
196 cgit_free_taginfo(ref->tag);
197 break;
198 case OBJ_COMMIT:
199 cgit_free_commitinfo(ref->commit);
200 break;
201 }
202 free(ref);
203}
204
205void cgit_free_reflist_inner(struct reflist *list)
206{
207 int i;
208
209 for (i = 0; i < list->count; i++) {
210 cgit_free_refinfo(list->refs[i]);
211 }
212 free(list->refs);
213}
214
179int cgit_refs_cb(const char *refname, const unsigned char *sha1, int flags, 215int cgit_refs_cb(const char *refname, const unsigned char *sha1, int flags,
180 void *cb_data) 216 void *cb_data)
181{ 217{
@@ -187,8 +223,8 @@ int cgit_refs_cb(const char *refname, const unsigned char *sha1, int flags,
187 return 0; 223 return 0;
188} 224}
189 225
190void cgit_diff_tree_cb(struct diff_queue_struct *q, 226static void cgit_diff_tree_cb(struct diff_queue_struct *q,
191 struct diff_options *options, void *data) 227 struct diff_options *options, void *data)
192{ 228{
193 int i; 229 int i;
194 230
@@ -224,7 +260,7 @@ static int load_mmfile(mmfile_t *file, const unsigned char *sha1)
224char *diffbuf = NULL; 260char *diffbuf = NULL;
225int buflen = 0; 261int buflen = 0;
226 262
227int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf) 263static int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf)
228{ 264{
229 int i; 265 int i;
230 266
@@ -461,14 +497,14 @@ int readfile(const char *path, char **buf, size_t *size)
461 return (*size == st.st_size ? 0 : e); 497 return (*size == st.st_size ? 0 : e);
462} 498}
463 499
464int is_token_char(char c) 500static int is_token_char(char c)
465{ 501{
466 return isalnum(c) || c == '_'; 502 return isalnum(c) || c == '_';
467} 503}
468 504
469/* Replace name with getenv(name), return pointer to zero-terminating char 505/* Replace name with getenv(name), return pointer to zero-terminating char
470 */ 506 */
471char *expand_macro(char *name, int maxlength) 507static char *expand_macro(char *name, int maxlength)
472{ 508{
473 char *value; 509 char *value;
474 int len; 510 int len;
diff --git a/ui-atom.c b/ui-atom.c
index b218456..5b5525d 100644
--- a/ui-atom.c
+++ b/ui-atom.c
@@ -10,7 +10,7 @@
10#include "html.h" 10#include "html.h"
11#include "ui-shared.h" 11#include "ui-shared.h"
12 12
13void add_entry(struct commit *commit, char *host) 13static void add_entry(struct commit *commit, char *host)
14{ 14{
15 char delim = '&'; 15 char delim = '&';
16 char *hex; 16 char *hex;
diff --git a/ui-commit.c b/ui-commit.c
index 74f37c8..0783285 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -74,6 +74,7 @@ void cgit_print_commit(char *hex, const char *prefix)
74 html(" /"); 74 html(" /");
75 cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix); 75 cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix);
76 } 76 }
77 free(tmp);
77 html("</td></tr>\n"); 78 html("</td></tr>\n");
78 for (p = commit->parents; p; p = p->next) { 79 for (p = commit->parents; p; p = p->next) {
79 parent = lookup_commit_reference(p->item->object.sha1); 80 parent = lookup_commit_reference(p->item->object.sha1);
diff --git a/ui-diff.c b/ui-diff.c
index 49e5b46..7de7802 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -166,8 +166,9 @@ static void inspect_filepair(struct diff_filepair *pair)
166 total_rems += lines_removed; 166 total_rems += lines_removed;
167} 167}
168 168
169void cgit_print_diffstat(const unsigned char *old_sha1, 169static void cgit_print_diffstat(const unsigned char *old_sha1,
170 const unsigned char *new_sha1, const char *prefix) 170 const unsigned char *new_sha1,
171 const char *prefix)
171{ 172{
172 int i; 173 int i;
173 174
diff --git a/ui-log.c b/ui-log.c
index 2f41602..857c05c 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -28,7 +28,7 @@ static const char *column_colors_html[] = {
28 28
29#define COLUMN_COLORS_HTML_MAX (ARRAY_SIZE(column_colors_html) - 1) 29#define COLUMN_COLORS_HTML_MAX (ARRAY_SIZE(column_colors_html) - 1)
30 30
31void count_lines(char *line, int size) 31static void count_lines(char *line, int size)
32{ 32{
33 if (size <= 0) 33 if (size <= 0)
34 return; 34 return;
@@ -40,7 +40,7 @@ void count_lines(char *line, int size)
40 rem_lines++; 40 rem_lines++;
41} 41}
42 42
43void inspect_files(struct diff_filepair *pair) 43static void inspect_files(struct diff_filepair *pair)
44{ 44{
45 unsigned long old_size = 0; 45 unsigned long old_size = 0;
46 unsigned long new_size = 0; 46 unsigned long new_size = 0;
@@ -95,7 +95,7 @@ next:
95 } 95 }
96} 96}
97 97
98void print_commit(struct commit *commit, struct rev_info *revs) 98static void print_commit(struct commit *commit, struct rev_info *revs)
99{ 99{
100 struct commitinfo *info; 100 struct commitinfo *info;
101 int cols = revs->graph ? 3 : 2; 101 int cols = revs->graph ? 3 : 2;
diff --git a/ui-refs.c b/ui-refs.c
index ce06b08..e89f836 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -103,6 +103,7 @@ static void print_tag_downloads(const struct cgit_repo *repo, const char *ref)
103 const struct cgit_snapshot_format* f; 103 const struct cgit_snapshot_format* f;
104 char *filename; 104 char *filename;
105 const char *basename; 105 const char *basename;
106 int free_ref = 0;
106 107
107 if (!ref || strlen(ref) < 2) 108 if (!ref || strlen(ref) < 2)
108 return; 109 return;
@@ -111,8 +112,10 @@ static void print_tag_downloads(const struct cgit_repo *repo, const char *ref)
111 if (prefixcmp(ref, basename) != 0) { 112 if (prefixcmp(ref, basename) != 0) {
112 if ((ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1])) 113 if ((ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1]))
113 ref++; 114 ref++;
114 if (isdigit(ref[0])) 115 if (isdigit(ref[0])) {
115 ref = xstrdup(fmt("%s-%s", basename, ref)); 116 ref = xstrdup(fmt("%s-%s", basename, ref));
117 free_ref = 1;
118 }
116 } 119 }
117 120
118 for (f = cgit_snapshot_formats; f->suffix; f++) { 121 for (f = cgit_snapshot_formats; f->suffix; f++) {
@@ -122,6 +125,9 @@ static void print_tag_downloads(const struct cgit_repo *repo, const char *ref)
122 cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename); 125 cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename);
123 html("&nbsp;&nbsp;"); 126 html("&nbsp;&nbsp;");
124 } 127 }
128
129 if (free_ref)
130 free((char *)ref);
125} 131}
126static int print_tag(struct refinfo *ref) 132static int print_tag(struct refinfo *ref)
127{ 133{
@@ -205,6 +211,8 @@ void cgit_print_branches(int maxcount)
205 211
206 if (maxcount < list.count) 212 if (maxcount < list.count)
207 print_refs_link("heads"); 213 print_refs_link("heads");
214
215 cgit_free_reflist_inner(&list);
208} 216}
209 217
210void cgit_print_tags(int maxcount) 218void cgit_print_tags(int maxcount)
@@ -229,6 +237,8 @@ void cgit_print_tags(int maxcount)
229 237
230 if (maxcount < list.count) 238 if (maxcount < list.count)
231 print_refs_link("tags"); 239 print_refs_link("tags");
240
241 cgit_free_reflist_inner(&list);
232} 242}
233 243
234void cgit_print_refs() 244void cgit_print_refs()
diff --git a/ui-repolist.c b/ui-repolist.c
index 1ae22aa..66c88c4 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -12,7 +12,7 @@
12#include "ui-shared.h" 12#include "ui-shared.h"
13#include <strings.h> 13#include <strings.h>
14 14
15time_t read_agefile(char *path) 15static time_t read_agefile(char *path)
16{ 16{
17 time_t result; 17 time_t result;
18 size_t size; 18 size_t size;
@@ -76,7 +76,7 @@ static void print_modtime(struct cgit_repo *repo)
76 cgit_print_age(t, -1, NULL); 76 cgit_print_age(t, -1, NULL);
77} 77}
78 78
79int is_match(struct cgit_repo *repo) 79static int is_match(struct cgit_repo *repo)
80{ 80{
81 if (!ctx.qry.search) 81 if (!ctx.qry.search)
82 return 1; 82 return 1;
@@ -91,7 +91,7 @@ int is_match(struct cgit_repo *repo)
91 return 0; 91 return 0;
92} 92}
93 93
94int is_in_url(struct cgit_repo *repo) 94static int is_in_url(struct cgit_repo *repo)
95{ 95{
96 if (!ctx.qry.url) 96 if (!ctx.qry.url)
97 return 1; 97 return 1;
@@ -100,7 +100,7 @@ int is_in_url(struct cgit_repo *repo)
100 return 0; 100 return 0;
101} 101}
102 102
103void print_sort_header(const char *title, const char *sort) 103static void print_sort_header(const char *title, const char *sort)
104{ 104{
105 htmlf("<th class='left'><a href='%s?s=%s", cgit_rooturl(), sort); 105 htmlf("<th class='left'><a href='%s?s=%s", cgit_rooturl(), sort);
106 if (ctx.qry.search) { 106 if (ctx.qry.search) {
@@ -110,7 +110,7 @@ void print_sort_header(const char *title, const char *sort)
110 htmlf("'>%s</a></th>", title); 110 htmlf("'>%s</a></th>", title);
111} 111}
112 112
113void print_header() 113static void print_header()
114{ 114{
115 html("<tr class='nohover'>"); 115 html("<tr class='nohover'>");
116 print_sort_header("Name", "name"); 116 print_sort_header("Name", "name");
@@ -124,7 +124,7 @@ void print_header()
124} 124}
125 125
126 126
127void print_pager(int items, int pagelen, char *search, char *sort) 127static void print_pager(int items, int pagelen, char *search, char *sort)
128{ 128{
129 int i, ofs; 129 int i, ofs;
130 char *class = NULL; 130 char *class = NULL;
@@ -223,7 +223,7 @@ struct sortcolumn sortcolumn[] = {
223 {NULL, NULL} 223 {NULL, NULL}
224}; 224};
225 225
226int sort_repolist(char *field) 226static int sort_repolist(char *field)
227{ 227{
228 struct sortcolumn *column; 228 struct sortcolumn *column;
229 229
diff --git a/ui-shared.c b/ui-shared.c
index 80f4aee..968933f 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -121,18 +121,6 @@ const char *cgit_repobasename(const char *reponame)
121 return rvbuf; 121 return rvbuf;
122} 122}
123 123
124char *cgit_currurl()
125{
126 if (!ctx.cfg.virtual_root)
127 return ctx.cfg.script_name;
128 else if (ctx.qry.page)
129 return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page);
130 else if (ctx.qry.repo)
131 return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo);
132 else
133 return fmt("%s/", ctx.cfg.virtual_root);
134}
135
136static void site_url(const char *page, const char *search, const char *sort, int ofs) 124static void site_url(const char *page, const char *search, const char *sort, int ofs)
137{ 125{
138 char *delim = "?"; 126 char *delim = "?";
@@ -433,8 +421,8 @@ void cgit_stats_link(const char *name, const char *title, const char *class,
433 reporevlink("stats", name, title, class, head, NULL, path); 421 reporevlink("stats", name, title, class, head, NULL, path);
434} 422}
435 423
436void cgit_self_link(char *name, const char *title, const char *class, 424static void cgit_self_link(char *name, const char *title, const char *class,
437 struct cgit_context *ctx) 425 struct cgit_context *ctx)
438{ 426{
439 if (!strcmp(ctx->qry.page, "repolist")) 427 if (!strcmp(ctx->qry.page, "repolist"))
440 cgit_index_link(name, title, class, ctx->qry.search, ctx->qry.sort, 428 cgit_index_link(name, title, class, ctx->qry.search, ctx->qry.sort,
@@ -513,8 +501,8 @@ void cgit_object_link(struct object *obj)
513 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); 501 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
514} 502}
515 503
516struct string_list_item *lookup_path(struct string_list *list, 504static struct string_list_item *lookup_path(struct string_list *list,
517 const char *path) 505 const char *path)
518{ 506{
519 struct string_list_item *item; 507 struct string_list_item *item;
520 508
@@ -717,53 +705,14 @@ void cgit_print_docend()
717 html("</body>\n</html>\n"); 705 html("</body>\n</html>\n");
718} 706}
719 707
720int print_branch_option(const char *refname, const unsigned char *sha1, 708static int print_branch_option(const char *refname, const unsigned char *sha1,
721 int flags, void *cb_data) 709 int flags, void *cb_data)
722{ 710{
723 char *name = (char *)refname; 711 char *name = (char *)refname;
724 html_option(name, name, ctx.qry.head); 712 html_option(name, name, ctx.qry.head);
725 return 0; 713 return 0;
726} 714}
727 715
728int print_archive_ref(const char *refname, const unsigned char *sha1,
729 int flags, void *cb_data)
730{
731 struct tag *tag;
732 struct taginfo *info;
733 struct object *obj;
734 char buf[256], *url;
735 unsigned char fileid[20];
736 int *header = (int *)cb_data;
737
738 if (prefixcmp(refname, "refs/archives"))
739 return 0;
740 strncpy(buf, refname + 14, sizeof(buf));
741 obj = parse_object(sha1);
742 if (!obj)
743 return 1;
744 if (obj->type == OBJ_TAG) {
745 tag = lookup_tag(sha1);
746 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
747 return 0;
748 hashcpy(fileid, tag->tagged->sha1);
749 } else if (obj->type != OBJ_BLOB) {
750 return 0;
751 } else {
752 hashcpy(fileid, sha1);
753 }
754 if (!*header) {
755 html("<h1>download</h1>\n");
756 *header = 1;
757 }
758 url = cgit_pageurl(ctx.qry.repo, "blob",
759 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid),
760 buf));
761 html_link_open(url, NULL, "menu");
762 html_txt(strlpart(buf, 20));
763 html_link_close();
764 return 0;
765}
766
767void cgit_add_hidden_formfields(int incl_head, int incl_search, 716void cgit_add_hidden_formfields(int incl_head, int incl_search,
768 const char *page) 717 const char *page)
769{ 718{
@@ -983,4 +932,5 @@ void cgit_print_snapshot_links(const char *repo, const char *head,
983 cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename); 932 cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename);
984 html("<br/>"); 933 html("<br/>");
985 } 934 }
935 free(prefix);
986} 936}
diff --git a/ui-snapshot.c b/ui-snapshot.c
index 54e659c..e199a92 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -153,7 +153,7 @@ static const char *get_ref_from_filename(const char *url, const char *filename,
153 return NULL; 153 return NULL;
154} 154}
155 155
156void show_error(char *msg) 156static void show_error(char *msg)
157{ 157{
158 ctx.page.mimetype = "text/html"; 158 ctx.page.mimetype = "text/html";
159 cgit_print_http_headers(&ctx); 159 cgit_print_http_headers(&ctx);
diff --git a/ui-stats.c b/ui-stats.c
index 9cf1dbd..480c8ee 100644
--- a/ui-stats.c
+++ b/ui-stats.c
@@ -211,8 +211,8 @@ static int cmp_total_commits(const void *a1, const void *a2)
211/* Walk the commit DAG and collect number of commits per author per 211/* Walk the commit DAG and collect number of commits per author per
212 * timeperiod into a nested string_list collection. 212 * timeperiod into a nested string_list collection.
213 */ 213 */
214struct string_list collect_stats(struct cgit_context *ctx, 214static struct string_list collect_stats(struct cgit_context *ctx,
215 struct cgit_period *period) 215 struct cgit_period *period)
216{ 216{
217 struct string_list authors; 217 struct string_list authors;
218 struct rev_info rev; 218 struct rev_info rev;
@@ -253,9 +253,12 @@ struct string_list collect_stats(struct cgit_context *ctx,
253 return authors; 253 return authors;
254} 254}
255 255
256void print_combined_authorrow(struct string_list *authors, int from, int to, 256static void print_combined_authorrow(struct string_list *authors, int from,
257 const char *name, const char *leftclass, const char *centerclass, 257 int to, const char *name,
258 const char *rightclass, struct cgit_period *period) 258 const char *leftclass,
259 const char *centerclass,
260 const char *rightclass,
261 struct cgit_period *period)
259{ 262{
260 struct string_list_item *author; 263 struct string_list_item *author;
261 struct authorstat *authorstat; 264 struct authorstat *authorstat;
@@ -293,8 +296,8 @@ void print_combined_authorrow(struct string_list *authors, int from, int to,
293 htmlf("<td class='%s'>%ld</td></tr>", rightclass, total); 296 htmlf("<td class='%s'>%ld</td></tr>", rightclass, total);
294} 297}
295 298
296void print_authors(struct string_list *authors, int top, 299static void print_authors(struct string_list *authors, int top,
297 struct cgit_period *period) 300 struct cgit_period *period)
298{ 301{
299 struct string_list_item *author; 302 struct string_list_item *author;
300 struct authorstat *authorstat; 303 struct authorstat *authorstat;
diff --git a/ui-tag.c b/ui-tag.c
index cab96b1..4d340d4 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -30,7 +30,7 @@ static void print_tag_content(char *buf)
30 } 30 }
31} 31}
32 32
33void print_download_links(char *revname) 33static void print_download_links(char *revname)
34{ 34{
35 html("<tr><th>download</th><td class='sha1'>"); 35 html("<tr><th>download</th><td class='sha1'>");
36 cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head, 36 cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
diff --git a/ui-tree.c b/ui-tree.c
index 561f9e7..b692b56 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -271,7 +271,6 @@ void cgit_print_tree(const char *rev, char *path)
271 if (!rev) 271 if (!rev)
272 rev = ctx.qry.head; 272 rev = ctx.qry.head;
273 273
274 walk_tree_ctx.curr_rev = xstrdup(rev);
275 if (get_sha1(rev, sha1)) { 274 if (get_sha1(rev, sha1)) {
276 cgit_print_error(fmt("Invalid revision name: %s", rev)); 275 cgit_print_error(fmt("Invalid revision name: %s", rev));
277 return; 276 return;
@@ -282,12 +281,17 @@ void cgit_print_tree(const char *rev, char *path)
282 return; 281 return;
283 } 282 }
284 283
284 walk_tree_ctx.curr_rev = xstrdup(rev);
285
285 if (path == NULL) { 286 if (path == NULL) {
286 ls_tree(commit->tree->object.sha1, NULL, &walk_tree_ctx); 287 ls_tree(commit->tree->object.sha1, NULL, &walk_tree_ctx);
287 return; 288 goto cleanup;
288 } 289 }
289 290
290 read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); 291 read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx);
291 if (walk_tree_ctx.state == 1) 292 if (walk_tree_ctx.state == 1)
292 ls_tail(); 293 ls_tail();
294
295cleanup:
296 free(walk_tree_ctx.curr_rev);
293} 297}