summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.h2
-rw-r--r--cgitrc7
-rw-r--r--shared.c5
-rw-r--r--ui-shared.c17
4 files changed, 31 insertions, 0 deletions
diff --git a/cgit.h b/cgit.h
index ab0efeb..f223dbc 100644
--- a/cgit.h
+++ b/cgit.h
@@ -1,291 +1,293 @@
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#include <utf8.h> 19#include <utf8.h>
20 20
21 21
22/* 22/*
23 * The valid cgit repo-commands 23 * The valid cgit repo-commands
24 */ 24 */
25#define CMD_LOG 1 25#define CMD_LOG 1
26#define CMD_COMMIT 2 26#define CMD_COMMIT 2
27#define CMD_DIFF 3 27#define CMD_DIFF 3
28#define CMD_TREE 4 28#define CMD_TREE 4
29#define CMD_BLOB 5 29#define CMD_BLOB 5
30#define CMD_SNAPSHOT 6 30#define CMD_SNAPSHOT 6
31#define CMD_TAG 7 31#define CMD_TAG 7
32#define CMD_REFS 8 32#define CMD_REFS 8
33 33
34/* 34/*
35 * Dateformats used on misc. pages 35 * Dateformats used on misc. pages
36 */ 36 */
37#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" 37#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S"
38#define FMT_SHORTDATE "%Y-%m-%d" 38#define FMT_SHORTDATE "%Y-%m-%d"
39 39
40 40
41/* 41/*
42 * Limits used for relative dates 42 * Limits used for relative dates
43 */ 43 */
44#define TM_MIN 60 44#define TM_MIN 60
45#define TM_HOUR (TM_MIN * 60) 45#define TM_HOUR (TM_MIN * 60)
46#define TM_DAY (TM_HOUR * 24) 46#define TM_DAY (TM_HOUR * 24)
47#define TM_WEEK (TM_DAY * 7) 47#define TM_WEEK (TM_DAY * 7)
48#define TM_YEAR (TM_DAY * 365) 48#define TM_YEAR (TM_DAY * 365)
49#define TM_MONTH (TM_YEAR / 12.0) 49#define TM_MONTH (TM_YEAR / 12.0)
50 50
51 51
52/* 52/*
53 * Default encoding 53 * Default encoding
54 */ 54 */
55#define PAGE_ENCODING "UTF-8" 55#define PAGE_ENCODING "UTF-8"
56 56
57typedef void (*configfn)(const char *name, const char *value); 57typedef void (*configfn)(const char *name, const char *value);
58typedef void (*filepair_fn)(struct diff_filepair *pair); 58typedef void (*filepair_fn)(struct diff_filepair *pair);
59typedef void (*linediff_fn)(char *line, int len); 59typedef void (*linediff_fn)(char *line, int len);
60 60
61struct cacheitem { 61struct cacheitem {
62 char *name; 62 char *name;
63 struct stat st; 63 struct stat st;
64 int ttl; 64 int ttl;
65 int fd; 65 int fd;
66}; 66};
67 67
68struct repoinfo { 68struct repoinfo {
69 char *url; 69 char *url;
70 char *name; 70 char *name;
71 char *path; 71 char *path;
72 char *desc; 72 char *desc;
73 char *owner; 73 char *owner;
74 char *defbranch; 74 char *defbranch;
75 char *group; 75 char *group;
76 char *module_link; 76 char *module_link;
77 char *readme; 77 char *readme;
78 char *clone_url;
78 int snapshots; 79 int snapshots;
79 int enable_log_filecount; 80 int enable_log_filecount;
80 int enable_log_linecount; 81 int enable_log_linecount;
81}; 82};
82 83
83struct repolist { 84struct repolist {
84 int length; 85 int length;
85 int count; 86 int count;
86 struct repoinfo *repos; 87 struct repoinfo *repos;
87}; 88};
88 89
89struct commitinfo { 90struct commitinfo {
90 struct commit *commit; 91 struct commit *commit;
91 char *author; 92 char *author;
92 char *author_email; 93 char *author_email;
93 unsigned long author_date; 94 unsigned long author_date;
94 char *committer; 95 char *committer;
95 char *committer_email; 96 char *committer_email;
96 unsigned long committer_date; 97 unsigned long committer_date;
97 char *subject; 98 char *subject;
98 char *msg; 99 char *msg;
99 char *msg_encoding; 100 char *msg_encoding;
100}; 101};
101 102
102struct taginfo { 103struct taginfo {
103 char *tagger; 104 char *tagger;
104 char *tagger_email; 105 char *tagger_email;
105 int tagger_date; 106 int tagger_date;
106 char *msg; 107 char *msg;
107}; 108};
108 109
109struct refinfo { 110struct refinfo {
110 const char *refname; 111 const char *refname;
111 struct object *object; 112 struct object *object;
112 union { 113 union {
113 struct taginfo *tag; 114 struct taginfo *tag;
114 struct commitinfo *commit; 115 struct commitinfo *commit;
115 }; 116 };
116}; 117};
117 118
118struct reflist { 119struct reflist {
119 struct refinfo **refs; 120 struct refinfo **refs;
120 int alloc; 121 int alloc;
121 int count; 122 int count;
122}; 123};
123 124
124extern const char *cgit_version; 125extern const char *cgit_version;
125 126
126extern struct repolist cgit_repolist; 127extern struct repolist cgit_repolist;
127extern struct repoinfo *cgit_repo; 128extern struct repoinfo *cgit_repo;
128extern int cgit_cmd; 129extern int cgit_cmd;
129 130
130extern char *cgit_root_title; 131extern char *cgit_root_title;
131extern char *cgit_css; 132extern char *cgit_css;
132extern char *cgit_logo; 133extern char *cgit_logo;
133extern char *cgit_index_header; 134extern char *cgit_index_header;
134extern char *cgit_index_info; 135extern char *cgit_index_info;
135extern char *cgit_logo_link; 136extern char *cgit_logo_link;
136extern char *cgit_module_link; 137extern char *cgit_module_link;
137extern char *cgit_agefile; 138extern char *cgit_agefile;
138extern char *cgit_virtual_root; 139extern char *cgit_virtual_root;
139extern char *cgit_script_name; 140extern char *cgit_script_name;
140extern char *cgit_cache_root; 141extern char *cgit_cache_root;
141extern char *cgit_repo_group; 142extern char *cgit_repo_group;
142extern char *cgit_robots; 143extern char *cgit_robots;
144extern char *cgit_clone_prefix;
143 145
144extern int cgit_nocache; 146extern int cgit_nocache;
145extern int cgit_snapshots; 147extern int cgit_snapshots;
146extern int cgit_enable_index_links; 148extern int cgit_enable_index_links;
147extern int cgit_enable_log_filecount; 149extern int cgit_enable_log_filecount;
148extern int cgit_enable_log_linecount; 150extern int cgit_enable_log_linecount;
149extern int cgit_max_lock_attempts; 151extern int cgit_max_lock_attempts;
150extern int cgit_cache_root_ttl; 152extern int cgit_cache_root_ttl;
151extern int cgit_cache_repo_ttl; 153extern int cgit_cache_repo_ttl;
152extern int cgit_cache_dynamic_ttl; 154extern int cgit_cache_dynamic_ttl;
153extern int cgit_cache_static_ttl; 155extern int cgit_cache_static_ttl;
154extern int cgit_cache_max_create_time; 156extern int cgit_cache_max_create_time;
155extern int cgit_summary_log; 157extern int cgit_summary_log;
156extern int cgit_summary_tags; 158extern int cgit_summary_tags;
157extern int cgit_summary_branches; 159extern int cgit_summary_branches;
158 160
159extern int cgit_max_msg_len; 161extern int cgit_max_msg_len;
160extern int cgit_max_repodesc_len; 162extern int cgit_max_repodesc_len;
161extern int cgit_max_commit_count; 163extern int cgit_max_commit_count;
162 164
163extern int cgit_query_has_symref; 165extern int cgit_query_has_symref;
164extern int cgit_query_has_sha1; 166extern int cgit_query_has_sha1;
165 167
166extern char *cgit_querystring; 168extern char *cgit_querystring;
167extern char *cgit_query_repo; 169extern char *cgit_query_repo;
168extern char *cgit_query_page; 170extern char *cgit_query_page;
169extern char *cgit_query_search; 171extern char *cgit_query_search;
170extern char *cgit_query_grep; 172extern char *cgit_query_grep;
171extern char *cgit_query_head; 173extern char *cgit_query_head;
172extern char *cgit_query_sha1; 174extern char *cgit_query_sha1;
173extern char *cgit_query_sha2; 175extern char *cgit_query_sha2;
174extern char *cgit_query_path; 176extern char *cgit_query_path;
175extern char *cgit_query_name; 177extern char *cgit_query_name;
176extern int cgit_query_ofs; 178extern int cgit_query_ofs;
177 179
178extern int htmlfd; 180extern int htmlfd;
179 181
180extern int cgit_get_cmd_index(const char *cmd); 182extern int cgit_get_cmd_index(const char *cmd);
181extern struct repoinfo *cgit_get_repoinfo(const char *url); 183extern struct repoinfo *cgit_get_repoinfo(const char *url);
182extern void cgit_global_config_cb(const char *name, const char *value); 184extern void cgit_global_config_cb(const char *name, const char *value);
183extern void cgit_repo_config_cb(const char *name, const char *value); 185extern void cgit_repo_config_cb(const char *name, const char *value);
184extern void cgit_querystring_cb(const char *name, const char *value); 186extern void cgit_querystring_cb(const char *name, const char *value);
185 187
186extern int chk_zero(int result, char *msg); 188extern int chk_zero(int result, char *msg);
187extern int chk_positive(int result, char *msg); 189extern int chk_positive(int result, char *msg);
188extern int chk_non_negative(int result, char *msg); 190extern int chk_non_negative(int result, char *msg);
189 191
190extern int hextoint(char c); 192extern int hextoint(char c);
191extern char *trim_end(const char *str, char c); 193extern char *trim_end(const char *str, char c);
192extern char *strlpart(char *txt, int maxlen); 194extern char *strlpart(char *txt, int maxlen);
193extern char *strrpart(char *txt, int maxlen); 195extern char *strrpart(char *txt, int maxlen);
194 196
195extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); 197extern void cgit_add_ref(struct reflist *list, struct refinfo *ref);
196extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, 198extern int cgit_refs_cb(const char *refname, const unsigned char *sha1,
197 int flags, void *cb_data); 199 int flags, void *cb_data);
198 200
199extern void *cgit_free_commitinfo(struct commitinfo *info); 201extern void *cgit_free_commitinfo(struct commitinfo *info);
200 202
201extern int cgit_diff_files(const unsigned char *old_sha1, 203extern int cgit_diff_files(const unsigned char *old_sha1,
202 const unsigned char *new_sha1, 204 const unsigned char *new_sha1,
203 linediff_fn fn); 205 linediff_fn fn);
204 206
205extern void cgit_diff_tree(const unsigned char *old_sha1, 207extern void cgit_diff_tree(const unsigned char *old_sha1,
206 const unsigned char *new_sha1, 208 const unsigned char *new_sha1,
207 filepair_fn fn, const char *prefix); 209 filepair_fn fn, const char *prefix);
208 210
209extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); 211extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
210 212
211extern char *fmt(const char *format,...); 213extern char *fmt(const char *format,...);
212 214
213extern void html(const char *txt); 215extern void html(const char *txt);
214extern void htmlf(const char *format,...); 216extern void htmlf(const char *format,...);
215extern void html_txt(char *txt); 217extern void html_txt(char *txt);
216extern void html_ntxt(int len, char *txt); 218extern void html_ntxt(int len, char *txt);
217extern void html_attr(char *txt); 219extern void html_attr(char *txt);
218extern void html_hidden(char *name, char *value); 220extern void html_hidden(char *name, char *value);
219extern void html_option(char *value, char *text, char *selected_value); 221extern void html_option(char *value, char *text, char *selected_value);
220extern void html_link_open(char *url, char *title, char *class); 222extern void html_link_open(char *url, char *title, char *class);
221extern void html_link_close(void); 223extern void html_link_close(void);
222extern void html_filemode(unsigned short mode); 224extern void html_filemode(unsigned short mode);
223extern int html_include(const char *filename); 225extern int html_include(const char *filename);
224 226
225extern int cgit_read_config(const char *filename, configfn fn); 227extern int cgit_read_config(const char *filename, configfn fn);
226extern int cgit_parse_query(char *txt, configfn fn); 228extern int cgit_parse_query(char *txt, configfn fn);
227extern struct commitinfo *cgit_parse_commit(struct commit *commit); 229extern struct commitinfo *cgit_parse_commit(struct commit *commit);
228extern struct taginfo *cgit_parse_tag(struct tag *tag); 230extern struct taginfo *cgit_parse_tag(struct tag *tag);
229extern void cgit_parse_url(const char *url); 231extern void cgit_parse_url(const char *url);
230 232
231extern char *cache_safe_filename(const char *unsafe); 233extern char *cache_safe_filename(const char *unsafe);
232extern int cache_lock(struct cacheitem *item); 234extern int cache_lock(struct cacheitem *item);
233extern int cache_unlock(struct cacheitem *item); 235extern int cache_unlock(struct cacheitem *item);
234extern int cache_cancel_lock(struct cacheitem *item); 236extern int cache_cancel_lock(struct cacheitem *item);
235extern int cache_exist(struct cacheitem *item); 237extern int cache_exist(struct cacheitem *item);
236extern int cache_expired(struct cacheitem *item); 238extern int cache_expired(struct cacheitem *item);
237 239
238extern char *cgit_repourl(const char *reponame); 240extern char *cgit_repourl(const char *reponame);
239extern char *cgit_fileurl(const char *reponame, const char *pagename, 241extern char *cgit_fileurl(const char *reponame, const char *pagename,
240 const char *filename, const char *query); 242 const char *filename, const char *query);
241extern char *cgit_pageurl(const char *reponame, const char *pagename, 243extern char *cgit_pageurl(const char *reponame, const char *pagename,
242 const char *query); 244 const char *query);
243 245
244extern const char *cgit_repobasename(const char *reponame); 246extern const char *cgit_repobasename(const char *reponame);
245 247
246extern void cgit_tree_link(char *name, char *title, char *class, char *head, 248extern void cgit_tree_link(char *name, char *title, char *class, char *head,
247 char *rev, char *path); 249 char *rev, char *path);
248extern void cgit_log_link(char *name, char *title, char *class, char *head, 250extern void cgit_log_link(char *name, char *title, char *class, char *head,
249 char *rev, char *path, int ofs, char *grep, 251 char *rev, char *path, int ofs, char *grep,
250 char *pattern); 252 char *pattern);
251extern void cgit_commit_link(char *name, char *title, char *class, char *head, 253extern void cgit_commit_link(char *name, char *title, char *class, char *head,
252 char *rev); 254 char *rev);
253extern void cgit_refs_link(char *name, char *title, char *class, char *head, 255extern void cgit_refs_link(char *name, char *title, char *class, char *head,
254 char *rev, char *path); 256 char *rev, char *path);
255extern void cgit_snapshot_link(char *name, char *title, char *class, 257extern void cgit_snapshot_link(char *name, char *title, char *class,
256 char *head, char *rev, char *archivename); 258 char *head, char *rev, char *archivename);
257extern void cgit_diff_link(char *name, char *title, char *class, char *head, 259extern void cgit_diff_link(char *name, char *title, char *class, char *head,
258 char *new_rev, char *old_rev, char *path); 260 char *new_rev, char *old_rev, char *path);
259 261
260extern void cgit_object_link(struct object *obj); 262extern void cgit_object_link(struct object *obj);
261 263
262extern void cgit_print_error(char *msg); 264extern void cgit_print_error(char *msg);
263extern void cgit_print_date(time_t secs, char *format); 265extern void cgit_print_date(time_t secs, char *format);
264extern void cgit_print_age(time_t t, time_t max_relative, char *format); 266extern void cgit_print_age(time_t t, time_t max_relative, char *format);
265extern void cgit_print_docstart(char *title, struct cacheitem *item); 267extern void cgit_print_docstart(char *title, struct cacheitem *item);
266extern void cgit_print_docend(); 268extern void cgit_print_docend();
267extern void cgit_print_pageheader(char *title, int show_search); 269extern void cgit_print_pageheader(char *title, int show_search);
268extern void cgit_print_snapshot_start(const char *mimetype, 270extern void cgit_print_snapshot_start(const char *mimetype,
269 const char *filename, 271 const char *filename,
270 struct cacheitem *item); 272 struct cacheitem *item);
271extern void cgit_print_branches(int maxcount); 273extern void cgit_print_branches(int maxcount);
272extern void cgit_print_tags(int maxcount); 274extern void cgit_print_tags(int maxcount);
273 275
274extern void cgit_print_repolist(struct cacheitem *item); 276extern void cgit_print_repolist(struct cacheitem *item);
275extern void cgit_print_summary(); 277extern void cgit_print_summary();
276extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, 278extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep,
277 char *pattern, char *path, int pager); 279 char *pattern, char *path, int pager);
278extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); 280extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path);
279extern void cgit_print_tree(const char *rev, char *path); 281extern void cgit_print_tree(const char *rev, char *path);
280extern void cgit_print_commit(char *hex); 282extern void cgit_print_commit(char *hex);
281extern void cgit_print_refs(); 283extern void cgit_print_refs();
282extern void cgit_print_tag(char *revname); 284extern void cgit_print_tag(char *revname);
283extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix); 285extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix);
284extern void cgit_print_snapshot(struct cacheitem *item, const char *head, 286extern void cgit_print_snapshot(struct cacheitem *item, const char *head,
285 const char *hex, const char *prefix, 287 const char *hex, const char *prefix,
286 const char *filename, int snapshot); 288 const char *filename, int snapshot);
287extern void cgit_print_snapshot_links(const char *repo, const char *head, 289extern void cgit_print_snapshot_links(const char *repo, const char *head,
288 const char *hex, int snapshots); 290 const char *hex, int snapshots);
289extern int cgit_parse_snapshots_mask(const char *str); 291extern int cgit_parse_snapshots_mask(const char *str);
290 292
291#endif /* CGIT_H */ 293#endif /* CGIT_H */
diff --git a/cgitrc b/cgitrc
index 8c616e0..ce0c01b 100644
--- a/cgitrc
+++ b/cgitrc
@@ -1,187 +1,194 @@
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## This variable can be used to override the default value for "robots" 11## This variable can be used to override the default value for "robots"
12## meta-tag. If unset, the meta-tag isn't generated. 12## meta-tag. If unset, the meta-tag isn't generated.
13#robots=index, nofollow 13#robots=index, nofollow
14 14
15 15
16## Set allowed snapshot types by default. Can be overridden per repo 16## Set allowed snapshot types by default. Can be overridden per repo
17# can be any combination of zip/tar.gz/tar.bz2/tar 17# can be any combination of zip/tar.gz/tar.bz2/tar
18#snapshots=0 18#snapshots=0
19 19
20 20
21## Enable/disable extra links to summary/log/tree per repo on index page 21## Enable/disable extra links to summary/log/tree per repo on index page
22#enable-index-links=0 22#enable-index-links=0
23 23
24 24
25## Enable/disable display of 'number of files changed' in log view 25## Enable/disable display of 'number of files changed' in log view
26#enable-log-filecount=0 26#enable-log-filecount=0
27 27
28 28
29## Enable/disable display of 'number of lines changed' in log view 29## Enable/disable display of 'number of lines changed' in log view
30#enable-log-linecount=0 30#enable-log-linecount=0
31 31
32 32
33## Enable/disable display of HEAD shortlog in summary view. Set it to maximum 33## Enable/disable display of HEAD shortlog in summary view. Set it to maximum
34## number of commits that should be displayed 34## number of commits that should be displayed
35#summary-log=0 35#summary-log=0
36 36
37 37
38## Restrict the number of branches printed in summary view. Set to 0 to 38## Restrict the number of branches printed in summary view. Set to 0 to
39## print all branches. 39## print all branches.
40#summary-branches=0 40#summary-branches=0
41 41
42 42
43## Restrict the number of tags printed in summary view. Set to 0 to 43## Restrict the number of tags printed in summary view. Set to 0 to
44## print all tags. 44## print all tags.
45#summary-tags=0 45#summary-tags=0
46 46
47 47
48## The "Idle" column on the repository index page can read a timestamp 48## The "Idle" column on the repository index page can read a timestamp
49## from the specified agefile (if this file cannot be found, the mtime 49## from the specified agefile (if this file cannot be found, the mtime
50## of HEAD is used). 50## of HEAD is used).
51## The cgit repo on hjemli.net uses the the following command in it's 51## The cgit repo on hjemli.net uses the the following command in it's
52## post-receive hook to update the age-file: 52## post-receive hook to update the age-file:
53## git-for-each-ref --format="%(committerdate)" --sort=-committerdate \ 53## git-for-each-ref --format="%(committerdate)" --sort=-committerdate \
54## --count=1 > $GIT_DIR/info/web/last-modifie 54## --count=1 > $GIT_DIR/info/web/last-modifie
55## 55##
56#agefile=info/web/last-modified 56#agefile=info/web/last-modified
57 57
58 58
59## Git detects renames, but with a limit on the number of files to 59## Git detects renames, but with a limit on the number of files to
60## consider. This option can be used to specify another limit (or -1 to 60## consider. This option can be used to specify another limit (or -1 to
61## use the default limit). 61## use the default limit).
62## 62##
63#renamelimit=-1 63#renamelimit=-1
64 64
65 65
66## Specify a root for virtual urls. This makes cgit generate urls like 66## Specify a root for virtual urls. This makes cgit generate urls like
67## 67##
68## http://localhost/git/repo/log/?h=branch 68## http://localhost/git/repo/log/?h=branch
69## 69##
70## instead of 70## instead of
71## 71##
72## http://localhost/cgit/cgit.cgi?url=repo/log&h=branch 72## http://localhost/cgit/cgit.cgi?url=repo/log&h=branch
73## 73##
74## For this to work with apache, a rewrite rule must be added to httpd.conf, 74## For this to work with apache, a rewrite rule must be added to httpd.conf,
75## possibly looking something like this: 75## possibly looking something like this:
76## 76##
77## RewriteRule ^/git/(.*)$ /cgit/cgit.cgi?url=$1 [L,QSA] 77## RewriteRule ^/git/(.*)$ /cgit/cgit.cgi?url=$1 [L,QSA]
78## 78##
79## For this to work with lighttpd, the rewrite rule should look more like this: 79## For this to work with lighttpd, the rewrite rule should look more like this:
80## 80##
81## url.rewrite = ( 81## url.rewrite = (
82## "^/git/([^?/]+/[^?]*)?(?:\?(.*))?$" => "/cgit.cgi?url=$1&$2" 82## "^/git/([^?/]+/[^?]*)?(?:\?(.*))?$" => "/cgit.cgi?url=$1&$2"
83## ) 83## )
84## 84##
85## This setting is disabled by default. 85## This setting is disabled by default.
86#virtual-root=/git 86#virtual-root=/git
87 87
88 88
89## Set the title printed on the root page 89## Set the title printed on the root page
90#root-title=Git repository browser 90#root-title=Git repository browser
91 91
92 92
93## If specified, the file at this path will be included as HTML in the 93## If specified, the file at this path will be included as HTML in the
94## sidebar on the repository index page 94## sidebar on the repository index page
95#index-info= 95#index-info=
96 96
97 97
98## If specified, the file at this path will be included as HTML above 98## If specified, the file at this path will be included as HTML above
99## the repository index 99## the repository index
100#index-header= 100#index-header=
101 101
102 102
103## Link to css file 103## Link to css file
104#css=/cgit/cgit.css 104#css=/cgit/cgit.css
105 105
106 106
107## Link to logo file 107## Link to logo file
108#logo=/cgit/git-logo.png 108#logo=/cgit/git-logo.png
109 109
110 110
111## Url loaded when clicking the logo 111## Url loaded when clicking the logo
112#logo-link=http://www.kernel.org/pub/software/scm/git/docs/ 112#logo-link=http://www.kernel.org/pub/software/scm/git/docs/
113 113
114 114
115## Url loaded when clicking a submodule link 115## Url loaded when clicking a submodule link
116#module-link=./?repo=%s&page=commit&id=%s 116#module-link=./?repo=%s&page=commit&id=%s
117 117
118 118
119## Shared prefix which, when combined with repo url, becomes the url used
120## to clone the repo
121#clone-prefix=
122
123
119## Number of chars shown of repo description (in repolist view) 124## Number of chars shown of repo description (in repolist view)
120#max-repodesc-length=60 125#max-repodesc-length=60
121 126
122 127
123## Number of chars shown of commit subject message (in log view) 128## Number of chars shown of commit subject message (in log view)
124#max-message-length=60 129#max-message-length=60
125 130
126 131
127## Number of commits per page in log view 132## Number of commits per page in log view
128#max-commit-count=50 133#max-commit-count=50
129 134
130 135
131## Root of cached output 136## Root of cached output
132#cache-root=/var/cache/cgit 137#cache-root=/var/cache/cgit
133 138
134 139
135## Include another config-file 140## Include another config-file
136#include=/var/cgit/repolist 141#include=/var/cgit/repolist
137 142
138## 143##
139## Time-To-Live settings: specifies how long (in minutes) different pages 144## Time-To-Live settings: specifies how long (in minutes) different pages
140## should be cached (0 for instant expiration, -1 for immortal pages) 145## should be cached (0 for instant expiration, -1 for immortal pages)
141## 146##
142 147
143## ttl for root page 148## ttl for root page
144#cache-root-ttl=5 149#cache-root-ttl=5
145 150
146## ttl for repo summary page 151## ttl for repo summary page
147#cache-repo-ttl=5 152#cache-repo-ttl=5
148 153
149## ttl for other dynamic pages 154## ttl for other dynamic pages
150#cache-dynamic-ttl=5 155#cache-dynamic-ttl=5
151 156
152## ttl for static pages (addressed by SHA-1) 157## ttl for static pages (addressed by SHA-1)
153#cache-static-ttl=-1 158#cache-static-ttl=-1
154 159
155 160
156 161
157## Example repository entry. Required values are repo.url and repo.path (each 162## Example repository entry. Required values are repo.url and repo.path (each
158## repository section must start with repo.url). 163## repository section must start with repo.url).
159#repo.url=cgit 164#repo.url=cgit
160#repo.name=cgit 165#repo.name=cgit
161#repo.desc=the caching cgi for git 166#repo.desc=the caching cgi for git
162 #repo.path=/pub/git/cgit ## this is the path to $GIT_DIR 167 #repo.path=/pub/git/cgit ## this is the path to $GIT_DIR
163#repo.owner=Lars Hjemli 168#repo.owner=Lars Hjemli
164 #repo.defbranch=master ## define a default branch 169 #repo.defbranch=master ## define a default branch
165 #repo.snapshots=tar.bz2 ## override a sitewide snapshot-setting 170 #repo.snapshots=tar.bz2 ## override a sitewide snapshot-setting
166 #repo.enable-log-filecount=0 ## override the default filecount setting 171 #repo.enable-log-filecount=0 ## override the default filecount setting
167 #repo.enable-log-linecount=0 ## override the default linecount setting 172 #repo.enable-log-linecount=0 ## override the default linecount setting
168 #repo.module-link=/git/%s/commit/?id=%s ## override the standard module-link 173 #repo.module-link=/git/%s/commit/?id=%s ## override the standard module-link
169 #repo.readme=info/web/readme ## specify a file to include on summary page 174 #repo.readme=info/web/readme ## specify a file to include on summary page
175#repo.clone-url=git://hjemli.net/pub/git/cgit
170 176
171## Additional repositories grouped under "mirrors" 177## Additional repositories grouped under "mirrors"
172#repo.group=mirrors 178#repo.group=mirrors
173 179
174#repo.url=git 180#repo.url=git
175#repo.path=/pub/git/git 181#repo.path=/pub/git/git
182#repo.clone-url=git://hjemli.net/pub/git/git
176# 183#
177#repo.url=linux 184#repo.url=linux
178#repo.path=/pub/git/linux 185#repo.path=/pub/git/linux
179 186
180## A group of private repositories (with a working directory) 187## A group of private repositories (with a working directory)
181#repo.group=private 188#repo.group=private
182 189
183#repo.url=larsh/cgit 190#repo.url=larsh/cgit
184#repo.path=/home/larsh/src/cgit/.git 191#repo.path=/home/larsh/src/cgit/.git
185 192
186#repo.url=larsh/git 193#repo.url=larsh/git
187#repo.path=/home/larsh/src/git/.git 194#repo.path=/home/larsh/src/git/.git
diff --git a/shared.c b/shared.c
index fd8b1e3..2c309f5 100644
--- a/shared.c
+++ b/shared.c
@@ -1,402 +1,407 @@
1/* shared.c: global vars + some callback functions 1/* shared.c: global vars + some callback functions
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10 10
11struct repolist cgit_repolist; 11struct repolist cgit_repolist;
12struct repoinfo *cgit_repo; 12struct repoinfo *cgit_repo;
13int cgit_cmd; 13int cgit_cmd;
14 14
15const char *cgit_version = CGIT_VERSION; 15const char *cgit_version = CGIT_VERSION;
16 16
17char *cgit_root_title = "Git repository browser"; 17char *cgit_root_title = "Git repository browser";
18char *cgit_css = "/cgit.css"; 18char *cgit_css = "/cgit.css";
19char *cgit_logo = "/git-logo.png"; 19char *cgit_logo = "/git-logo.png";
20char *cgit_index_header = NULL; 20char *cgit_index_header = NULL;
21char *cgit_index_info = NULL; 21char *cgit_index_info = NULL;
22char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; 22char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/";
23char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; 23char *cgit_module_link = "./?repo=%s&page=commit&id=%s";
24char *cgit_agefile = "info/web/last-modified"; 24char *cgit_agefile = "info/web/last-modified";
25char *cgit_virtual_root = NULL; 25char *cgit_virtual_root = NULL;
26char *cgit_script_name = CGIT_SCRIPT_NAME; 26char *cgit_script_name = CGIT_SCRIPT_NAME;
27char *cgit_cache_root = CGIT_CACHE_ROOT; 27char *cgit_cache_root = CGIT_CACHE_ROOT;
28char *cgit_repo_group = NULL; 28char *cgit_repo_group = NULL;
29char *cgit_robots = "index, nofollow"; 29char *cgit_robots = "index, nofollow";
30char *cgit_clone_prefix = NULL;
30 31
31int cgit_nocache = 0; 32int cgit_nocache = 0;
32int cgit_snapshots = 0; 33int cgit_snapshots = 0;
33int cgit_enable_index_links = 0; 34int cgit_enable_index_links = 0;
34int cgit_enable_log_filecount = 0; 35int cgit_enable_log_filecount = 0;
35int cgit_enable_log_linecount = 0; 36int cgit_enable_log_linecount = 0;
36int cgit_max_lock_attempts = 5; 37int cgit_max_lock_attempts = 5;
37int cgit_cache_root_ttl = 5; 38int cgit_cache_root_ttl = 5;
38int cgit_cache_repo_ttl = 5; 39int cgit_cache_repo_ttl = 5;
39int cgit_cache_dynamic_ttl = 5; 40int cgit_cache_dynamic_ttl = 5;
40int cgit_cache_static_ttl = -1; 41int cgit_cache_static_ttl = -1;
41int cgit_cache_max_create_time = 5; 42int cgit_cache_max_create_time = 5;
42int cgit_summary_log = 0; 43int cgit_summary_log = 0;
43int cgit_summary_tags = 0; 44int cgit_summary_tags = 0;
44int cgit_summary_branches = 0; 45int cgit_summary_branches = 0;
45int cgit_renamelimit = -1; 46int cgit_renamelimit = -1;
46 47
47int cgit_max_msg_len = 60; 48int cgit_max_msg_len = 60;
48int cgit_max_repodesc_len = 60; 49int cgit_max_repodesc_len = 60;
49int cgit_max_commit_count = 50; 50int cgit_max_commit_count = 50;
50 51
51int cgit_query_has_symref = 0; 52int cgit_query_has_symref = 0;
52int cgit_query_has_sha1 = 0; 53int cgit_query_has_sha1 = 0;
53 54
54char *cgit_querystring = NULL; 55char *cgit_querystring = NULL;
55char *cgit_query_repo = NULL; 56char *cgit_query_repo = NULL;
56char *cgit_query_page = NULL; 57char *cgit_query_page = NULL;
57char *cgit_query_head = NULL; 58char *cgit_query_head = NULL;
58char *cgit_query_search = NULL; 59char *cgit_query_search = NULL;
59char *cgit_query_grep = NULL; 60char *cgit_query_grep = NULL;
60char *cgit_query_sha1 = NULL; 61char *cgit_query_sha1 = NULL;
61char *cgit_query_sha2 = NULL; 62char *cgit_query_sha2 = NULL;
62char *cgit_query_path = NULL; 63char *cgit_query_path = NULL;
63char *cgit_query_name = NULL; 64char *cgit_query_name = NULL;
64int cgit_query_ofs = 0; 65int cgit_query_ofs = 0;
65 66
66int htmlfd = 0; 67int htmlfd = 0;
67 68
68 69
69int cgit_get_cmd_index(const char *cmd) 70int cgit_get_cmd_index(const char *cmd)
70{ 71{
71 static char *cmds[] = {"log", "commit", "diff", "tree", "blob", 72 static char *cmds[] = {"log", "commit", "diff", "tree", "blob",
72 "snapshot", "tag", "refs", NULL}; 73 "snapshot", "tag", "refs", NULL};
73 int i; 74 int i;
74 75
75 for(i = 0; cmds[i]; i++) 76 for(i = 0; cmds[i]; i++)
76 if (!strcmp(cmd, cmds[i])) 77 if (!strcmp(cmd, cmds[i]))
77 return i + 1; 78 return i + 1;
78 return 0; 79 return 0;
79} 80}
80 81
81int chk_zero(int result, char *msg) 82int chk_zero(int result, char *msg)
82{ 83{
83 if (result != 0) 84 if (result != 0)
84 die("%s: %s", msg, strerror(errno)); 85 die("%s: %s", msg, strerror(errno));
85 return result; 86 return result;
86} 87}
87 88
88int chk_positive(int result, char *msg) 89int chk_positive(int result, char *msg)
89{ 90{
90 if (result <= 0) 91 if (result <= 0)
91 die("%s: %s", msg, strerror(errno)); 92 die("%s: %s", msg, strerror(errno));
92 return result; 93 return result;
93} 94}
94 95
95int chk_non_negative(int result, char *msg) 96int chk_non_negative(int result, char *msg)
96{ 97{
97 if (result < 0) 98 if (result < 0)
98 die("%s: %s",msg, strerror(errno)); 99 die("%s: %s",msg, strerror(errno));
99 return result; 100 return result;
100} 101}
101 102
102struct repoinfo *add_repo(const char *url) 103struct repoinfo *add_repo(const char *url)
103{ 104{
104 struct repoinfo *ret; 105 struct repoinfo *ret;
105 106
106 if (++cgit_repolist.count > cgit_repolist.length) { 107 if (++cgit_repolist.count > cgit_repolist.length) {
107 if (cgit_repolist.length == 0) 108 if (cgit_repolist.length == 0)
108 cgit_repolist.length = 8; 109 cgit_repolist.length = 8;
109 else 110 else
110 cgit_repolist.length *= 2; 111 cgit_repolist.length *= 2;
111 cgit_repolist.repos = xrealloc(cgit_repolist.repos, 112 cgit_repolist.repos = xrealloc(cgit_repolist.repos,
112 cgit_repolist.length * 113 cgit_repolist.length *
113 sizeof(struct repoinfo)); 114 sizeof(struct repoinfo));
114 } 115 }
115 116
116 ret = &cgit_repolist.repos[cgit_repolist.count-1]; 117 ret = &cgit_repolist.repos[cgit_repolist.count-1];
117 ret->url = trim_end(url, '/'); 118 ret->url = trim_end(url, '/');
118 ret->name = ret->url; 119 ret->name = ret->url;
119 ret->path = NULL; 120 ret->path = NULL;
120 ret->desc = NULL; 121 ret->desc = NULL;
121 ret->owner = NULL; 122 ret->owner = NULL;
122 ret->group = cgit_repo_group; 123 ret->group = cgit_repo_group;
123 ret->defbranch = "master"; 124 ret->defbranch = "master";
124 ret->snapshots = cgit_snapshots; 125 ret->snapshots = cgit_snapshots;
125 ret->enable_log_filecount = cgit_enable_log_filecount; 126 ret->enable_log_filecount = cgit_enable_log_filecount;
126 ret->enable_log_linecount = cgit_enable_log_linecount; 127 ret->enable_log_linecount = cgit_enable_log_linecount;
127 ret->module_link = cgit_module_link; 128 ret->module_link = cgit_module_link;
128 ret->readme = NULL; 129 ret->readme = NULL;
129 return ret; 130 return ret;
130} 131}
131 132
132struct repoinfo *cgit_get_repoinfo(const char *url) 133struct repoinfo *cgit_get_repoinfo(const char *url)
133{ 134{
134 int i; 135 int i;
135 struct repoinfo *repo; 136 struct repoinfo *repo;
136 137
137 for (i=0; i<cgit_repolist.count; i++) { 138 for (i=0; i<cgit_repolist.count; i++) {
138 repo = &cgit_repolist.repos[i]; 139 repo = &cgit_repolist.repos[i];
139 if (!strcmp(repo->url, url)) 140 if (!strcmp(repo->url, url))
140 return repo; 141 return repo;
141 } 142 }
142 return NULL; 143 return NULL;
143} 144}
144 145
145void cgit_global_config_cb(const char *name, const char *value) 146void cgit_global_config_cb(const char *name, const char *value)
146{ 147{
147 if (!strcmp(name, "root-title")) 148 if (!strcmp(name, "root-title"))
148 cgit_root_title = xstrdup(value); 149 cgit_root_title = xstrdup(value);
149 else if (!strcmp(name, "css")) 150 else if (!strcmp(name, "css"))
150 cgit_css = xstrdup(value); 151 cgit_css = xstrdup(value);
151 else if (!strcmp(name, "logo")) 152 else if (!strcmp(name, "logo"))
152 cgit_logo = xstrdup(value); 153 cgit_logo = xstrdup(value);
153 else if (!strcmp(name, "index-header")) 154 else if (!strcmp(name, "index-header"))
154 cgit_index_header = xstrdup(value); 155 cgit_index_header = xstrdup(value);
155 else if (!strcmp(name, "index-info")) 156 else if (!strcmp(name, "index-info"))
156 cgit_index_info = xstrdup(value); 157 cgit_index_info = xstrdup(value);
157 else if (!strcmp(name, "logo-link")) 158 else if (!strcmp(name, "logo-link"))
158 cgit_logo_link = xstrdup(value); 159 cgit_logo_link = xstrdup(value);
159 else if (!strcmp(name, "module-link")) 160 else if (!strcmp(name, "module-link"))
160 cgit_module_link = xstrdup(value); 161 cgit_module_link = xstrdup(value);
161 else if (!strcmp(name, "virtual-root")) { 162 else if (!strcmp(name, "virtual-root")) {
162 cgit_virtual_root = trim_end(value, '/'); 163 cgit_virtual_root = trim_end(value, '/');
163 if (!cgit_virtual_root && (!strcmp(value, "/"))) 164 if (!cgit_virtual_root && (!strcmp(value, "/")))
164 cgit_virtual_root = ""; 165 cgit_virtual_root = "";
165 } else if (!strcmp(name, "nocache")) 166 } else if (!strcmp(name, "nocache"))
166 cgit_nocache = atoi(value); 167 cgit_nocache = atoi(value);
167 else if (!strcmp(name, "snapshots")) 168 else if (!strcmp(name, "snapshots"))
168 cgit_snapshots = cgit_parse_snapshots_mask(value); 169 cgit_snapshots = cgit_parse_snapshots_mask(value);
169 else if (!strcmp(name, "enable-index-links")) 170 else if (!strcmp(name, "enable-index-links"))
170 cgit_enable_index_links = atoi(value); 171 cgit_enable_index_links = atoi(value);
171 else if (!strcmp(name, "enable-log-filecount")) 172 else if (!strcmp(name, "enable-log-filecount"))
172 cgit_enable_log_filecount = atoi(value); 173 cgit_enable_log_filecount = atoi(value);
173 else if (!strcmp(name, "enable-log-linecount")) 174 else if (!strcmp(name, "enable-log-linecount"))
174 cgit_enable_log_linecount = atoi(value); 175 cgit_enable_log_linecount = atoi(value);
175 else if (!strcmp(name, "cache-root")) 176 else if (!strcmp(name, "cache-root"))
176 cgit_cache_root = xstrdup(value); 177 cgit_cache_root = xstrdup(value);
177 else if (!strcmp(name, "cache-root-ttl")) 178 else if (!strcmp(name, "cache-root-ttl"))
178 cgit_cache_root_ttl = atoi(value); 179 cgit_cache_root_ttl = atoi(value);
179 else if (!strcmp(name, "cache-repo-ttl")) 180 else if (!strcmp(name, "cache-repo-ttl"))
180 cgit_cache_repo_ttl = atoi(value); 181 cgit_cache_repo_ttl = atoi(value);
181 else if (!strcmp(name, "cache-static-ttl")) 182 else if (!strcmp(name, "cache-static-ttl"))
182 cgit_cache_static_ttl = atoi(value); 183 cgit_cache_static_ttl = atoi(value);
183 else if (!strcmp(name, "cache-dynamic-ttl")) 184 else if (!strcmp(name, "cache-dynamic-ttl"))
184 cgit_cache_dynamic_ttl = atoi(value); 185 cgit_cache_dynamic_ttl = atoi(value);
185 else if (!strcmp(name, "max-message-length")) 186 else if (!strcmp(name, "max-message-length"))
186 cgit_max_msg_len = atoi(value); 187 cgit_max_msg_len = atoi(value);
187 else if (!strcmp(name, "max-repodesc-length")) 188 else if (!strcmp(name, "max-repodesc-length"))
188 cgit_max_repodesc_len = atoi(value); 189 cgit_max_repodesc_len = atoi(value);
189 else if (!strcmp(name, "max-commit-count")) 190 else if (!strcmp(name, "max-commit-count"))
190 cgit_max_commit_count = atoi(value); 191 cgit_max_commit_count = atoi(value);
191 else if (!strcmp(name, "summary-log")) 192 else if (!strcmp(name, "summary-log"))
192 cgit_summary_log = atoi(value); 193 cgit_summary_log = atoi(value);
193 else if (!strcmp(name, "summary-branches")) 194 else if (!strcmp(name, "summary-branches"))
194 cgit_summary_branches = atoi(value); 195 cgit_summary_branches = atoi(value);
195 else if (!strcmp(name, "summary-tags")) 196 else if (!strcmp(name, "summary-tags"))
196 cgit_summary_tags = atoi(value); 197 cgit_summary_tags = atoi(value);
197 else if (!strcmp(name, "agefile")) 198 else if (!strcmp(name, "agefile"))
198 cgit_agefile = xstrdup(value); 199 cgit_agefile = xstrdup(value);
199 else if (!strcmp(name, "renamelimit")) 200 else if (!strcmp(name, "renamelimit"))
200 cgit_renamelimit = atoi(value); 201 cgit_renamelimit = atoi(value);
201 else if (!strcmp(name, "robots")) 202 else if (!strcmp(name, "robots"))
202 cgit_robots = xstrdup(value); 203 cgit_robots = xstrdup(value);
204 else if (!strcmp(name, "clone-prefix"))
205 cgit_clone_prefix = xstrdup(value);
203 else if (!strcmp(name, "repo.group")) 206 else if (!strcmp(name, "repo.group"))
204 cgit_repo_group = xstrdup(value); 207 cgit_repo_group = xstrdup(value);
205 else if (!strcmp(name, "repo.url")) 208 else if (!strcmp(name, "repo.url"))
206 cgit_repo = add_repo(value); 209 cgit_repo = add_repo(value);
207 else if (!strcmp(name, "repo.name")) 210 else if (!strcmp(name, "repo.name"))
208 cgit_repo->name = xstrdup(value); 211 cgit_repo->name = xstrdup(value);
209 else if (cgit_repo && !strcmp(name, "repo.path")) 212 else if (cgit_repo && !strcmp(name, "repo.path"))
210 cgit_repo->path = trim_end(value, '/'); 213 cgit_repo->path = trim_end(value, '/');
214 else if (cgit_repo && !strcmp(name, "repo.clone-url"))
215 cgit_repo->clone_url = xstrdup(value);
211 else if (cgit_repo && !strcmp(name, "repo.desc")) 216 else if (cgit_repo && !strcmp(name, "repo.desc"))
212 cgit_repo->desc = xstrdup(value); 217 cgit_repo->desc = xstrdup(value);
213 else if (cgit_repo && !strcmp(name, "repo.owner")) 218 else if (cgit_repo && !strcmp(name, "repo.owner"))
214 cgit_repo->owner = xstrdup(value); 219 cgit_repo->owner = xstrdup(value);
215 else if (cgit_repo && !strcmp(name, "repo.defbranch")) 220 else if (cgit_repo && !strcmp(name, "repo.defbranch"))
216 cgit_repo->defbranch = xstrdup(value); 221 cgit_repo->defbranch = xstrdup(value);
217 else if (cgit_repo && !strcmp(name, "repo.snapshots")) 222 else if (cgit_repo && !strcmp(name, "repo.snapshots"))
218 cgit_repo->snapshots = cgit_snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ 223 cgit_repo->snapshots = cgit_snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */
219 else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount")) 224 else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount"))
220 cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value); 225 cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value);
221 else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount")) 226 else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount"))
222 cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value); 227 cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value);
223 else if (cgit_repo && !strcmp(name, "repo.module-link")) 228 else if (cgit_repo && !strcmp(name, "repo.module-link"))
224 cgit_repo->module_link= xstrdup(value); 229 cgit_repo->module_link= xstrdup(value);
225 else if (cgit_repo && !strcmp(name, "repo.readme") && value != NULL) { 230 else if (cgit_repo && !strcmp(name, "repo.readme") && value != NULL) {
226 if (*value == '/') 231 if (*value == '/')
227 cgit_repo->readme = xstrdup(value); 232 cgit_repo->readme = xstrdup(value);
228 else 233 else
229 cgit_repo->readme = xstrdup(fmt("%s/%s", cgit_repo->path, value)); 234 cgit_repo->readme = xstrdup(fmt("%s/%s", cgit_repo->path, value));
230 } else if (!strcmp(name, "include")) 235 } else if (!strcmp(name, "include"))
231 cgit_read_config(value, cgit_global_config_cb); 236 cgit_read_config(value, cgit_global_config_cb);
232} 237}
233 238
234void cgit_querystring_cb(const char *name, const char *value) 239void cgit_querystring_cb(const char *name, const char *value)
235{ 240{
236 if (!strcmp(name,"r")) { 241 if (!strcmp(name,"r")) {
237 cgit_query_repo = xstrdup(value); 242 cgit_query_repo = xstrdup(value);
238 cgit_repo = cgit_get_repoinfo(value); 243 cgit_repo = cgit_get_repoinfo(value);
239 } else if (!strcmp(name, "p")) { 244 } else if (!strcmp(name, "p")) {
240 cgit_query_page = xstrdup(value); 245 cgit_query_page = xstrdup(value);
241 cgit_cmd = cgit_get_cmd_index(value); 246 cgit_cmd = cgit_get_cmd_index(value);
242 } else if (!strcmp(name, "url")) { 247 } else if (!strcmp(name, "url")) {
243 cgit_parse_url(value); 248 cgit_parse_url(value);
244 } else if (!strcmp(name, "qt")) { 249 } else if (!strcmp(name, "qt")) {
245 cgit_query_grep = xstrdup(value); 250 cgit_query_grep = xstrdup(value);
246 } else if (!strcmp(name, "q")) { 251 } else if (!strcmp(name, "q")) {
247 cgit_query_search = xstrdup(value); 252 cgit_query_search = xstrdup(value);
248 } else if (!strcmp(name, "h")) { 253 } else if (!strcmp(name, "h")) {
249 cgit_query_head = xstrdup(value); 254 cgit_query_head = xstrdup(value);
250 cgit_query_has_symref = 1; 255 cgit_query_has_symref = 1;
251 } else if (!strcmp(name, "id")) { 256 } else if (!strcmp(name, "id")) {
252 cgit_query_sha1 = xstrdup(value); 257 cgit_query_sha1 = xstrdup(value);
253 cgit_query_has_sha1 = 1; 258 cgit_query_has_sha1 = 1;
254 } else if (!strcmp(name, "id2")) { 259 } else if (!strcmp(name, "id2")) {
255 cgit_query_sha2 = xstrdup(value); 260 cgit_query_sha2 = xstrdup(value);
256 cgit_query_has_sha1 = 1; 261 cgit_query_has_sha1 = 1;
257 } else if (!strcmp(name, "ofs")) { 262 } else if (!strcmp(name, "ofs")) {
258 cgit_query_ofs = atoi(value); 263 cgit_query_ofs = atoi(value);
259 } else if (!strcmp(name, "path")) { 264 } else if (!strcmp(name, "path")) {
260 cgit_query_path = trim_end(value, '/'); 265 cgit_query_path = trim_end(value, '/');
261 } else if (!strcmp(name, "name")) { 266 } else if (!strcmp(name, "name")) {
262 cgit_query_name = xstrdup(value); 267 cgit_query_name = xstrdup(value);
263 } 268 }
264} 269}
265 270
266void *cgit_free_commitinfo(struct commitinfo *info) 271void *cgit_free_commitinfo(struct commitinfo *info)
267{ 272{
268 free(info->author); 273 free(info->author);
269 free(info->author_email); 274 free(info->author_email);
270 free(info->committer); 275 free(info->committer);
271 free(info->committer_email); 276 free(info->committer_email);
272 free(info->subject); 277 free(info->subject);
273 free(info->msg); 278 free(info->msg);
274 free(info->msg_encoding); 279 free(info->msg_encoding);
275 free(info); 280 free(info);
276 return NULL; 281 return NULL;
277} 282}
278 283
279int hextoint(char c) 284int hextoint(char c)
280{ 285{
281 if (c >= 'a' && c <= 'f') 286 if (c >= 'a' && c <= 'f')
282 return 10 + c - 'a'; 287 return 10 + c - 'a';
283 else if (c >= 'A' && c <= 'F') 288 else if (c >= 'A' && c <= 'F')
284 return 10 + c - 'A'; 289 return 10 + c - 'A';
285 else if (c >= '0' && c <= '9') 290 else if (c >= '0' && c <= '9')
286 return c - '0'; 291 return c - '0';
287 else 292 else
288 return -1; 293 return -1;
289} 294}
290 295
291char *trim_end(const char *str, char c) 296char *trim_end(const char *str, char c)
292{ 297{
293 int len; 298 int len;
294 char *s, *t; 299 char *s, *t;
295 300
296 if (str == NULL) 301 if (str == NULL)
297 return NULL; 302 return NULL;
298 t = (char *)str; 303 t = (char *)str;
299 len = strlen(t); 304 len = strlen(t);
300 while(len > 0 && t[len - 1] == c) 305 while(len > 0 && t[len - 1] == c)
301 len--; 306 len--;
302 307
303 if (len == 0) 308 if (len == 0)
304 return NULL; 309 return NULL;
305 310
306 c = t[len]; 311 c = t[len];
307 t[len] = '\0'; 312 t[len] = '\0';
308 s = xstrdup(t); 313 s = xstrdup(t);
309 t[len] = c; 314 t[len] = c;
310 return s; 315 return s;
311} 316}
312 317
313char *strlpart(char *txt, int maxlen) 318char *strlpart(char *txt, int maxlen)
314{ 319{
315 char *result; 320 char *result;
316 321
317 if (!txt) 322 if (!txt)
318 return txt; 323 return txt;
319 324
320 if (strlen(txt) <= maxlen) 325 if (strlen(txt) <= maxlen)
321 return txt; 326 return txt;
322 result = xmalloc(maxlen + 1); 327 result = xmalloc(maxlen + 1);
323 memcpy(result, txt, maxlen - 3); 328 memcpy(result, txt, maxlen - 3);
324 result[maxlen-1] = result[maxlen-2] = result[maxlen-3] = '.'; 329 result[maxlen-1] = result[maxlen-2] = result[maxlen-3] = '.';
325 result[maxlen] = '\0'; 330 result[maxlen] = '\0';
326 return result; 331 return result;
327} 332}
328 333
329char *strrpart(char *txt, int maxlen) 334char *strrpart(char *txt, int maxlen)
330{ 335{
331 char *result; 336 char *result;
332 337
333 if (!txt) 338 if (!txt)
334 return txt; 339 return txt;
335 340
336 if (strlen(txt) <= maxlen) 341 if (strlen(txt) <= maxlen)
337 return txt; 342 return txt;
338 result = xmalloc(maxlen + 1); 343 result = xmalloc(maxlen + 1);
339 memcpy(result + 3, txt + strlen(txt) - maxlen + 4, maxlen - 3); 344 memcpy(result + 3, txt + strlen(txt) - maxlen + 4, maxlen - 3);
340 result[0] = result[1] = result[2] = '.'; 345 result[0] = result[1] = result[2] = '.';
341 return result; 346 return result;
342} 347}
343 348
344void cgit_add_ref(struct reflist *list, struct refinfo *ref) 349void cgit_add_ref(struct reflist *list, struct refinfo *ref)
345{ 350{
346 size_t size; 351 size_t size;
347 352
348 if (list->count >= list->alloc) { 353 if (list->count >= list->alloc) {
349 list->alloc += (list->alloc ? list->alloc : 4); 354 list->alloc += (list->alloc ? list->alloc : 4);
350 size = list->alloc * sizeof(struct refinfo *); 355 size = list->alloc * sizeof(struct refinfo *);
351 list->refs = xrealloc(list->refs, size); 356 list->refs = xrealloc(list->refs, size);
352 } 357 }
353 list->refs[list->count++] = ref; 358 list->refs[list->count++] = ref;
354} 359}
355 360
356struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char *sha1) 361struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char *sha1)
357{ 362{
358 struct refinfo *ref; 363 struct refinfo *ref;
359 364
360 ref = xmalloc(sizeof (struct refinfo)); 365 ref = xmalloc(sizeof (struct refinfo));
361 ref->refname = xstrdup(refname); 366 ref->refname = xstrdup(refname);
362 ref->object = parse_object(sha1); 367 ref->object = parse_object(sha1);
363 switch (ref->object->type) { 368 switch (ref->object->type) {
364 case OBJ_TAG: 369 case OBJ_TAG:
365 ref->tag = cgit_parse_tag((struct tag *)ref->object); 370 ref->tag = cgit_parse_tag((struct tag *)ref->object);
366 break; 371 break;
367 case OBJ_COMMIT: 372 case OBJ_COMMIT:
368 ref->commit = cgit_parse_commit((struct commit *)ref->object); 373 ref->commit = cgit_parse_commit((struct commit *)ref->object);
369 break; 374 break;
370 } 375 }
371 return ref; 376 return ref;
372} 377}
373 378
374int cgit_refs_cb(const char *refname, const unsigned char *sha1, int flags, 379int cgit_refs_cb(const char *refname, const unsigned char *sha1, int flags,
375 void *cb_data) 380 void *cb_data)
376{ 381{
377 struct reflist *list = (struct reflist *)cb_data; 382 struct reflist *list = (struct reflist *)cb_data;
378 struct refinfo *info = cgit_mk_refinfo(refname, sha1); 383 struct refinfo *info = cgit_mk_refinfo(refname, sha1);
379 384
380 if (info) 385 if (info)
381 cgit_add_ref(list, info); 386 cgit_add_ref(list, info);
382 return 0; 387 return 0;
383} 388}
384 389
385void cgit_diff_tree_cb(struct diff_queue_struct *q, 390void cgit_diff_tree_cb(struct diff_queue_struct *q,
386 struct diff_options *options, void *data) 391 struct diff_options *options, void *data)
387{ 392{
388 int i; 393 int i;
389 394
390 for (i = 0; i < q->nr; i++) { 395 for (i = 0; i < q->nr; i++) {
391 if (q->queue[i]->status == 'U') 396 if (q->queue[i]->status == 'U')
392 continue; 397 continue;
393 ((filepair_fn)data)(q->queue[i]); 398 ((filepair_fn)data)(q->queue[i]);
394 } 399 }
395} 400}
396 401
397static int load_mmfile(mmfile_t *file, const unsigned char *sha1) 402static int load_mmfile(mmfile_t *file, const unsigned char *sha1)
398{ 403{
399 enum object_type type; 404 enum object_type type;
400 405
401 if (is_null_sha1(sha1)) { 406 if (is_null_sha1(sha1)) {
402 file->ptr = (char *)""; 407 file->ptr = (char *)"";
diff --git a/ui-shared.c b/ui-shared.c
index 3e13c86..ece041c 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -271,275 +271,292 @@ void cgit_diff_link(char *name, char *title, char *class, char *head,
271 html_txt(name); 271 html_txt(name);
272 html("</a>"); 272 html("</a>");
273} 273}
274 274
275void cgit_object_link(struct object *obj) 275void cgit_object_link(struct object *obj)
276{ 276{
277 char *page, *arg, *url; 277 char *page, *arg, *url;
278 278
279 if (obj->type == OBJ_COMMIT) { 279 if (obj->type == OBJ_COMMIT) {
280 cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, 280 cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL,
281 cgit_query_head, sha1_to_hex(obj->sha1)); 281 cgit_query_head, sha1_to_hex(obj->sha1));
282 return; 282 return;
283 } else if (obj->type == OBJ_TREE) { 283 } else if (obj->type == OBJ_TREE) {
284 page = "tree"; 284 page = "tree";
285 arg = "id"; 285 arg = "id";
286 } else if (obj->type == OBJ_TAG) { 286 } else if (obj->type == OBJ_TAG) {
287 page = "tag"; 287 page = "tag";
288 arg = "id"; 288 arg = "id";
289 } else { 289 } else {
290 page = "blob"; 290 page = "blob";
291 arg = "id"; 291 arg = "id";
292 } 292 }
293 293
294 url = cgit_pageurl(cgit_query_repo, page, 294 url = cgit_pageurl(cgit_query_repo, page,
295 fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); 295 fmt("%s=%s", arg, sha1_to_hex(obj->sha1)));
296 html_link_open(url, NULL, NULL); 296 html_link_open(url, NULL, NULL);
297 htmlf("%s %s", typename(obj->type), 297 htmlf("%s %s", typename(obj->type),
298 sha1_to_hex(obj->sha1)); 298 sha1_to_hex(obj->sha1));
299 html_link_close(); 299 html_link_close();
300} 300}
301 301
302void cgit_print_date(time_t secs, char *format) 302void cgit_print_date(time_t secs, char *format)
303{ 303{
304 char buf[64]; 304 char buf[64];
305 struct tm *time; 305 struct tm *time;
306 306
307 if (!secs) 307 if (!secs)
308 return; 308 return;
309 time = gmtime(&secs); 309 time = gmtime(&secs);
310 strftime(buf, sizeof(buf)-1, format, time); 310 strftime(buf, sizeof(buf)-1, format, time);
311 html_txt(buf); 311 html_txt(buf);
312} 312}
313 313
314void cgit_print_age(time_t t, time_t max_relative, char *format) 314void cgit_print_age(time_t t, time_t max_relative, char *format)
315{ 315{
316 time_t now, secs; 316 time_t now, secs;
317 317
318 if (!t) 318 if (!t)
319 return; 319 return;
320 time(&now); 320 time(&now);
321 secs = now - t; 321 secs = now - t;
322 322
323 if (secs > max_relative && max_relative >= 0) { 323 if (secs > max_relative && max_relative >= 0) {
324 cgit_print_date(t, format); 324 cgit_print_date(t, format);
325 return; 325 return;
326 } 326 }
327 327
328 if (secs < TM_HOUR * 2) { 328 if (secs < TM_HOUR * 2) {
329 htmlf("<span class='age-mins'>%.0f min.</span>", 329 htmlf("<span class='age-mins'>%.0f min.</span>",
330 secs * 1.0 / TM_MIN); 330 secs * 1.0 / TM_MIN);
331 return; 331 return;
332 } 332 }
333 if (secs < TM_DAY * 2) { 333 if (secs < TM_DAY * 2) {
334 htmlf("<span class='age-hours'>%.0f hours</span>", 334 htmlf("<span class='age-hours'>%.0f hours</span>",
335 secs * 1.0 / TM_HOUR); 335 secs * 1.0 / TM_HOUR);
336 return; 336 return;
337 } 337 }
338 if (secs < TM_WEEK * 2) { 338 if (secs < TM_WEEK * 2) {
339 htmlf("<span class='age-days'>%.0f days</span>", 339 htmlf("<span class='age-days'>%.0f days</span>",
340 secs * 1.0 / TM_DAY); 340 secs * 1.0 / TM_DAY);
341 return; 341 return;
342 } 342 }
343 if (secs < TM_MONTH * 2) { 343 if (secs < TM_MONTH * 2) {
344 htmlf("<span class='age-weeks'>%.0f weeks</span>", 344 htmlf("<span class='age-weeks'>%.0f weeks</span>",
345 secs * 1.0 / TM_WEEK); 345 secs * 1.0 / TM_WEEK);
346 return; 346 return;
347 } 347 }
348 if (secs < TM_YEAR * 2) { 348 if (secs < TM_YEAR * 2) {
349 htmlf("<span class='age-months'>%.0f months</span>", 349 htmlf("<span class='age-months'>%.0f months</span>",
350 secs * 1.0 / TM_MONTH); 350 secs * 1.0 / TM_MONTH);
351 return; 351 return;
352 } 352 }
353 htmlf("<span class='age-years'>%.0f years</span>", 353 htmlf("<span class='age-years'>%.0f years</span>",
354 secs * 1.0 / TM_YEAR); 354 secs * 1.0 / TM_YEAR);
355} 355}
356 356
357void cgit_print_docstart(char *title, struct cacheitem *item) 357void cgit_print_docstart(char *title, struct cacheitem *item)
358{ 358{
359 html("Content-Type: text/html; charset=" PAGE_ENCODING "\n"); 359 html("Content-Type: text/html; charset=" PAGE_ENCODING "\n");
360 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); 360 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime));
361 htmlf("Expires: %s\n", http_date(item->st.st_mtime + 361 htmlf("Expires: %s\n", http_date(item->st.st_mtime +
362 ttl_seconds(item->ttl))); 362 ttl_seconds(item->ttl)));
363 html("\n"); 363 html("\n");
364 html(cgit_doctype); 364 html(cgit_doctype);
365 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); 365 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
366 html("<head>\n"); 366 html("<head>\n");
367 html("<title>"); 367 html("<title>");
368 html_txt(title); 368 html_txt(title);
369 html("</title>\n"); 369 html("</title>\n");
370 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); 370 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
371 if (cgit_robots && *cgit_robots) 371 if (cgit_robots && *cgit_robots)
372 htmlf("<meta name='robots' content='%s'/>\n", cgit_robots); 372 htmlf("<meta name='robots' content='%s'/>\n", cgit_robots);
373 html("<link rel='stylesheet' type='text/css' href='"); 373 html("<link rel='stylesheet' type='text/css' href='");
374 html_attr(cgit_css); 374 html_attr(cgit_css);
375 html("'/>\n"); 375 html("'/>\n");
376 html("</head>\n"); 376 html("</head>\n");
377 html("<body>\n"); 377 html("<body>\n");
378} 378}
379 379
380void cgit_print_docend() 380void cgit_print_docend()
381{ 381{
382 html("</td>\n</tr>\n</table>\n</body>\n</html>\n"); 382 html("</td>\n</tr>\n</table>\n</body>\n</html>\n");
383} 383}
384 384
385int print_branch_option(const char *refname, const unsigned char *sha1, 385int print_branch_option(const char *refname, const unsigned char *sha1,
386 int flags, void *cb_data) 386 int flags, void *cb_data)
387{ 387{
388 char *name = (char *)refname; 388 char *name = (char *)refname;
389 html_option(name, name, cgit_query_head); 389 html_option(name, name, cgit_query_head);
390 return 0; 390 return 0;
391} 391}
392 392
393int print_archive_ref(const char *refname, const unsigned char *sha1, 393int print_archive_ref(const char *refname, const unsigned char *sha1,
394 int flags, void *cb_data) 394 int flags, void *cb_data)
395{ 395{
396 struct tag *tag; 396 struct tag *tag;
397 struct taginfo *info; 397 struct taginfo *info;
398 struct object *obj; 398 struct object *obj;
399 char buf[256], *url; 399 char buf[256], *url;
400 unsigned char fileid[20]; 400 unsigned char fileid[20];
401 int *header = (int *)cb_data; 401 int *header = (int *)cb_data;
402 402
403 if (prefixcmp(refname, "refs/archives")) 403 if (prefixcmp(refname, "refs/archives"))
404 return 0; 404 return 0;
405 strncpy(buf, refname+14, sizeof(buf)); 405 strncpy(buf, refname+14, sizeof(buf));
406 obj = parse_object(sha1); 406 obj = parse_object(sha1);
407 if (!obj) 407 if (!obj)
408 return 1; 408 return 1;
409 if (obj->type == OBJ_TAG) { 409 if (obj->type == OBJ_TAG) {
410 tag = lookup_tag(sha1); 410 tag = lookup_tag(sha1);
411 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) 411 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
412 return 0; 412 return 0;
413 hashcpy(fileid, tag->tagged->sha1); 413 hashcpy(fileid, tag->tagged->sha1);
414 } else if (obj->type != OBJ_BLOB) { 414 } else if (obj->type != OBJ_BLOB) {
415 return 0; 415 return 0;
416 } else { 416 } else {
417 hashcpy(fileid, sha1); 417 hashcpy(fileid, sha1);
418 } 418 }
419 if (!*header) { 419 if (!*header) {
420 html("<h1>download</h1>\n"); 420 html("<h1>download</h1>\n");
421 *header = 1; 421 *header = 1;
422 } 422 }
423 url = cgit_pageurl(cgit_query_repo, "blob", 423 url = cgit_pageurl(cgit_query_repo, "blob",
424 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid), 424 fmt("id=%s&amp;path=%s", sha1_to_hex(fileid),
425 buf)); 425 buf));
426 html_link_open(url, NULL, "menu"); 426 html_link_open(url, NULL, "menu");
427 html_txt(strlpart(buf, 20)); 427 html_txt(strlpart(buf, 20));
428 html_link_close(); 428 html_link_close();
429 return 0; 429 return 0;
430} 430}
431 431
432void add_hidden_formfields(int incl_head, int incl_search, char *page) 432void add_hidden_formfields(int incl_head, int incl_search, char *page)
433{ 433{
434 char *url; 434 char *url;
435 435
436 if (!cgit_virtual_root) { 436 if (!cgit_virtual_root) {
437 url = fmt("%s/%s", cgit_query_repo, page); 437 url = fmt("%s/%s", cgit_query_repo, page);
438 if (cgit_query_path) 438 if (cgit_query_path)
439 url = fmt("%s/%s", url, cgit_query_path); 439 url = fmt("%s/%s", url, cgit_query_path);
440 html_hidden("url", url); 440 html_hidden("url", url);
441 } 441 }
442 442
443 if (incl_head && strcmp(cgit_query_head, cgit_repo->defbranch)) 443 if (incl_head && strcmp(cgit_query_head, cgit_repo->defbranch))
444 html_hidden("h", cgit_query_head); 444 html_hidden("h", cgit_query_head);
445 445
446 if (cgit_query_sha1) 446 if (cgit_query_sha1)
447 html_hidden("id", cgit_query_sha1); 447 html_hidden("id", cgit_query_sha1);
448 if (cgit_query_sha2) 448 if (cgit_query_sha2)
449 html_hidden("id2", cgit_query_sha2); 449 html_hidden("id2", cgit_query_sha2);
450 450
451 if (incl_search) { 451 if (incl_search) {
452 if (cgit_query_grep) 452 if (cgit_query_grep)
453 html_hidden("qt", cgit_query_grep); 453 html_hidden("qt", cgit_query_grep);
454 if (cgit_query_search) 454 if (cgit_query_search)
455 html_hidden("q", cgit_query_search); 455 html_hidden("q", cgit_query_search);
456 } 456 }
457} 457}
458 458
459void cgit_print_pageheader(char *title, int show_search) 459void cgit_print_pageheader(char *title, int show_search)
460{ 460{
461 static const char *default_info = "This is cgit, a fast webinterface for git repositories"; 461 static const char *default_info = "This is cgit, a fast webinterface for git repositories";
462 int header = 0; 462 int header = 0;
463 char *url;
463 464
464 html("<table id='layout' summary=''>\n"); 465 html("<table id='layout' summary=''>\n");
465 html("<tr><td id='sidebar'>\n"); 466 html("<tr><td id='sidebar'>\n");
466 html("<table class='sidebar' cellspacing='0' summary=''>\n"); 467 html("<table class='sidebar' cellspacing='0' summary=''>\n");
467 html("<tr><td class='sidebar'>\n<a href='"); 468 html("<tr><td class='sidebar'>\n<a href='");
468 html_attr(cgit_rooturl()); 469 html_attr(cgit_rooturl());
469 htmlf("'><img src='%s' alt='cgit'/></a>\n", 470 htmlf("'><img src='%s' alt='cgit'/></a>\n",
470 cgit_logo); 471 cgit_logo);
471 html("</td></tr>\n<tr><td class='sidebar'>\n"); 472 html("</td></tr>\n<tr><td class='sidebar'>\n");
472 if (cgit_query_repo) { 473 if (cgit_query_repo) {
473 html("<h1 class='first'>"); 474 html("<h1 class='first'>");
474 html_txt(strrpart(cgit_repo->name, 20)); 475 html_txt(strrpart(cgit_repo->name, 20));
475 html("</h1>\n"); 476 html("</h1>\n");
476 html_txt(cgit_repo->desc); 477 html_txt(cgit_repo->desc);
477 if (cgit_repo->owner) { 478 if (cgit_repo->owner) {
478 html("<h1>owner</h1>\n"); 479 html("<h1>owner</h1>\n");
479 html_txt(cgit_repo->owner); 480 html_txt(cgit_repo->owner);
480 } 481 }
481 html("<h1>navigate</h1>\n"); 482 html("<h1>navigate</h1>\n");
482 reporevlink(NULL, "summary", NULL, "menu", cgit_query_head, 483 reporevlink(NULL, "summary", NULL, "menu", cgit_query_head,
483 NULL, NULL); 484 NULL, NULL);
484 cgit_log_link("log", NULL, "menu", cgit_query_head, NULL, NULL, 485 cgit_log_link("log", NULL, "menu", cgit_query_head, NULL, NULL,
485 0, NULL, NULL); 486 0, NULL, NULL);
486 cgit_tree_link("tree", NULL, "menu", cgit_query_head, 487 cgit_tree_link("tree", NULL, "menu", cgit_query_head,
487 cgit_query_sha1, NULL); 488 cgit_query_sha1, NULL);
488 cgit_commit_link("commit", NULL, "menu", cgit_query_head, 489 cgit_commit_link("commit", NULL, "menu", cgit_query_head,
489 cgit_query_sha1); 490 cgit_query_sha1);
490 cgit_diff_link("diff", NULL, "menu", cgit_query_head, 491 cgit_diff_link("diff", NULL, "menu", cgit_query_head,
491 cgit_query_sha1, cgit_query_sha2, NULL); 492 cgit_query_sha1, cgit_query_sha2, NULL);
492 493
493 for_each_ref(print_archive_ref, &header); 494 for_each_ref(print_archive_ref, &header);
494 495
496 if (cgit_repo->clone_url || cgit_clone_prefix) {
497 html("<h1>clone</h1>\n");
498 if (cgit_repo->clone_url)
499 url = cgit_repo->clone_url;
500 else
501 url = fmt("%s%s", cgit_clone_prefix,
502 cgit_repo->url);
503 html("<a class='menu' href='");
504 html_attr(url);
505 html("' title='");
506 html_attr(url);
507 html("'>\n");
508 html_txt(strrpart(url, 20));
509 html("</a>\n");
510 }
511
495 html("<h1>branch</h1>\n"); 512 html("<h1>branch</h1>\n");
496 html("<form method='get' action=''>\n"); 513 html("<form method='get' action=''>\n");
497 add_hidden_formfields(0, 1, cgit_query_page); 514 add_hidden_formfields(0, 1, cgit_query_page);
498 // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>"); 515 // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>");
499 html("<select name='h' onchange='this.form.submit();'>\n"); 516 html("<select name='h' onchange='this.form.submit();'>\n");
500 for_each_branch_ref(print_branch_option, cgit_query_head); 517 for_each_branch_ref(print_branch_option, cgit_query_head);
501 html("</select>\n"); 518 html("</select>\n");
502 // html("</td><td>"); 519 // html("</td><td>");
503 html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n"); 520 html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n");
504 // html("</td></tr></table>"); 521 // html("</td></tr></table>");
505 html("</form>\n"); 522 html("</form>\n");
506 523
507 html("<h1>search</h1>\n"); 524 html("<h1>search</h1>\n");
508 html("<form method='get' action='"); 525 html("<form method='get' action='");
509 if (cgit_virtual_root) 526 if (cgit_virtual_root)
510 html_attr(cgit_fileurl(cgit_query_repo, "log", 527 html_attr(cgit_fileurl(cgit_query_repo, "log",
511 cgit_query_path, NULL)); 528 cgit_query_path, NULL));
512 html("'>\n"); 529 html("'>\n");
513 add_hidden_formfields(1, 0, "log"); 530 add_hidden_formfields(1, 0, "log");
514 html("<select name='qt'>\n"); 531 html("<select name='qt'>\n");
515 html_option("grep", "log msg", cgit_query_grep); 532 html_option("grep", "log msg", cgit_query_grep);
516 html_option("author", "author", cgit_query_grep); 533 html_option("author", "author", cgit_query_grep);
517 html_option("committer", "committer", cgit_query_grep); 534 html_option("committer", "committer", cgit_query_grep);
518 html("</select>\n"); 535 html("</select>\n");
519 html("<input class='txt' type='text' name='q' value='"); 536 html("<input class='txt' type='text' name='q' value='");
520 html_attr(cgit_query_search); 537 html_attr(cgit_query_search);
521 html("'/>\n"); 538 html("'/>\n");
522 html("</form>\n"); 539 html("</form>\n");
523 } else { 540 } else {
524 if (!cgit_index_info || html_include(cgit_index_info)) 541 if (!cgit_index_info || html_include(cgit_index_info))
525 html(default_info); 542 html(default_info);
526 } 543 }
527 544
528 html("</td></tr></table></td>\n"); 545 html("</td></tr></table></td>\n");
529 546
530 html("<td id='content'>\n"); 547 html("<td id='content'>\n");
531} 548}
532 549
533 550
534void cgit_print_snapshot_start(const char *mimetype, const char *filename, 551void cgit_print_snapshot_start(const char *mimetype, const char *filename,
535 struct cacheitem *item) 552 struct cacheitem *item)
536{ 553{
537 htmlf("Content-Type: %s\n", mimetype); 554 htmlf("Content-Type: %s\n", mimetype);
538 htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); 555 htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename);
539 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); 556 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime));
540 htmlf("Expires: %s\n", http_date(item->st.st_mtime + 557 htmlf("Expires: %s\n", http_date(item->st.st_mtime +
541 ttl_seconds(item->ttl))); 558 ttl_seconds(item->ttl)));
542 html("\n"); 559 html("\n");
543} 560}
544 561
545/* vim:set sw=8: */ 562/* vim:set sw=8: */