diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | cgit.c | 69 | ||||
-rw-r--r-- | cgit.h | 8 | ||||
-rw-r--r-- | ui-repolist.c | 60 | ||||
-rw-r--r-- | ui-shared.c | 21 |
5 files changed, 90 insertions, 70 deletions
diff --git a/Makefile b/Makefile index a4291f7..81ebb18 100644 --- a/Makefile +++ b/Makefile | |||
@@ -5,7 +5,7 @@ INSTALL_CSS = /var/www/htdocs/cgit.css | |||
5 | CACHE_ROOT = /var/cache/cgit | 5 | CACHE_ROOT = /var/cache/cgit |
6 | 6 | ||
7 | EXTLIBS = ../git/libgit.a ../git/xdiff/lib.a -lz -lcrypto | 7 | EXTLIBS = ../git/libgit.a ../git/xdiff/lib.a -lz -lcrypto |
8 | OBJECTS = parsing.o html.o cache.o ui-shared.o | 8 | OBJECTS = parsing.o html.o cache.o ui-shared.o ui-repolist.o |
9 | 9 | ||
10 | CFLAGS += -Wall | 10 | CFLAGS += -Wall |
11 | 11 | ||
diff --git a/cgit.c b/cgit.c index 5438fa1..b3ff512 100644 --- a/cgit.c +++ b/cgit.c | |||
@@ -84,26 +84,6 @@ void cgit_querystring_cb(const char *name, const char *value) | |||
84 | } | 84 | } |
85 | } | 85 | } |
86 | 86 | ||
87 | char *cgit_repourl(const char *reponame) | ||
88 | { | ||
89 | if (cgit_virtual_root) { | ||
90 | return fmt("%s/%s/", cgit_virtual_root, reponame); | ||
91 | } else { | ||
92 | return fmt("?r=%s", reponame); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | char *cgit_pageurl(const char *reponame, const char *pagename, | ||
97 | const char *query) | ||
98 | { | ||
99 | if (cgit_virtual_root) { | ||
100 | return fmt("%s/%s/%s/?%s", cgit_virtual_root, reponame, | ||
101 | pagename, query); | ||
102 | } else { | ||
103 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, | 87 | static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, |
108 | int flags, void *cb_data) | 88 | int flags, void *cb_data) |
109 | { | 89 | { |
@@ -134,55 +114,6 @@ static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, | |||
134 | return 0; | 114 | return 0; |
135 | } | 115 | } |
136 | 116 | ||
137 | static void cgit_print_repolist(struct cacheitem *item) | ||
138 | { | ||
139 | DIR *d; | ||
140 | struct dirent *de; | ||
141 | struct stat st; | ||
142 | char *name; | ||
143 | |||
144 | chdir(cgit_root); | ||
145 | cgit_print_docstart(cgit_root_title, item); | ||
146 | cgit_print_pageheader(cgit_root_title); | ||
147 | |||
148 | if (!(d = opendir("."))) { | ||
149 | cgit_print_error(fmt("Unable to scan repository directory: %s", | ||
150 | strerror(errno))); | ||
151 | cgit_print_docend(); | ||
152 | return; | ||
153 | } | ||
154 | |||
155 | html("<h2>Repositories</h2>\n"); | ||
156 | html("<table class='list'>"); | ||
157 | html("<tr><th>Name</th><th>Description</th><th>Owner</th></tr>\n"); | ||
158 | while ((de = readdir(d)) != NULL) { | ||
159 | if (de->d_name[0] == '.') | ||
160 | continue; | ||
161 | if (stat(de->d_name, &st) < 0) | ||
162 | continue; | ||
163 | if (!S_ISDIR(st.st_mode)) | ||
164 | continue; | ||
165 | |||
166 | cgit_repo_name = cgit_repo_desc = cgit_repo_owner = NULL; | ||
167 | name = fmt("%s/info/cgit", de->d_name); | ||
168 | if (cgit_read_config(name, cgit_repo_config_cb)) | ||
169 | continue; | ||
170 | |||
171 | html("<tr><td>"); | ||
172 | html_link_open(cgit_repourl(de->d_name), NULL, NULL); | ||
173 | html_txt(cgit_repo_name); | ||
174 | html_link_close(); | ||
175 | html("</td><td>"); | ||
176 | html_txt(cgit_repo_desc); | ||
177 | html("</td><td>"); | ||
178 | html_txt(cgit_repo_owner); | ||
179 | html("</td></tr>\n"); | ||
180 | } | ||
181 | closedir(d); | ||
182 | html("</table>"); | ||
183 | cgit_print_docend(); | ||
184 | } | ||
185 | |||
186 | static void cgit_print_branches() | 117 | static void cgit_print_branches() |
187 | { | 118 | { |
188 | html("<table class='list'>"); | 119 | html("<table class='list'>"); |
diff --git a/cgit.h b/cgit.h index e64fbd7..bf5bd8d 100644 --- a/cgit.h +++ b/cgit.h | |||
@@ -65,10 +65,18 @@ extern int cache_unlock(struct cacheitem *item); | |||
65 | extern int cache_exist(struct cacheitem *item); | 65 | extern int cache_exist(struct cacheitem *item); |
66 | extern int cache_expired(struct cacheitem *item); | 66 | extern int cache_expired(struct cacheitem *item); |
67 | 67 | ||
68 | extern char *cgit_repourl(const char *reponame); | ||
69 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | ||
70 | const char *query); | ||
71 | |||
68 | extern void cgit_print_error(char *msg); | 72 | extern void cgit_print_error(char *msg); |
69 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 73 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
70 | extern void cgit_print_docend(); | 74 | extern void cgit_print_docend(); |
71 | extern void cgit_print_pageheader(char *title); | 75 | extern void cgit_print_pageheader(char *title); |
72 | 76 | ||
77 | extern void cgit_print_repolist(struct cacheitem *item); | ||
78 | |||
79 | |||
80 | extern void cgit_repo_config_cb(const char *name, const char *value); | ||
73 | 81 | ||
74 | #endif /* CGIT_H */ | 82 | #endif /* CGIT_H */ |
diff --git a/ui-repolist.c b/ui-repolist.c new file mode 100644 index 0000000..1fe7059 --- /dev/null +++ b/ui-repolist.c | |||
@@ -0,0 +1,60 @@ | |||
1 | /* ui-repolist.c: functions for generating the repolist page | ||
2 | * | ||
3 | * Copyright (C) 2006 Lars Hjemli | ||
4 | * | ||
5 | * Licensed under GNU General Public License v2 | ||
6 | * (see COPYING for full license text) | ||
7 | */ | ||
8 | |||
9 | #include "cgit.h" | ||
10 | |||
11 | void cgit_print_repolist(struct cacheitem *item) | ||
12 | { | ||
13 | DIR *d; | ||
14 | struct dirent *de; | ||
15 | struct stat st; | ||
16 | char *name; | ||
17 | |||
18 | chdir(cgit_root); | ||
19 | cgit_print_docstart(cgit_root_title, item); | ||
20 | cgit_print_pageheader(cgit_root_title); | ||
21 | |||
22 | if (!(d = opendir("."))) { | ||
23 | cgit_print_error(fmt("Unable to scan repository directory: %s", | ||
24 | strerror(errno))); | ||
25 | cgit_print_docend(); | ||
26 | return; | ||
27 | } | ||
28 | |||
29 | html("<h2>Repositories</h2>\n"); | ||
30 | html("<table class='list'>"); | ||
31 | html("<tr><th>Name</th><th>Description</th><th>Owner</th></tr>\n"); | ||
32 | while ((de = readdir(d)) != NULL) { | ||
33 | if (de->d_name[0] == '.') | ||
34 | continue; | ||
35 | if (stat(de->d_name, &st) < 0) | ||
36 | continue; | ||
37 | if (!S_ISDIR(st.st_mode)) | ||
38 | continue; | ||
39 | |||
40 | cgit_repo_name = cgit_repo_desc = cgit_repo_owner = NULL; | ||
41 | name = fmt("%s/info/cgit", de->d_name); | ||
42 | if (cgit_read_config(name, cgit_repo_config_cb)) | ||
43 | continue; | ||
44 | |||
45 | html("<tr><td>"); | ||
46 | html_link_open(cgit_repourl(de->d_name), NULL, NULL); | ||
47 | html_txt(cgit_repo_name); | ||
48 | html_link_close(); | ||
49 | html("</td><td>"); | ||
50 | html_txt(cgit_repo_desc); | ||
51 | html("</td><td>"); | ||
52 | html_txt(cgit_repo_owner); | ||
53 | html("</td></tr>\n"); | ||
54 | } | ||
55 | closedir(d); | ||
56 | html("</table>"); | ||
57 | cgit_print_docend(); | ||
58 | } | ||
59 | |||
60 | |||
diff --git a/ui-shared.c b/ui-shared.c index e795043..cb8a8df 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -39,6 +39,27 @@ void cgit_print_error(char *msg) | |||
39 | html_txt(msg); | 39 | html_txt(msg); |
40 | html("</div>\n"); | 40 | html("</div>\n"); |
41 | } | 41 | } |
42 | |||
43 | char *cgit_repourl(const char *reponame) | ||
44 | { | ||
45 | if (cgit_virtual_root) { | ||
46 | return fmt("%s/%s/", cgit_virtual_root, reponame); | ||
47 | } else { | ||
48 | return fmt("?r=%s", reponame); | ||
49 | } | ||
50 | } | ||
51 | |||
52 | char *cgit_pageurl(const char *reponame, const char *pagename, | ||
53 | const char *query) | ||
54 | { | ||
55 | if (cgit_virtual_root) { | ||
56 | return fmt("%s/%s/%s/?%s", cgit_virtual_root, reponame, | ||
57 | pagename, query); | ||
58 | } else { | ||
59 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); | ||
60 | } | ||
61 | } | ||
62 | |||
42 | void cgit_print_docstart(char *title, struct cacheitem *item) | 63 | void cgit_print_docstart(char *title, struct cacheitem *item) |
43 | { | 64 | { |
44 | html("Content-Type: text/html; charset=utf-8\n"); | 65 | html("Content-Type: text/html; charset=utf-8\n"); |