summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.css2
-rw-r--r--cgit.h2
-rw-r--r--cgitrc7
-rw-r--r--html.c3
-rw-r--r--shared.c6
-rw-r--r--ui-tree.c19
6 files changed, 27 insertions, 12 deletions
diff --git a/cgit.css b/cgit.css
index 640bbc9..ef4bc62 100644
--- a/cgit.css
+++ b/cgit.css
@@ -1,271 +1,271 @@
1body { 1body {
2 font-family: arial; 2 font-family: arial;
3 font-size: 11pt; 3 font-size: 11pt;
4 background: white; 4 background: white;
5 padding: 0em; 5 padding: 0em;
6 margin: 0em; 6 margin: 0em;
7} 7}
8 8
9 9
10h2 { 10h2 {
11 font-size: 120%; 11 font-size: 120%;
12 font-weight: bold; 12 font-weight: bold;
13 margin-bottom: 0.25em; 13 margin-bottom: 0.25em;
14} 14}
15 15
16h3 { 16h3 {
17 margin-top: 0em; 17 margin-top: 0em;
18 font-size: 100%; 18 font-size: 100%;
19 font-weight: normal; 19 font-weight: normal;
20} 20}
21 21
22a { 22a {
23 color: blue; 23 color: blue;
24 text-decoration: none; 24 text-decoration: none;
25} 25}
26 26
27a:hover { 27a:hover {
28 text-decoration: underline; 28 text-decoration: underline;
29} 29}
30 30
31table.list { 31table.list {
32 border: none; 32 border: none;
33 border-collapse: collapse; 33 border-collapse: collapse;
34} 34}
35 35
36table.list tr { 36table.list tr {
37 background: white; 37 background: white;
38} 38}
39 39
40table.list tr:hover { 40table.list tr:hover {
41 background: #eee; 41 background: #eee;
42} 42}
43 43
44table.list tr.nohover:hover { 44table.list tr.nohover:hover {
45 background: white; 45 background: white;
46} 46}
47 47
48table.list th { 48table.list th {
49 font-weight: normal; 49 font-weight: normal;
50 border-bottom: solid 1px #777; 50 border-bottom: solid 1px #777;
51 padding: 0.1em 0.5em 0.1em 0.5em; 51 padding: 0.1em 0.5em 0.1em 0.5em;
52 vertical-align: baseline; 52 vertical-align: baseline;
53} 53}
54 54
55table.list td { 55table.list td {
56 border: none; 56 border: none;
57 padding: 0.1em 0.5em 0.1em 0.5em; 57 padding: 0.1em 0.5em 0.1em 0.5em;
58} 58}
59 59
60img { 60img {
61 border: none; 61 border: none;
62} 62}
63 63
64table#layout { 64table#layout {
65 width: 100%; 65 width: 100%;
66 border-collapse: separate; 66 border-collapse: separate;
67 border-spacing: 0px; 67 border-spacing: 0px;
68 margin: 0px; 68 margin: 0px;
69} 69}
70 70
71td#header, td#logo { 71td#header, td#logo {
72 color: #666; 72 color: #666;
73 background-color: #ddd; 73 background-color: #ddd;
74 border-bottom: solid 1px #000; 74 border-bottom: solid 1px #000;
75} 75}
76 76
77td#header { 77td#header {
78 font-size: 150%; 78 font-size: 150%;
79 font-weight: bold; 79 font-weight: bold;
80 padding: 0.2em 0.5em; 80 padding: 0.2em 0.5em;
81 vertical-align: text-bottom; 81 vertical-align: text-bottom;
82} 82}
83 83
84td#logo { 84td#logo {
85 text-align: right; 85 text-align: right;
86 vertical-align: middle; 86 vertical-align: middle;
87 padding-right: 0.5em; 87 padding-right: 0.5em;
88} 88}
89 89
90td#crumb, td#search { 90td#crumb, td#search {
91 color: #ccc; 91 color: #ccc;
92 border-top: solid 3px #555; 92 border-top: solid 3px #555;
93 background-color: #666; 93 background-color: #666;
94 border-bottom: solid 1px #333; 94 border-bottom: solid 1px #333;
95 padding: 2px 1em; 95 padding: 2px 1em;
96} 96}
97 97
98td#crumb { 98td#crumb {
99 font-weight: bold; 99 font-weight: bold;
100} 100}
101 101
102td#crumb a { 102td#crumb a {
103 color: #ccc; 103 color: #ccc;
104} 104}
105 105
106td#crumb a:hover { 106td#crumb a:hover {
107 color: #eee; 107 color: #eee;
108} 108}
109 109
110td#search { 110td#search {
111 text-align: right; 111 text-align: right;
112 vertical-align: center; 112 vertical-align: center;
113 padding-right: 0.5em; 113 padding-right: 0.5em;
114} 114}
115 115
116td#search form { 116td#search form {
117 margin: 0px; 117 margin: 0px;
118 padding: 0px; 118 padding: 0px;
119} 119}
120 120
121td#search input { 121td#search input {
122 font-size: 9pt; 122 font-size: 9pt;
123 padding: 0px; 123 padding: 0px;
124 width: 10em; 124 width: 10em;
125 border: solid 1px #333; 125 border: solid 1px #333;
126 color: #333; 126 color: #333;
127 background-color: #fff; 127 background-color: #fff;
128} 128}
129 129
130td#content { 130td#content {
131 padding: 1em 0.5em; 131 padding: 1em 0.5em;
132} 132}
133 133
134div#blob { 134div#blob {
135 border: solid 1px black; 135 border: solid 1px black;
136} 136}
137 137
138div.error { 138div.error {
139 color: red; 139 color: red;
140 font-weight: bold; 140 font-weight: bold;
141 margin: 1em 2em; 141 margin: 1em 2em;
142} 142}
143 143
144div.ls-blob, div.ls-dir { 144td.ls-blob, td.ls-dir, td.ls-mod {
145 font-family: monospace; 145 font-family: monospace;
146} 146}
147 147
148div.ls-dir a { 148div.ls-dir a {
149 font-weight: bold; 149 font-weight: bold;
150} 150}
151 151
152th.filesize, td.filesize { 152th.filesize, td.filesize {
153 text-align: right; 153 text-align: right;
154} 154}
155 155
156td.filesize { 156td.filesize {
157 font-family: monospace; 157 font-family: monospace;
158} 158}
159 159
160td.filemode { 160td.filemode {
161 font-family: monospace; 161 font-family: monospace;
162} 162}
163 163
164td.blob { 164td.blob {
165 white-space: pre; 165 white-space: pre;
166 font-family: monospace; 166 font-family: monospace;
167 background-color: white; 167 background-color: white;
168} 168}
169 169
170table.nowrap td { 170table.nowrap td {
171 white-space: nowrap; 171 white-space: nowrap;
172} 172}
173 173
174table.commit-info { 174table.commit-info {
175 border-collapse: collapse; 175 border-collapse: collapse;
176 margin-top: 1.5em; 176 margin-top: 1.5em;
177} 177}
178 178
179table.commit-info th { 179table.commit-info th {
180 text-align: left; 180 text-align: left;
181 font-weight: normal; 181 font-weight: normal;
182 padding: 0.1em 1em 0.1em 0.1em; 182 padding: 0.1em 1em 0.1em 0.1em;
183} 183}
184 184
185table.commit-info td { 185table.commit-info td {
186 font-weight: normal; 186 font-weight: normal;
187 padding: 0.1em 1em 0.1em 0.1em; 187 padding: 0.1em 1em 0.1em 0.1em;
188} 188}
189 189
190div.commit-subject { 190div.commit-subject {
191 font-weight: bold; 191 font-weight: bold;
192 font-size: 125%; 192 font-size: 125%;
193 margin: 1.5em 0em 0.5em 0em; 193 margin: 1.5em 0em 0.5em 0em;
194 padding: 0em; 194 padding: 0em;
195} 195}
196 196
197div.commit-msg { 197div.commit-msg {
198 white-space: pre; 198 white-space: pre;
199 font-family: monospace; 199 font-family: monospace;
200} 200}
201 201
202table.diffstat { 202table.diffstat {
203 border-collapse: collapse; 203 border-collapse: collapse;
204 margin-top: 1.5em; 204 margin-top: 1.5em;
205} 205}
206 206
207table.diffstat th { 207table.diffstat th {
208 font-weight: normal; 208 font-weight: normal;
209 text-align: left; 209 text-align: left;
210 text-decoration: underline; 210 text-decoration: underline;
211 padding: 0.1em 1em 0.1em 0.1em; 211 padding: 0.1em 1em 0.1em 0.1em;
212 font-size: 100%; 212 font-size: 100%;
213} 213}
214 214
215table.diffstat td { 215table.diffstat td {
216 padding: 0.1em 1em 0.1em 0.1em; 216 padding: 0.1em 1em 0.1em 0.1em;
217 font-size: 100%; 217 font-size: 100%;
218} 218}
219 219
220table.diffstat td span.modechange { 220table.diffstat td span.modechange {
221 padding-left: 1em; 221 padding-left: 1em;
222 color: red; 222 color: red;
223} 223}
224 224
225table.diffstat td.add a { 225table.diffstat td.add a {
226 color: green; 226 color: green;
227} 227}
228 228
229table.diffstat td.del a { 229table.diffstat td.del a {
230 color: red; 230 color: red;
231} 231}
232 232
233table.diffstat td.upd a { 233table.diffstat td.upd a {
234 color: blue; 234 color: blue;
235} 235}
236 236
237table.diffstat td.summary { 237table.diffstat td.summary {
238 color: #888; 238 color: #888;
239 padding-top: 0.5em; 239 padding-top: 0.5em;
240} 240}
241 241
242table.diff td { 242table.diff td {
243 border: solid 1px black; 243 border: solid 1px black;
244 font-family: monospace; 244 font-family: monospace;
245 white-space: pre; 245 white-space: pre;
246} 246}
247 247
248table.diff td div.hunk { 248table.diff td div.hunk {
249 background: #ccc; 249 background: #ccc;
250} 250}
251 251
252table.diff td div.add { 252table.diff td div.add {
253 color: green; 253 color: green;
254} 254}
255 255
256table.diff td div.del { 256table.diff td div.del {
257 color: red; 257 color: red;
258} 258}
259 259
260.sha1 { 260.sha1 {
261 font-family: courier; 261 font-family: courier;
262 font-size: 90%; 262 font-size: 90%;
263} 263}
264 264
265.left { 265.left {
266 text-align: left; 266 text-align: left;
267} 267}
268 268
269.right { 269.right {
270 text-align: right; 270 text-align: right;
271} 271}
diff --git a/cgit.h b/cgit.h
index 292e488..b7f8827 100644
--- a/cgit.h
+++ b/cgit.h
@@ -1,167 +1,169 @@
1#ifndef CGIT_H 1#ifndef CGIT_H
2#define CGIT_H 2#define CGIT_H
3 3
4 4
5#include <git-compat-util.h> 5#include <git-compat-util.h>
6#include <cache.h> 6#include <cache.h>
7#include <grep.h> 7#include <grep.h>
8#include <object.h> 8#include <object.h>
9#include <tree.h> 9#include <tree.h>
10#include <commit.h> 10#include <commit.h>
11#include <tag.h> 11#include <tag.h>
12#include <diff.h> 12#include <diff.h>
13#include <diffcore.h> 13#include <diffcore.h>
14#include <refs.h> 14#include <refs.h>
15#include <revision.h> 15#include <revision.h>
16#include <log-tree.h> 16#include <log-tree.h>
17#include <archive.h> 17#include <archive.h>
18#include <xdiff/xdiff.h> 18#include <xdiff/xdiff.h>
19 19
20 20
21typedef void (*configfn)(const char *name, const char *value); 21typedef void (*configfn)(const char *name, const char *value);
22 22
23struct cacheitem { 23struct cacheitem {
24 char *name; 24 char *name;
25 struct stat st; 25 struct stat st;
26 int ttl; 26 int ttl;
27 int fd; 27 int fd;
28}; 28};
29 29
30struct repoinfo { 30struct repoinfo {
31 char *url; 31 char *url;
32 char *name; 32 char *name;
33 char *path; 33 char *path;
34 char *desc; 34 char *desc;
35 char *owner; 35 char *owner;
36 char *module_link;
36 int snapshots; 37 int snapshots;
37}; 38};
38 39
39struct repolist { 40struct repolist {
40 int length; 41 int length;
41 int count; 42 int count;
42 struct repoinfo *repos; 43 struct repoinfo *repos;
43}; 44};
44 45
45struct commitinfo { 46struct commitinfo {
46 struct commit *commit; 47 struct commit *commit;
47 char *author; 48 char *author;
48 char *author_email; 49 char *author_email;
49 unsigned long author_date; 50 unsigned long author_date;
50 char *committer; 51 char *committer;
51 char *committer_email; 52 char *committer_email;
52 unsigned long committer_date; 53 unsigned long committer_date;
53 char *subject; 54 char *subject;
54 char *msg; 55 char *msg;
55}; 56};
56 57
57struct taginfo { 58struct taginfo {
58 char *tagger; 59 char *tagger;
59 char *tagger_email; 60 char *tagger_email;
60 int tagger_date; 61 int tagger_date;
61 char *msg; 62 char *msg;
62}; 63};
63 64
64extern const char cgit_version[]; 65extern const char cgit_version[];
65 66
66extern struct repolist cgit_repolist; 67extern struct repolist cgit_repolist;
67extern struct repoinfo *cgit_repo; 68extern struct repoinfo *cgit_repo;
68 69
69extern char *cgit_root_title; 70extern char *cgit_root_title;
70extern char *cgit_css; 71extern char *cgit_css;
71extern char *cgit_logo; 72extern char *cgit_logo;
72extern char *cgit_logo_link; 73extern char *cgit_logo_link;
74extern char *cgit_module_link;
73extern char *cgit_virtual_root; 75extern char *cgit_virtual_root;
74extern char *cgit_cache_root; 76extern char *cgit_cache_root;
75 77
76extern int cgit_nocache; 78extern int cgit_nocache;
77extern int cgit_snapshots; 79extern int cgit_snapshots;
78extern int cgit_max_lock_attempts; 80extern int cgit_max_lock_attempts;
79extern int cgit_cache_root_ttl; 81extern int cgit_cache_root_ttl;
80extern int cgit_cache_repo_ttl; 82extern int cgit_cache_repo_ttl;
81extern int cgit_cache_dynamic_ttl; 83extern int cgit_cache_dynamic_ttl;
82extern int cgit_cache_static_ttl; 84extern int cgit_cache_static_ttl;
83extern int cgit_cache_max_create_time; 85extern int cgit_cache_max_create_time;
84 86
85extern int cgit_max_msg_len; 87extern int cgit_max_msg_len;
86 88
87extern char *cgit_repo_name; 89extern char *cgit_repo_name;
88extern char *cgit_repo_desc; 90extern char *cgit_repo_desc;
89extern char *cgit_repo_owner; 91extern char *cgit_repo_owner;
90 92
91extern int cgit_query_has_symref; 93extern int cgit_query_has_symref;
92extern int cgit_query_has_sha1; 94extern int cgit_query_has_sha1;
93 95
94extern char *cgit_querystring; 96extern char *cgit_querystring;
95extern char *cgit_query_repo; 97extern char *cgit_query_repo;
96extern char *cgit_query_page; 98extern char *cgit_query_page;
97extern char *cgit_query_search; 99extern char *cgit_query_search;
98extern char *cgit_query_head; 100extern char *cgit_query_head;
99extern char *cgit_query_sha1; 101extern char *cgit_query_sha1;
100extern char *cgit_query_sha2; 102extern char *cgit_query_sha2;
101extern char *cgit_query_path; 103extern char *cgit_query_path;
102extern char *cgit_query_name; 104extern char *cgit_query_name;
103extern int cgit_query_ofs; 105extern int cgit_query_ofs;
104 106
105extern int htmlfd; 107extern int htmlfd;
106 108
107extern void cgit_global_config_cb(const char *name, const char *value); 109extern void cgit_global_config_cb(const char *name, const char *value);
108extern void cgit_repo_config_cb(const char *name, const char *value); 110extern void cgit_repo_config_cb(const char *name, const char *value);
109extern void cgit_querystring_cb(const char *name, const char *value); 111extern void cgit_querystring_cb(const char *name, const char *value);
110 112
111extern int chk_zero(int result, char *msg); 113extern int chk_zero(int result, char *msg);
112extern int chk_positive(int result, char *msg); 114extern int chk_positive(int result, char *msg);
113 115
114extern int hextoint(char c); 116extern int hextoint(char c);
115 117
116extern void *cgit_free_commitinfo(struct commitinfo *info); 118extern void *cgit_free_commitinfo(struct commitinfo *info);
117 119
118extern char *fmt(const char *format,...); 120extern char *fmt(const char *format,...);
119 121
120extern void html(const char *txt); 122extern void html(const char *txt);
121extern void htmlf(const char *format,...); 123extern void htmlf(const char *format,...);
122extern void html_txt(char *txt); 124extern void html_txt(char *txt);
123extern void html_ntxt(int len, char *txt); 125extern void html_ntxt(int len, char *txt);
124extern void html_attr(char *txt); 126extern void html_attr(char *txt);
125extern void html_hidden(char *name, char *value); 127extern void html_hidden(char *name, char *value);
126extern void html_link_open(char *url, char *title, char *class); 128extern void html_link_open(char *url, char *title, char *class);
127extern void html_link_close(void); 129extern void html_link_close(void);
128extern void html_filemode(unsigned short mode); 130extern void html_filemode(unsigned short mode);
129 131
130extern int cgit_read_config(const char *filename, configfn fn); 132extern int cgit_read_config(const char *filename, configfn fn);
131extern int cgit_parse_query(char *txt, configfn fn); 133extern int cgit_parse_query(char *txt, configfn fn);
132extern struct commitinfo *cgit_parse_commit(struct commit *commit); 134extern struct commitinfo *cgit_parse_commit(struct commit *commit);
133extern struct taginfo *cgit_parse_tag(struct tag *tag); 135extern struct taginfo *cgit_parse_tag(struct tag *tag);
134 136
135extern char *cache_safe_filename(const char *unsafe); 137extern char *cache_safe_filename(const char *unsafe);
136extern int cache_lock(struct cacheitem *item); 138extern int cache_lock(struct cacheitem *item);
137extern int cache_unlock(struct cacheitem *item); 139extern int cache_unlock(struct cacheitem *item);
138extern int cache_cancel_lock(struct cacheitem *item); 140extern int cache_cancel_lock(struct cacheitem *item);
139extern int cache_exist(struct cacheitem *item); 141extern int cache_exist(struct cacheitem *item);
140extern int cache_expired(struct cacheitem *item); 142extern int cache_expired(struct cacheitem *item);
141 143
142extern char *cgit_repourl(const char *reponame); 144extern char *cgit_repourl(const char *reponame);
143extern char *cgit_pageurl(const char *reponame, const char *pagename, 145extern char *cgit_pageurl(const char *reponame, const char *pagename,
144 const char *query); 146 const char *query);
145 147
146extern void cgit_print_error(char *msg); 148extern void cgit_print_error(char *msg);
147extern void cgit_print_date(unsigned long secs); 149extern void cgit_print_date(unsigned long secs);
148extern void cgit_print_docstart(char *title, struct cacheitem *item); 150extern void cgit_print_docstart(char *title, struct cacheitem *item);
149extern void cgit_print_docend(); 151extern void cgit_print_docend();
150extern void cgit_print_pageheader(char *title, int show_search); 152extern void cgit_print_pageheader(char *title, int show_search);
151extern void cgit_print_snapshot_start(const char *mimetype, 153extern void cgit_print_snapshot_start(const char *mimetype,
152 const char *filename, 154 const char *filename,
153 struct cacheitem *item); 155 struct cacheitem *item);
154 156
155extern void cgit_print_repolist(struct cacheitem *item); 157extern void cgit_print_repolist(struct cacheitem *item);
156extern void cgit_print_summary(); 158extern void cgit_print_summary();
157extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep); 159extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep);
158extern void cgit_print_view(const char *hex, char *path); 160extern void cgit_print_view(const char *hex, char *path);
159extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); 161extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path);
160extern void cgit_print_tree(const char *hex, char *path); 162extern void cgit_print_tree(const char *hex, char *path);
161extern void cgit_print_commit(const char *hex); 163extern void cgit_print_commit(const char *hex);
162extern void cgit_print_diff(const char *old_hex, const char *new_hex); 164extern void cgit_print_diff(const char *old_hex, const char *new_hex);
163extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, 165extern void cgit_print_snapshot(struct cacheitem *item, const char *hex,
164 const char *format, const char *prefix, 166 const char *format, const char *prefix,
165 const char *filename); 167 const char *filename);
166 168
167#endif /* CGIT_H */ 169#endif /* CGIT_H */
diff --git a/cgitrc b/cgitrc
index 3bae642..f217b39 100644
--- a/cgitrc
+++ b/cgitrc
@@ -1,84 +1,89 @@
1## 1##
2## cgitrc: template for /etc/cgitrc 2## cgitrc: template for /etc/cgitrc
3## 3##
4 4
5 5
6## Uncomment and set to 1 to deactivate caching of generated pages. Mostly 6## Uncomment and set to 1 to deactivate caching of generated pages. Mostly
7## usefull for testing. 7## usefull for testing.
8#nocache=0 8#nocache=0
9 9
10 10
11## Enable/disable snapshots by default. This can be overridden per repo 11## Enable/disable snapshots by default. This can be overridden per repo
12#snapshots=0 12#snapshots=0
13 13
14 14
15## Specify a root for virtual urls. This makes cgit generate urls like 15## Specify a root for virtual urls. This makes cgit generate urls like
16## 16##
17## http://localhost/git/repo/log/?id=master 17## http://localhost/git/repo/log/?id=master
18## 18##
19## instead of 19## instead of
20## 20##
21## http://localhost/cgit/cgit.cgi?r=repo&p=log&id=master 21## http://localhost/cgit/cgit.cgi?r=repo&p=log&id=master
22## 22##
23## For this to work with apache, rewrite rules must be added to httpd.conf, 23## For this to work with apache, rewrite rules must be added to httpd.conf,
24## possibly looking something like this: 24## possibly looking something like this:
25## 25##
26## RewriteRule ^/git/$ /cgit/cgit.cgi [L,QSA] 26## RewriteRule ^/git/$ /cgit/cgit.cgi [L,QSA]
27## RewriteRule ^/git/([^/]+)/$ /cgit/cgit.cgi?r=$1 [L,QSA] 27## RewriteRule ^/git/([^/]+)/$ /cgit/cgit.cgi?r=$1 [L,QSA]
28## RewriteRule ^/git/([^/]+)/([^/]+)/$ /cgit/cgit.cgi?r=$1&p=$2 [L,QSA] 28## RewriteRule ^/git/([^/]+)/([^/]+)/$ /cgit/cgit.cgi?r=$1&p=$2 [L,QSA]
29## 29##
30## This setting is disabled by default. 30## This setting is disabled by default.
31#virtual-root=/git 31#virtual-root=/git
32 32
33 33
34## Set the title printed on the root page 34## Set the title printed on the root page
35#root-title=Git repository browser 35#root-title=Git repository browser
36 36
37 37
38## Link to css file 38## Link to css file
39#css=/cgit/cgit.css 39#css=/cgit/cgit.css
40 40
41 41
42## Link to logo file 42## Link to logo file
43#logo=/cgit/git-logo.png 43#logo=/cgit/git-logo.png
44 44
45 45
46## Url loaded when clicking the logo 46## Url loaded when clicking the logo
47#logo-link=http://www.kernel.org/pub/software/scm/git/docs/ 47#logo-link=http://www.kernel.org/pub/software/scm/git/docs/
48 48
49 49
50## Url loaded when clicking a submodule link
51#module-link=./?repo=%s&page=commit&id=%s
52
53
50## Number of chars shown of commit subject message (in log view) 54## Number of chars shown of commit subject message (in log view)
51#max-message-length=60 55#max-message-length=60
52 56
53 57
54## Root of cached output 58## Root of cached output
55#cache-root=/var/cache/cgit 59#cache-root=/var/cache/cgit
56 60
57 61
58## 62##
59## Time-To-Live settings: specifies how long (in minutes) different pages 63## Time-To-Live settings: specifies how long (in minutes) different pages
60## should be cached (0 for instant expiration, -1 for immortal pages) 64## should be cached (0 for instant expiration, -1 for immortal pages)
61## 65##
62 66
63## ttl for root page 67## ttl for root page
64#cache-root-ttl=5 68#cache-root-ttl=5
65 69
66## ttl for repo summary page 70## ttl for repo summary page
67#cache-repo-ttl=5 71#cache-repo-ttl=5
68 72
69## ttl for other dynamic pages 73## ttl for other dynamic pages
70#cache-dynamic-ttl=5 74#cache-dynamic-ttl=5
71 75
72## ttl for static pages (addressed by SHA-1) 76## ttl for static pages (addressed by SHA-1)
73#cache-static-ttl=-1 77#cache-static-ttl=-1
74 78
75 79
76 80
77## Example repository entry. Required values are repo.url and repo.path (each 81## Example repository entry. Required values are repo.url and repo.path (each
78## repository section must start with repo.url). 82## repository section must start with repo.url).
79#repo.url=cgit 83#repo.url=cgit
80#repo.name=cgit 84#repo.name=cgit
81#repo.desc=the caching cgi for git 85#repo.desc=the caching cgi for git
82#repo.path=/pub/git/cgit 86#repo.path=/pub/git/cgit
83#repo.owner=Lars Hjemli 87#repo.owner=Lars Hjemli
84#repo.snapshots=1 # override a sitewide snapshot-setting 88 #repo.snapshots=1 # override a sitewide snapshot-setting
89 #repo.module-link=/git/%s/commit/?id=%s # override the standard module-link
diff --git a/html.c b/html.c
index c0b2ed4..175b4b6 100644
--- a/html.c
+++ b/html.c
@@ -1,167 +1,168 @@
1/* html.c: helper functions for html output 1/* html.c: helper functions for html output
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
11char *fmt(const char *format, ...) 11char *fmt(const char *format, ...)
12{ 12{
13 static char buf[8][1024]; 13 static char buf[8][1024];
14 static int bufidx; 14 static int bufidx;
15 int len; 15 int len;
16 va_list args; 16 va_list args;
17 17
18 bufidx++; 18 bufidx++;
19 bufidx &= 7; 19 bufidx &= 7;
20 20
21 va_start(args, format); 21 va_start(args, format);
22 len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); 22 len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args);
23 va_end(args); 23 va_end(args);
24 if (len>sizeof(buf[bufidx])) 24 if (len>sizeof(buf[bufidx]))
25 die("[html.c] string truncated: %s", format); 25 die("[html.c] string truncated: %s", format);
26 return buf[bufidx]; 26 return buf[bufidx];
27} 27}
28 28
29void html(const char *txt) 29void html(const char *txt)
30{ 30{
31 write(htmlfd, txt, strlen(txt)); 31 write(htmlfd, txt, strlen(txt));
32} 32}
33 33
34void htmlf(const char *format, ...) 34void htmlf(const char *format, ...)
35{ 35{
36 static char buf[65536]; 36 static char buf[65536];
37 va_list args; 37 va_list args;
38 38
39 va_start(args, format); 39 va_start(args, format);
40 vsnprintf(buf, sizeof(buf), format, args); 40 vsnprintf(buf, sizeof(buf), format, args);
41 va_end(args); 41 va_end(args);
42 html(buf); 42 html(buf);
43} 43}
44 44
45void html_txt(char *txt) 45void html_txt(char *txt)
46{ 46{
47 char *t = txt; 47 char *t = txt;
48 while(t && *t){ 48 while(t && *t){
49 int c = *t; 49 int c = *t;
50 if (c=='<' || c=='>' || c=='&') { 50 if (c=='<' || c=='>' || c=='&') {
51 *t = '\0'; 51 *t = '\0';
52 html(txt); 52 html(txt);
53 *t = c; 53 *t = c;
54 if (c=='>') 54 if (c=='>')
55 html("&gt;"); 55 html("&gt;");
56 else if (c=='<') 56 else if (c=='<')
57 html("&lt;"); 57 html("&lt;");
58 else if (c=='&') 58 else if (c=='&')
59 html("&amp;"); 59 html("&amp;");
60 txt = t+1; 60 txt = t+1;
61 } 61 }
62 t++; 62 t++;
63 } 63 }
64 if (t!=txt) 64 if (t!=txt)
65 html(txt); 65 html(txt);
66} 66}
67 67
68void html_ntxt(int len, char *txt) 68void html_ntxt(int len, char *txt)
69{ 69{
70 char *t = txt; 70 char *t = txt;
71 while(t && *t && len--){ 71 while(t && *t && len--){
72 int c = *t; 72 int c = *t;
73 if (c=='<' || c=='>' || c=='&') { 73 if (c=='<' || c=='>' || c=='&') {
74 *t = '\0'; 74 *t = '\0';
75 html(txt); 75 html(txt);
76 *t = c; 76 *t = c;
77 if (c=='>') 77 if (c=='>')
78 html("&gt;"); 78 html("&gt;");
79 else if (c=='<') 79 else if (c=='<')
80 html("&lt;"); 80 html("&lt;");
81 else if (c=='&') 81 else if (c=='&')
82 html("&amp;"); 82 html("&amp;");
83 txt = t+1; 83 txt = t+1;
84 } 84 }
85 t++; 85 t++;
86 } 86 }
87 if (t!=txt) { 87 if (t!=txt) {
88 char c = *t; 88 char c = *t;
89 *t = '\0'; 89 *t = '\0';
90 html(txt); 90 html(txt);
91 *t = c; 91 *t = c;
92 } 92 }
93 if (len<0) 93 if (len<0)
94 html("..."); 94 html("...");
95} 95}
96 96
97void html_attr(char *txt) 97void html_attr(char *txt)
98{ 98{
99 char *t = txt; 99 char *t = txt;
100 while(t && *t){ 100 while(t && *t){
101 int c = *t; 101 int c = *t;
102 if (c=='<' || c=='>' || c=='\'') { 102 if (c=='<' || c=='>' || c=='\'') {
103 *t = '\0'; 103 *t = '\0';
104 html(txt); 104 html(txt);
105 *t = c; 105 *t = c;
106 if (c=='>') 106 if (c=='>')
107 html("&gt;"); 107 html("&gt;");
108 else if (c=='<') 108 else if (c=='<')
109 html("&lt;"); 109 html("&lt;");
110 else if (c=='\'') 110 else if (c=='\'')
111 html("&quote;"); 111 html("&quote;");
112 txt = t+1; 112 txt = t+1;
113 } 113 }
114 t++; 114 t++;
115 } 115 }
116 if (t!=txt) 116 if (t!=txt)
117 html(txt); 117 html(txt);
118} 118}
119 119
120void html_hidden(char *name, char *value) 120void html_hidden(char *name, char *value)
121{ 121{
122 html("<input type='hidden' name='"); 122 html("<input type='hidden' name='");
123 html_attr(name); 123 html_attr(name);
124 html("' value='"); 124 html("' value='");
125 html_attr(value); 125 html_attr(value);
126 html("'/>"); 126 html("'/>");
127} 127}
128 128
129void html_link_open(char *url, char *title, char *class) 129void html_link_open(char *url, char *title, char *class)
130{ 130{
131 html("<a href='"); 131 html("<a href='");
132 html_attr(url); 132 html_attr(url);
133 if (title) { 133 if (title) {
134 html("' title='"); 134 html("' title='");
135 html_attr(title); 135 html_attr(title);
136 } 136 }
137 if (class) { 137 if (class) {
138 html("' class='"); 138 html("' class='");
139 html_attr(class); 139 html_attr(class);
140 } 140 }
141 html("'>"); 141 html("'>");
142} 142}
143 143
144void html_link_close(void) 144void html_link_close(void)
145{ 145{
146 html("</a>"); 146 html("</a>");
147} 147}
148 148
149void html_fileperm(unsigned short mode) 149void html_fileperm(unsigned short mode)
150{ 150{
151 htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), 151 htmlf("%c%c%c", (mode & 4 ? 'r' : '-'),
152 (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); 152 (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-'));
153} 153}
154 154
155void html_filemode(unsigned short mode) 155void html_filemode(unsigned short mode)
156{ 156{
157 if (S_ISDIR(mode)) 157 if (S_ISDIR(mode))
158 html("d"); 158 html("d");
159 else if (S_ISLNK(mode)) 159 else if (S_ISLNK(mode))
160 html("l"); 160 html("l");
161 else if (S_ISDIRLNK(mode))
162 html("m");
161 else 163 else
162 html("-"); 164 html("-");
163 html_fileperm(mode >> 6); 165 html_fileperm(mode >> 6);
164 html_fileperm(mode >> 3); 166 html_fileperm(mode >> 3);
165 html_fileperm(mode); 167 html_fileperm(mode);
166} 168}
167
diff --git a/shared.c b/shared.c
index 531d8c0..19d2df0 100644
--- a/shared.c
+++ b/shared.c
@@ -1,191 +1,197 @@
1/* shared.c: global vars + some callback functions 1/* shared.c: global vars + some callback functions
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10 10
11struct repolist cgit_repolist; 11struct repolist cgit_repolist;
12struct repoinfo *cgit_repo; 12struct repoinfo *cgit_repo;
13 13
14char *cgit_root_title = "Git repository browser"; 14char *cgit_root_title = "Git repository browser";
15char *cgit_css = "/cgit.css"; 15char *cgit_css = "/cgit.css";
16char *cgit_logo = "/git-logo.png"; 16char *cgit_logo = "/git-logo.png";
17char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; 17char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/";
18char *cgit_module_link = "./?repo=%s&page=commit&id=%s";
18char *cgit_virtual_root = NULL; 19char *cgit_virtual_root = NULL;
19 20
20char *cgit_cache_root = "/var/cache/cgit"; 21char *cgit_cache_root = "/var/cache/cgit";
21 22
22int cgit_nocache = 0; 23int cgit_nocache = 0;
23int cgit_snapshots = 0; 24int cgit_snapshots = 0;
24int cgit_max_lock_attempts = 5; 25int cgit_max_lock_attempts = 5;
25int cgit_cache_root_ttl = 5; 26int cgit_cache_root_ttl = 5;
26int cgit_cache_repo_ttl = 5; 27int cgit_cache_repo_ttl = 5;
27int cgit_cache_dynamic_ttl = 5; 28int cgit_cache_dynamic_ttl = 5;
28int cgit_cache_static_ttl = -1; 29int cgit_cache_static_ttl = -1;
29int cgit_cache_max_create_time = 5; 30int cgit_cache_max_create_time = 5;
30 31
31int cgit_max_msg_len = 60; 32int cgit_max_msg_len = 60;
32 33
33char *cgit_repo_name = NULL; 34char *cgit_repo_name = NULL;
34char *cgit_repo_desc = NULL; 35char *cgit_repo_desc = NULL;
35char *cgit_repo_owner = NULL; 36char *cgit_repo_owner = NULL;
36 37
37int cgit_query_has_symref = 0; 38int cgit_query_has_symref = 0;
38int cgit_query_has_sha1 = 0; 39int cgit_query_has_sha1 = 0;
39 40
40char *cgit_querystring = NULL; 41char *cgit_querystring = NULL;
41char *cgit_query_repo = NULL; 42char *cgit_query_repo = NULL;
42char *cgit_query_page = NULL; 43char *cgit_query_page = NULL;
43char *cgit_query_head = NULL; 44char *cgit_query_head = NULL;
44char *cgit_query_search = NULL; 45char *cgit_query_search = NULL;
45char *cgit_query_sha1 = NULL; 46char *cgit_query_sha1 = NULL;
46char *cgit_query_sha2 = NULL; 47char *cgit_query_sha2 = NULL;
47char *cgit_query_path = NULL; 48char *cgit_query_path = NULL;
48char *cgit_query_name = NULL; 49char *cgit_query_name = NULL;
49int cgit_query_ofs = 0; 50int cgit_query_ofs = 0;
50 51
51int htmlfd = 0; 52int htmlfd = 0;
52 53
53int chk_zero(int result, char *msg) 54int chk_zero(int result, char *msg)
54{ 55{
55 if (result != 0) 56 if (result != 0)
56 die("%s: %s", msg, strerror(errno)); 57 die("%s: %s", msg, strerror(errno));
57 return result; 58 return result;
58} 59}
59 60
60int chk_positive(int result, char *msg) 61int chk_positive(int result, char *msg)
61{ 62{
62 if (result <= 0) 63 if (result <= 0)
63 die("%s: %s", msg, strerror(errno)); 64 die("%s: %s", msg, strerror(errno));
64 return result; 65 return result;
65} 66}
66 67
67struct repoinfo *add_repo(const char *url) 68struct repoinfo *add_repo(const char *url)
68{ 69{
69 struct repoinfo *ret; 70 struct repoinfo *ret;
70 71
71 if (++cgit_repolist.count > cgit_repolist.length) { 72 if (++cgit_repolist.count > cgit_repolist.length) {
72 if (cgit_repolist.length == 0) 73 if (cgit_repolist.length == 0)
73 cgit_repolist.length = 8; 74 cgit_repolist.length = 8;
74 else 75 else
75 cgit_repolist.length *= 2; 76 cgit_repolist.length *= 2;
76 cgit_repolist.repos = xrealloc(cgit_repolist.repos, 77 cgit_repolist.repos = xrealloc(cgit_repolist.repos,
77 cgit_repolist.length * 78 cgit_repolist.length *
78 sizeof(struct repoinfo)); 79 sizeof(struct repoinfo));
79 } 80 }
80 81
81 ret = &cgit_repolist.repos[cgit_repolist.count-1]; 82 ret = &cgit_repolist.repos[cgit_repolist.count-1];
82 ret->url = xstrdup(url); 83 ret->url = xstrdup(url);
83 ret->name = ret->url; 84 ret->name = ret->url;
84 ret->path = NULL; 85 ret->path = NULL;
85 ret->desc = NULL; 86 ret->desc = NULL;
86 ret->owner = NULL; 87 ret->owner = NULL;
87 ret->snapshots = cgit_snapshots; 88 ret->snapshots = cgit_snapshots;
89 ret->module_link = cgit_module_link;
88 return ret; 90 return ret;
89} 91}
90 92
91void cgit_global_config_cb(const char *name, const char *value) 93void cgit_global_config_cb(const char *name, const char *value)
92{ 94{
93 if (!strcmp(name, "root-title")) 95 if (!strcmp(name, "root-title"))
94 cgit_root_title = xstrdup(value); 96 cgit_root_title = xstrdup(value);
95 else if (!strcmp(name, "css")) 97 else if (!strcmp(name, "css"))
96 cgit_css = xstrdup(value); 98 cgit_css = xstrdup(value);
97 else if (!strcmp(name, "logo")) 99 else if (!strcmp(name, "logo"))
98 cgit_logo = xstrdup(value); 100 cgit_logo = xstrdup(value);
99 else if (!strcmp(name, "logo-link")) 101 else if (!strcmp(name, "logo-link"))
100 cgit_logo_link = xstrdup(value); 102 cgit_logo_link = xstrdup(value);
103 else if (!strcmp(name, "module-link"))
104 cgit_module_link = xstrdup(value);
101 else if (!strcmp(name, "virtual-root")) 105 else if (!strcmp(name, "virtual-root"))
102 cgit_virtual_root = xstrdup(value); 106 cgit_virtual_root = xstrdup(value);
103 else if (!strcmp(name, "nocache")) 107 else if (!strcmp(name, "nocache"))
104 cgit_nocache = atoi(value); 108 cgit_nocache = atoi(value);
105 else if (!strcmp(name, "snapshots")) 109 else if (!strcmp(name, "snapshots"))
106 cgit_snapshots = atoi(value); 110 cgit_snapshots = atoi(value);
107 else if (!strcmp(name, "cache-root")) 111 else if (!strcmp(name, "cache-root"))
108 cgit_cache_root = xstrdup(value); 112 cgit_cache_root = xstrdup(value);
109 else if (!strcmp(name, "cache-root-ttl")) 113 else if (!strcmp(name, "cache-root-ttl"))
110 cgit_cache_root_ttl = atoi(value); 114 cgit_cache_root_ttl = atoi(value);
111 else if (!strcmp(name, "cache-repo-ttl")) 115 else if (!strcmp(name, "cache-repo-ttl"))
112 cgit_cache_repo_ttl = atoi(value); 116 cgit_cache_repo_ttl = atoi(value);
113 else if (!strcmp(name, "cache-static-ttl")) 117 else if (!strcmp(name, "cache-static-ttl"))
114 cgit_cache_static_ttl = atoi(value); 118 cgit_cache_static_ttl = atoi(value);
115 else if (!strcmp(name, "cache-dynamic-ttl")) 119 else if (!strcmp(name, "cache-dynamic-ttl"))
116 cgit_cache_dynamic_ttl = atoi(value); 120 cgit_cache_dynamic_ttl = atoi(value);
117 else if (!strcmp(name, "max-message-length")) 121 else if (!strcmp(name, "max-message-length"))
118 cgit_max_msg_len = atoi(value); 122 cgit_max_msg_len = atoi(value);
119 else if (!strcmp(name, "repo.url")) 123 else if (!strcmp(name, "repo.url"))
120 cgit_repo = add_repo(value); 124 cgit_repo = add_repo(value);
121 else if (!strcmp(name, "repo.name")) 125 else if (!strcmp(name, "repo.name"))
122 cgit_repo->name = xstrdup(value); 126 cgit_repo->name = xstrdup(value);
123 else if (cgit_repo && !strcmp(name, "repo.path")) 127 else if (cgit_repo && !strcmp(name, "repo.path"))
124 cgit_repo->path = xstrdup(value); 128 cgit_repo->path = xstrdup(value);
125 else if (cgit_repo && !strcmp(name, "repo.desc")) 129 else if (cgit_repo && !strcmp(name, "repo.desc"))
126 cgit_repo->desc = xstrdup(value); 130 cgit_repo->desc = xstrdup(value);
127 else if (cgit_repo && !strcmp(name, "repo.owner")) 131 else if (cgit_repo && !strcmp(name, "repo.owner"))
128 cgit_repo->owner = xstrdup(value); 132 cgit_repo->owner = xstrdup(value);
129 else if (cgit_repo && !strcmp(name, "repo.snapshots")) 133 else if (cgit_repo && !strcmp(name, "repo.snapshots"))
130 cgit_repo->snapshots = atoi(value); 134 cgit_repo->snapshots = atoi(value);
135 else if (cgit_repo && !strcmp(name, "repo.module-link"))
136 cgit_repo->module_link= xstrdup(value);
131} 137}
132 138
133void cgit_repo_config_cb(const char *name, const char *value) 139void cgit_repo_config_cb(const char *name, const char *value)
134{ 140{
135 if (!strcmp(name, "name")) 141 if (!strcmp(name, "name"))
136 cgit_repo_name = xstrdup(value); 142 cgit_repo_name = xstrdup(value);
137 else if (!strcmp(name, "desc")) 143 else if (!strcmp(name, "desc"))
138 cgit_repo_desc = xstrdup(value); 144 cgit_repo_desc = xstrdup(value);
139 else if (!strcmp(name, "owner")) 145 else if (!strcmp(name, "owner"))
140 cgit_repo_owner = xstrdup(value); 146 cgit_repo_owner = xstrdup(value);
141} 147}
142 148
143void cgit_querystring_cb(const char *name, const char *value) 149void cgit_querystring_cb(const char *name, const char *value)
144{ 150{
145 if (!strcmp(name,"r")) { 151 if (!strcmp(name,"r")) {
146 cgit_query_repo = xstrdup(value); 152 cgit_query_repo = xstrdup(value);
147 } else if (!strcmp(name, "p")) { 153 } else if (!strcmp(name, "p")) {
148 cgit_query_page = xstrdup(value); 154 cgit_query_page = xstrdup(value);
149 } else if (!strcmp(name, "q")) { 155 } else if (!strcmp(name, "q")) {
150 cgit_query_search = xstrdup(value); 156 cgit_query_search = xstrdup(value);
151 } else if (!strcmp(name, "h")) { 157 } else if (!strcmp(name, "h")) {
152 cgit_query_head = xstrdup(value); 158 cgit_query_head = xstrdup(value);
153 cgit_query_has_symref = 1; 159 cgit_query_has_symref = 1;
154 } else if (!strcmp(name, "id")) { 160 } else if (!strcmp(name, "id")) {
155 cgit_query_sha1 = xstrdup(value); 161 cgit_query_sha1 = xstrdup(value);
156 cgit_query_has_sha1 = 1; 162 cgit_query_has_sha1 = 1;
157 } else if (!strcmp(name, "id2")) { 163 } else if (!strcmp(name, "id2")) {
158 cgit_query_sha2 = xstrdup(value); 164 cgit_query_sha2 = xstrdup(value);
159 cgit_query_has_sha1 = 1; 165 cgit_query_has_sha1 = 1;
160 } else if (!strcmp(name, "ofs")) { 166 } else if (!strcmp(name, "ofs")) {
161 cgit_query_ofs = atoi(value); 167 cgit_query_ofs = atoi(value);
162 } else if (!strcmp(name, "path")) { 168 } else if (!strcmp(name, "path")) {
163 cgit_query_path = xstrdup(value); 169 cgit_query_path = xstrdup(value);
164 } else if (!strcmp(name, "name")) { 170 } else if (!strcmp(name, "name")) {
165 cgit_query_name = xstrdup(value); 171 cgit_query_name = xstrdup(value);
166 } 172 }
167} 173}
168 174
169void *cgit_free_commitinfo(struct commitinfo *info) 175void *cgit_free_commitinfo(struct commitinfo *info)
170{ 176{
171 free(info->author); 177 free(info->author);
172 free(info->author_email); 178 free(info->author_email);
173 free(info->committer); 179 free(info->committer);
174 free(info->committer_email); 180 free(info->committer_email);
175 free(info->subject); 181 free(info->subject);
176 free(info); 182 free(info);
177 return NULL; 183 return NULL;
178} 184}
179 185
180int hextoint(char c) 186int hextoint(char c)
181{ 187{
182 if (c >= 'a' && c <= 'f') 188 if (c >= 'a' && c <= 'f')
183 return 10 + c - 'a'; 189 return 10 + c - 'a';
184 else if (c >= 'A' && c <= 'F') 190 else if (c >= 'A' && c <= 'F')
185 return 10 + c - 'A'; 191 return 10 + c - 'A';
186 else if (c >= '0' && c <= '9') 192 else if (c >= '0' && c <= '9')
187 return c - '0'; 193 return c - '0';
188 else 194 else
189 return -1; 195 return -1;
190} 196}
191 197
diff --git a/ui-tree.c b/ui-tree.c
index 60f7560..dee8309 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -1,80 +1,81 @@
1/* ui-tree.c: functions for tree output 1/* ui-tree.c: functions for tree output
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 11
12static int print_entry(const unsigned char *sha1, const char *base, 12static int print_entry(const unsigned char *sha1, const char *base,
13 int baselen, const char *pathname, unsigned int mode, 13 int baselen, const char *pathname, unsigned int mode,
14 int stage) 14 int stage)
15{ 15{
16 char *name; 16 char *name;
17 enum object_type type; 17 enum object_type type;
18 unsigned long size; 18 unsigned long size = 0;
19 19
20 name = xstrdup(pathname); 20 name = xstrdup(pathname);
21 type = sha1_object_info(sha1, &size); 21 type = sha1_object_info(sha1, &size);
22 if (type == OBJ_BAD) { 22 if (type == OBJ_BAD && !S_ISDIRLNK(mode)) {
23 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", 23 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
24 name, 24 name,
25 sha1_to_hex(sha1)); 25 sha1_to_hex(sha1));
26 return 0; 26 return 0;
27 } 27 }
28 html("<tr><td class='filemode'>"); 28 html("<tr><td class='filemode'>");
29 html_filemode(mode); 29 html_filemode(mode);
30 html("</td><td>"); 30 html("</td><td ");
31 if (S_ISDIRLNK(mode)) { 31 if (S_ISDIRLNK(mode)) {
32 htmlf("<div class='ls-dirlnk'>%s => submodule</div>", name); 32 htmlf("class='ls-mod'><a href='");
33 html_attr(fmt(cgit_repo->module_link,
34 name,
35 sha1_to_hex(sha1)));
33 } else if (S_ISDIR(mode)) { 36 } else if (S_ISDIR(mode)) {
34 html("<div class='ls-dir'><a href='"); 37 html("class='ls-dir'><a href='");
35 html_attr(cgit_pageurl(cgit_query_repo, "tree", 38 html_attr(cgit_pageurl(cgit_query_repo, "tree",
36 fmt("id=%s&path=%s%s/", 39 fmt("id=%s&path=%s%s/",
37 sha1_to_hex(sha1), 40 sha1_to_hex(sha1),
38 cgit_query_path ? cgit_query_path : "", 41 cgit_query_path ? cgit_query_path : "",
39 pathname))); 42 pathname)));
40 htmlf("'>%s</a></div>", name);
41 } else { 43 } else {
42 html("<div class='ls-blob'><a href='"); 44 html("class='ls-blob'><a href='");
43 html_attr(cgit_pageurl(cgit_query_repo, "view", 45 html_attr(cgit_pageurl(cgit_query_repo, "view",
44 fmt("id=%s&path=%s%s", sha1_to_hex(sha1), 46 fmt("id=%s&path=%s%s", sha1_to_hex(sha1),
45 cgit_query_path ? cgit_query_path : "", 47 cgit_query_path ? cgit_query_path : "",
46 pathname))); 48 pathname)));
47 htmlf("'>%s</a></div>", name);
48 } 49 }
49 html("</div></td>"); 50 htmlf("'>%s</a></div></td>", name);
50 htmlf("<td class='filesize'>%li</td>", size); 51 htmlf("<td class='filesize'>%li</td>", size);
51 html("</tr>\n"); 52 html("</tr>\n");
52 free(name); 53 free(name);
53 return 0; 54 return 0;
54} 55}
55 56
56void cgit_print_tree(const char *hex, char *path) 57void cgit_print_tree(const char *hex, char *path)
57{ 58{
58 struct tree *tree; 59 struct tree *tree;
59 unsigned char sha1[20]; 60 unsigned char sha1[20];
60 61
61 if (get_sha1_hex(hex, sha1)) { 62 if (get_sha1_hex(hex, sha1)) {
62 cgit_print_error(fmt("Invalid object id: %s", hex)); 63 cgit_print_error(fmt("Invalid object id: %s", hex));
63 return; 64 return;
64 } 65 }
65 tree = parse_tree_indirect(sha1); 66 tree = parse_tree_indirect(sha1);
66 if (!tree) { 67 if (!tree) {
67 cgit_print_error(fmt("Not a tree object: %s", hex)); 68 cgit_print_error(fmt("Not a tree object: %s", hex));
68 return; 69 return;
69 } 70 }
70 71
71 html_txt(path); 72 html_txt(path);
72 html("<table class='list'>\n"); 73 html("<table class='list'>\n");
73 html("<tr class='nohover'>"); 74 html("<tr class='nohover'>");
74 html("<th class='left'>Mode</th>"); 75 html("<th class='left'>Mode</th>");
75 html("<th class='left'>Name</th>"); 76 html("<th class='left'>Name</th>");
76 html("<th class='right'>Size</th>"); 77 html("<th class='right'>Size</th>");
77 html("</tr>\n"); 78 html("</tr>\n");
78 read_tree_recursive(tree, "", 0, 1, NULL, print_entry); 79 read_tree_recursive(tree, "", 0, 1, NULL, print_entry);
79 html("</table>\n"); 80 html("</table>\n");
80} 81}