author | Lars Hjemli <hjemli@gmail.com> | 2007-06-18 22:56:40 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-06-18 22:56:40 (UTC) |
commit | 0d05bca502f4a5347fa629045aca97ba9b404acc (patch) (unidiff) | |
tree | e11b6a3e183aab02824f83c51759b5d426a64a67 | |
parent | a215bf4620113fcefb8dd3442bf3501bd648c463 (diff) | |
download | cgit-0d05bca502f4a5347fa629045aca97ba9b404acc.zip cgit-0d05bca502f4a5347fa629045aca97ba9b404acc.tar.gz cgit-0d05bca502f4a5347fa629045aca97ba9b404acc.tar.bz2 |
Add setting to enable/disable extra links on index page
The summary/log/tree links displayed for each repository on the index
page lost some of their purpose when the header menu was added, so this
commit introduces the parameter 'enable-index-links' which must be set
to 1 to enable these links.
Suggested-by: Kristian Høgsberg <krh@bitplanet.net>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.h | 1 | ||||
-rw-r--r-- | cgitrc | 4 | ||||
-rw-r--r-- | shared.c | 3 | ||||
-rw-r--r-- | ui-repolist.c | 35 |
4 files changed, 31 insertions, 12 deletions
@@ -1,234 +1,235 @@ | |||
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 | ||
21 | /* | 21 | /* |
22 | * The valid cgit repo-commands | 22 | * The valid cgit repo-commands |
23 | */ | 23 | */ |
24 | #define CMD_LOG 1 | 24 | #define CMD_LOG 1 |
25 | #define CMD_COMMIT 2 | 25 | #define CMD_COMMIT 2 |
26 | #define CMD_DIFF 3 | 26 | #define CMD_DIFF 3 |
27 | #define CMD_TREE 4 | 27 | #define CMD_TREE 4 |
28 | #define CMD_BLOB 5 | 28 | #define CMD_BLOB 5 |
29 | #define CMD_SNAPSHOT 6 | 29 | #define CMD_SNAPSHOT 6 |
30 | 30 | ||
31 | 31 | ||
32 | /* | 32 | /* |
33 | * Dateformats used on misc. pages | 33 | * Dateformats used on misc. pages |
34 | */ | 34 | */ |
35 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" | 35 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S" |
36 | #define FMT_SHORTDATE "%Y-%m-%d" | 36 | #define FMT_SHORTDATE "%Y-%m-%d" |
37 | 37 | ||
38 | 38 | ||
39 | /* | 39 | /* |
40 | * Limits used for relative dates | 40 | * Limits used for relative dates |
41 | */ | 41 | */ |
42 | #define TM_MIN 60 | 42 | #define TM_MIN 60 |
43 | #define TM_HOUR (TM_MIN * 60) | 43 | #define TM_HOUR (TM_MIN * 60) |
44 | #define TM_DAY (TM_HOUR * 24) | 44 | #define TM_DAY (TM_HOUR * 24) |
45 | #define TM_WEEK (TM_DAY * 7) | 45 | #define TM_WEEK (TM_DAY * 7) |
46 | #define TM_YEAR (TM_DAY * 365) | 46 | #define TM_YEAR (TM_DAY * 365) |
47 | #define TM_MONTH (TM_YEAR / 12.0) | 47 | #define TM_MONTH (TM_YEAR / 12.0) |
48 | 48 | ||
49 | 49 | ||
50 | typedef void (*configfn)(const char *name, const char *value); | 50 | typedef void (*configfn)(const char *name, const char *value); |
51 | typedef void (*filepair_fn)(struct diff_filepair *pair); | 51 | typedef void (*filepair_fn)(struct diff_filepair *pair); |
52 | typedef void (*linediff_fn)(char *line, int len); | 52 | typedef void (*linediff_fn)(char *line, int len); |
53 | 53 | ||
54 | struct cacheitem { | 54 | struct cacheitem { |
55 | char *name; | 55 | char *name; |
56 | struct stat st; | 56 | struct stat st; |
57 | int ttl; | 57 | int ttl; |
58 | int fd; | 58 | int fd; |
59 | }; | 59 | }; |
60 | 60 | ||
61 | struct repoinfo { | 61 | struct repoinfo { |
62 | char *url; | 62 | char *url; |
63 | char *name; | 63 | char *name; |
64 | char *path; | 64 | char *path; |
65 | char *desc; | 65 | char *desc; |
66 | char *owner; | 66 | char *owner; |
67 | char *defbranch; | 67 | char *defbranch; |
68 | char *group; | 68 | char *group; |
69 | char *module_link; | 69 | char *module_link; |
70 | char *readme; | 70 | char *readme; |
71 | int snapshots; | 71 | int snapshots; |
72 | int enable_log_filecount; | 72 | int enable_log_filecount; |
73 | int enable_log_linecount; | 73 | int enable_log_linecount; |
74 | }; | 74 | }; |
75 | 75 | ||
76 | struct repolist { | 76 | struct repolist { |
77 | int length; | 77 | int length; |
78 | int count; | 78 | int count; |
79 | struct repoinfo *repos; | 79 | struct repoinfo *repos; |
80 | }; | 80 | }; |
81 | 81 | ||
82 | struct commitinfo { | 82 | struct commitinfo { |
83 | struct commit *commit; | 83 | struct commit *commit; |
84 | char *author; | 84 | char *author; |
85 | char *author_email; | 85 | char *author_email; |
86 | unsigned long author_date; | 86 | unsigned long author_date; |
87 | char *committer; | 87 | char *committer; |
88 | char *committer_email; | 88 | char *committer_email; |
89 | unsigned long committer_date; | 89 | unsigned long committer_date; |
90 | char *subject; | 90 | char *subject; |
91 | char *msg; | 91 | char *msg; |
92 | }; | 92 | }; |
93 | 93 | ||
94 | struct taginfo { | 94 | struct taginfo { |
95 | char *tagger; | 95 | char *tagger; |
96 | char *tagger_email; | 96 | char *tagger_email; |
97 | int tagger_date; | 97 | int tagger_date; |
98 | char *msg; | 98 | char *msg; |
99 | }; | 99 | }; |
100 | 100 | ||
101 | extern const char cgit_version[]; | 101 | extern const char cgit_version[]; |
102 | 102 | ||
103 | extern struct repolist cgit_repolist; | 103 | extern struct repolist cgit_repolist; |
104 | extern struct repoinfo *cgit_repo; | 104 | extern struct repoinfo *cgit_repo; |
105 | extern int cgit_cmd; | 105 | extern int cgit_cmd; |
106 | 106 | ||
107 | extern char *cgit_root_title; | 107 | extern char *cgit_root_title; |
108 | extern char *cgit_css; | 108 | extern char *cgit_css; |
109 | extern char *cgit_logo; | 109 | extern char *cgit_logo; |
110 | extern char *cgit_index_header; | 110 | extern char *cgit_index_header; |
111 | extern char *cgit_logo_link; | 111 | extern char *cgit_logo_link; |
112 | extern char *cgit_module_link; | 112 | extern char *cgit_module_link; |
113 | extern char *cgit_agefile; | 113 | extern char *cgit_agefile; |
114 | extern char *cgit_virtual_root; | 114 | extern char *cgit_virtual_root; |
115 | extern char *cgit_script_name; | 115 | extern char *cgit_script_name; |
116 | extern char *cgit_cache_root; | 116 | extern char *cgit_cache_root; |
117 | extern char *cgit_repo_group; | 117 | extern char *cgit_repo_group; |
118 | 118 | ||
119 | extern int cgit_nocache; | 119 | extern int cgit_nocache; |
120 | extern int cgit_snapshots; | 120 | extern int cgit_snapshots; |
121 | extern int cgit_enable_index_links; | ||
121 | extern int cgit_enable_log_filecount; | 122 | extern int cgit_enable_log_filecount; |
122 | extern int cgit_enable_log_linecount; | 123 | extern int cgit_enable_log_linecount; |
123 | extern int cgit_max_lock_attempts; | 124 | extern int cgit_max_lock_attempts; |
124 | extern int cgit_cache_root_ttl; | 125 | extern int cgit_cache_root_ttl; |
125 | extern int cgit_cache_repo_ttl; | 126 | extern int cgit_cache_repo_ttl; |
126 | extern int cgit_cache_dynamic_ttl; | 127 | extern int cgit_cache_dynamic_ttl; |
127 | extern int cgit_cache_static_ttl; | 128 | extern int cgit_cache_static_ttl; |
128 | extern int cgit_cache_max_create_time; | 129 | extern int cgit_cache_max_create_time; |
129 | extern int cgit_summary_log; | 130 | extern int cgit_summary_log; |
130 | 131 | ||
131 | extern int cgit_max_msg_len; | 132 | extern int cgit_max_msg_len; |
132 | extern int cgit_max_repodesc_len; | 133 | extern int cgit_max_repodesc_len; |
133 | extern int cgit_max_commit_count; | 134 | extern int cgit_max_commit_count; |
134 | 135 | ||
135 | extern int cgit_query_has_symref; | 136 | extern int cgit_query_has_symref; |
136 | extern int cgit_query_has_sha1; | 137 | extern int cgit_query_has_sha1; |
137 | 138 | ||
138 | extern char *cgit_querystring; | 139 | extern char *cgit_querystring; |
139 | extern char *cgit_query_repo; | 140 | extern char *cgit_query_repo; |
140 | extern char *cgit_query_page; | 141 | extern char *cgit_query_page; |
141 | extern char *cgit_query_search; | 142 | extern char *cgit_query_search; |
142 | extern char *cgit_query_head; | 143 | extern char *cgit_query_head; |
143 | extern char *cgit_query_sha1; | 144 | extern char *cgit_query_sha1; |
144 | extern char *cgit_query_sha2; | 145 | extern char *cgit_query_sha2; |
145 | extern char *cgit_query_path; | 146 | extern char *cgit_query_path; |
146 | extern char *cgit_query_name; | 147 | extern char *cgit_query_name; |
147 | extern int cgit_query_ofs; | 148 | extern int cgit_query_ofs; |
148 | 149 | ||
149 | extern int htmlfd; | 150 | extern int htmlfd; |
150 | 151 | ||
151 | extern int cgit_get_cmd_index(const char *cmd); | 152 | extern int cgit_get_cmd_index(const char *cmd); |
152 | extern struct repoinfo *cgit_get_repoinfo(const char *url); | 153 | extern struct repoinfo *cgit_get_repoinfo(const char *url); |
153 | extern void cgit_global_config_cb(const char *name, const char *value); | 154 | extern void cgit_global_config_cb(const char *name, const char *value); |
154 | extern void cgit_repo_config_cb(const char *name, const char *value); | 155 | extern void cgit_repo_config_cb(const char *name, const char *value); |
155 | extern void cgit_querystring_cb(const char *name, const char *value); | 156 | extern void cgit_querystring_cb(const char *name, const char *value); |
156 | 157 | ||
157 | extern int chk_zero(int result, char *msg); | 158 | extern int chk_zero(int result, char *msg); |
158 | extern int chk_positive(int result, char *msg); | 159 | extern int chk_positive(int result, char *msg); |
159 | 160 | ||
160 | extern int hextoint(char c); | 161 | extern int hextoint(char c); |
161 | 162 | ||
162 | extern void *cgit_free_commitinfo(struct commitinfo *info); | 163 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
163 | 164 | ||
164 | extern int cgit_diff_files(const unsigned char *old_sha1, | 165 | extern int cgit_diff_files(const unsigned char *old_sha1, |
165 | const unsigned char *new_sha1, | 166 | const unsigned char *new_sha1, |
166 | linediff_fn fn); | 167 | linediff_fn fn); |
167 | 168 | ||
168 | extern void cgit_diff_tree(const unsigned char *old_sha1, | 169 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
169 | const unsigned char *new_sha1, | 170 | const unsigned char *new_sha1, |
170 | filepair_fn fn); | 171 | filepair_fn fn); |
171 | 172 | ||
172 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); | 173 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
173 | 174 | ||
174 | extern char *fmt(const char *format,...); | 175 | extern char *fmt(const char *format,...); |
175 | 176 | ||
176 | extern void html(const char *txt); | 177 | extern void html(const char *txt); |
177 | extern void htmlf(const char *format,...); | 178 | extern void htmlf(const char *format,...); |
178 | extern void html_txt(char *txt); | 179 | extern void html_txt(char *txt); |
179 | extern void html_ntxt(int len, char *txt); | 180 | extern void html_ntxt(int len, char *txt); |
180 | extern void html_attr(char *txt); | 181 | extern void html_attr(char *txt); |
181 | extern void html_hidden(char *name, char *value); | 182 | extern void html_hidden(char *name, char *value); |
182 | extern void html_link_open(char *url, char *title, char *class); | 183 | extern void html_link_open(char *url, char *title, char *class); |
183 | extern void html_link_close(void); | 184 | extern void html_link_close(void); |
184 | extern void html_filemode(unsigned short mode); | 185 | extern void html_filemode(unsigned short mode); |
185 | extern int html_include(const char *filename); | 186 | extern int html_include(const char *filename); |
186 | 187 | ||
187 | extern int cgit_read_config(const char *filename, configfn fn); | 188 | extern int cgit_read_config(const char *filename, configfn fn); |
188 | extern int cgit_parse_query(char *txt, configfn fn); | 189 | extern int cgit_parse_query(char *txt, configfn fn); |
189 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 190 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
190 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 191 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
191 | extern void cgit_parse_url(const char *url); | 192 | extern void cgit_parse_url(const char *url); |
192 | 193 | ||
193 | extern char *cache_safe_filename(const char *unsafe); | 194 | extern char *cache_safe_filename(const char *unsafe); |
194 | extern int cache_lock(struct cacheitem *item); | 195 | extern int cache_lock(struct cacheitem *item); |
195 | extern int cache_unlock(struct cacheitem *item); | 196 | extern int cache_unlock(struct cacheitem *item); |
196 | extern int cache_cancel_lock(struct cacheitem *item); | 197 | extern int cache_cancel_lock(struct cacheitem *item); |
197 | extern int cache_exist(struct cacheitem *item); | 198 | extern int cache_exist(struct cacheitem *item); |
198 | extern int cache_expired(struct cacheitem *item); | 199 | extern int cache_expired(struct cacheitem *item); |
199 | 200 | ||
200 | extern char *cgit_repourl(const char *reponame); | 201 | extern char *cgit_repourl(const char *reponame); |
201 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 202 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
202 | const char *query); | 203 | const char *query); |
203 | 204 | ||
204 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, | 205 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, |
205 | char *rev, char *path); | 206 | char *rev, char *path); |
206 | extern void cgit_log_link(char *name, char *title, char *class, char *head, | 207 | extern void cgit_log_link(char *name, char *title, char *class, char *head, |
207 | char *rev, char *path); | 208 | char *rev, char *path); |
208 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, | 209 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, |
209 | char *rev); | 210 | char *rev); |
210 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, | 211 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, |
211 | char *new_rev, char *old_rev, char *path); | 212 | char *new_rev, char *old_rev, char *path); |
212 | 213 | ||
213 | extern void cgit_print_error(char *msg); | 214 | extern void cgit_print_error(char *msg); |
214 | extern void cgit_print_date(time_t secs, char *format); | 215 | extern void cgit_print_date(time_t secs, char *format); |
215 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 216 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
216 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 217 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
217 | extern void cgit_print_docend(); | 218 | extern void cgit_print_docend(); |
218 | extern void cgit_print_pageheader(char *title, int show_search); | 219 | extern void cgit_print_pageheader(char *title, int show_search); |
219 | extern void cgit_print_snapshot_start(const char *mimetype, | 220 | extern void cgit_print_snapshot_start(const char *mimetype, |
220 | const char *filename, | 221 | const char *filename, |
221 | struct cacheitem *item); | 222 | struct cacheitem *item); |
222 | 223 | ||
223 | extern void cgit_print_repolist(struct cacheitem *item); | 224 | extern void cgit_print_repolist(struct cacheitem *item); |
224 | extern void cgit_print_summary(); | 225 | extern void cgit_print_summary(); |
225 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); | 226 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); |
226 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); | 227 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
227 | extern void cgit_print_tree(const char *rev, char *path); | 228 | extern void cgit_print_tree(const char *rev, char *path); |
228 | extern void cgit_print_commit(char *hex); | 229 | extern void cgit_print_commit(char *hex); |
229 | extern void cgit_print_diff(const char *new_hex, const char *old_hex); | 230 | extern void cgit_print_diff(const char *new_hex, const char *old_hex); |
230 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, | 231 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, |
231 | const char *format, const char *prefix, | 232 | const char *format, const char *prefix, |
232 | const char *filename); | 233 | const char *filename); |
233 | 234 | ||
234 | #endif /* CGIT_H */ | 235 | #endif /* CGIT_H */ |
@@ -1,116 +1,120 @@ | |||
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 | ## Enable/disable extra links to summary/log/tree per repo on index page | ||
16 | #enable-index-links=0 | ||
17 | |||
18 | |||
15 | ## Enable/disable display of 'number of files changed' in log view | 19 | ## Enable/disable display of 'number of files changed' in log view |
16 | #enable-log-filecount=0 | 20 | #enable-log-filecount=0 |
17 | 21 | ||
18 | 22 | ||
19 | ## Enable/disable display of 'number of lines changed' in log view | 23 | ## Enable/disable display of 'number of lines changed' in log view |
20 | #enable-log-linecount=0 | 24 | #enable-log-linecount=0 |
21 | 25 | ||
22 | 26 | ||
23 | ## Enable/disable display of HEAD shortlog in summary view. Set it to maximum | 27 | ## Enable/disable display of HEAD shortlog in summary view. Set it to maximum |
24 | ## number of commits that should be displayed | 28 | ## number of commits that should be displayed |
25 | #summary-log=0 | 29 | #summary-log=0 |
26 | 30 | ||
27 | 31 | ||
28 | ## Specify a root for virtual urls. This makes cgit generate urls like | 32 | ## Specify a root for virtual urls. This makes cgit generate urls like |
29 | ## | 33 | ## |
30 | ## http://localhost/git/repo/log/?id=master | 34 | ## http://localhost/git/repo/log/?id=master |
31 | ## | 35 | ## |
32 | ## instead of | 36 | ## instead of |
33 | ## | 37 | ## |
34 | ## http://localhost/cgit/cgit.cgi?r=repo&p=log&id=master | 38 | ## http://localhost/cgit/cgit.cgi?r=repo&p=log&id=master |
35 | ## | 39 | ## |
36 | ## For this to work with apache, rewrite rules must be added to httpd.conf, | 40 | ## For this to work with apache, rewrite rules must be added to httpd.conf, |
37 | ## possibly looking something like this: | 41 | ## possibly looking something like this: |
38 | ## | 42 | ## |
39 | ## RewriteRule ^/git/$ /cgit/cgit.cgi [L,QSA] | 43 | ## RewriteRule ^/git/$ /cgit/cgit.cgi [L,QSA] |
40 | ## RewriteRule ^/git/([^/]+)/$ /cgit/cgit.cgi?r=$1 [L,QSA] | 44 | ## RewriteRule ^/git/([^/]+)/$ /cgit/cgit.cgi?r=$1 [L,QSA] |
41 | ## RewriteRule ^/git/([^/]+)/([^/]+)/$ /cgit/cgit.cgi?r=$1&p=$2 [L,QSA] | 45 | ## RewriteRule ^/git/([^/]+)/([^/]+)/$ /cgit/cgit.cgi?r=$1&p=$2 [L,QSA] |
42 | ## | 46 | ## |
43 | ## This setting is disabled by default. | 47 | ## This setting is disabled by default. |
44 | #virtual-root=/git | 48 | #virtual-root=/git |
45 | 49 | ||
46 | 50 | ||
47 | ## Set the title printed on the root page | 51 | ## Set the title printed on the root page |
48 | #root-title=Git repository browser | 52 | #root-title=Git repository browser |
49 | 53 | ||
50 | 54 | ||
51 | ## Link to css file | 55 | ## Link to css file |
52 | #css=/cgit/cgit.css | 56 | #css=/cgit/cgit.css |
53 | 57 | ||
54 | 58 | ||
55 | ## Link to logo file | 59 | ## Link to logo file |
56 | #logo=/cgit/git-logo.png | 60 | #logo=/cgit/git-logo.png |
57 | 61 | ||
58 | 62 | ||
59 | ## Url loaded when clicking the logo | 63 | ## Url loaded when clicking the logo |
60 | #logo-link=http://www.kernel.org/pub/software/scm/git/docs/ | 64 | #logo-link=http://www.kernel.org/pub/software/scm/git/docs/ |
61 | 65 | ||
62 | 66 | ||
63 | ## Url loaded when clicking a submodule link | 67 | ## Url loaded when clicking a submodule link |
64 | #module-link=./?repo=%s&page=commit&id=%s | 68 | #module-link=./?repo=%s&page=commit&id=%s |
65 | 69 | ||
66 | 70 | ||
67 | ## Number of chars shown of repo description (in repolist view) | 71 | ## Number of chars shown of repo description (in repolist view) |
68 | #max-repodesc-length=60 | 72 | #max-repodesc-length=60 |
69 | 73 | ||
70 | 74 | ||
71 | ## Number of chars shown of commit subject message (in log view) | 75 | ## Number of chars shown of commit subject message (in log view) |
72 | #max-message-length=60 | 76 | #max-message-length=60 |
73 | 77 | ||
74 | 78 | ||
75 | ## Number of commits per page in log view | 79 | ## Number of commits per page in log view |
76 | #max-commit-count=50 | 80 | #max-commit-count=50 |
77 | 81 | ||
78 | 82 | ||
79 | ## Root of cached output | 83 | ## Root of cached output |
80 | #cache-root=/var/cache/cgit | 84 | #cache-root=/var/cache/cgit |
81 | 85 | ||
82 | 86 | ||
83 | ## Include another config-file | 87 | ## Include another config-file |
84 | #include=/var/cgit/repolist | 88 | #include=/var/cgit/repolist |
85 | 89 | ||
86 | ## | 90 | ## |
87 | ## Time-To-Live settings: specifies how long (in minutes) different pages | 91 | ## Time-To-Live settings: specifies how long (in minutes) different pages |
88 | ## should be cached (0 for instant expiration, -1 for immortal pages) | 92 | ## should be cached (0 for instant expiration, -1 for immortal pages) |
89 | ## | 93 | ## |
90 | 94 | ||
91 | ## ttl for root page | 95 | ## ttl for root page |
92 | #cache-root-ttl=5 | 96 | #cache-root-ttl=5 |
93 | 97 | ||
94 | ## ttl for repo summary page | 98 | ## ttl for repo summary page |
95 | #cache-repo-ttl=5 | 99 | #cache-repo-ttl=5 |
96 | 100 | ||
97 | ## ttl for other dynamic pages | 101 | ## ttl for other dynamic pages |
98 | #cache-dynamic-ttl=5 | 102 | #cache-dynamic-ttl=5 |
99 | 103 | ||
100 | ## ttl for static pages (addressed by SHA-1) | 104 | ## ttl for static pages (addressed by SHA-1) |
101 | #cache-static-ttl=-1 | 105 | #cache-static-ttl=-1 |
102 | 106 | ||
103 | 107 | ||
104 | 108 | ||
105 | ## Example repository entry. Required values are repo.url and repo.path (each | 109 | ## Example repository entry. Required values are repo.url and repo.path (each |
106 | ## repository section must start with repo.url). | 110 | ## repository section must start with repo.url). |
107 | #repo.url=cgit | 111 | #repo.url=cgit |
108 | #repo.name=cgit | 112 | #repo.name=cgit |
109 | #repo.desc=the caching cgi for git | 113 | #repo.desc=the caching cgi for git |
110 | #repo.path=/pub/git/cgit | 114 | #repo.path=/pub/git/cgit |
111 | #repo.owner=Lars Hjemli | 115 | #repo.owner=Lars Hjemli |
112 | #repo.snapshots=1 # override a sitewide snapshot-setting | 116 | #repo.snapshots=1 # override a sitewide snapshot-setting |
113 | #repo.enable-log-filecount=0 # override the default filecount setting | 117 | #repo.enable-log-filecount=0 # override the default filecount setting |
114 | #repo.enable-log-linecount=0 # override the default linecount setting | 118 | #repo.enable-log-linecount=0 # override the default linecount setting |
115 | #repo.module-link=/git/%s/commit/?id=%s # override the standard module-link | 119 | #repo.module-link=/git/%s/commit/?id=%s # override the standard module-link |
116 | #repo.readme=info/web/readme # specify a file to include on summary page | 120 | #repo.readme=info/web/readme # specify a file to include on summary page |
@@ -1,378 +1,381 @@ | |||
1 | /* shared.c: global vars + some callback functions | 1 | /* shared.c: global vars + some callback functions |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | struct repolist cgit_repolist; | 11 | struct repolist cgit_repolist; |
12 | struct repoinfo *cgit_repo; | 12 | struct repoinfo *cgit_repo; |
13 | int cgit_cmd; | 13 | int cgit_cmd; |
14 | 14 | ||
15 | char *cgit_root_title = "Git repository browser"; | 15 | char *cgit_root_title = "Git repository browser"; |
16 | char *cgit_css = "/cgit.css"; | 16 | char *cgit_css = "/cgit.css"; |
17 | char *cgit_logo = "/git-logo.png"; | 17 | char *cgit_logo = "/git-logo.png"; |
18 | char *cgit_index_header = NULL; | 18 | char *cgit_index_header = NULL; |
19 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; | 19 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; |
20 | char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; | 20 | char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; |
21 | char *cgit_agefile = "info/web/last-modified"; | 21 | char *cgit_agefile = "info/web/last-modified"; |
22 | char *cgit_virtual_root = NULL; | 22 | char *cgit_virtual_root = NULL; |
23 | char *cgit_script_name = CGIT_SCRIPT_NAME; | 23 | char *cgit_script_name = CGIT_SCRIPT_NAME; |
24 | char *cgit_cache_root = "/var/cache/cgit"; | 24 | char *cgit_cache_root = "/var/cache/cgit"; |
25 | char *cgit_repo_group = NULL; | 25 | char *cgit_repo_group = NULL; |
26 | 26 | ||
27 | int cgit_nocache = 0; | 27 | int cgit_nocache = 0; |
28 | int cgit_snapshots = 0; | 28 | int cgit_snapshots = 0; |
29 | int cgit_enable_index_links = 0; | ||
29 | int cgit_enable_log_filecount = 0; | 30 | int cgit_enable_log_filecount = 0; |
30 | int cgit_enable_log_linecount = 0; | 31 | int cgit_enable_log_linecount = 0; |
31 | int cgit_max_lock_attempts = 5; | 32 | int cgit_max_lock_attempts = 5; |
32 | int cgit_cache_root_ttl = 5; | 33 | int cgit_cache_root_ttl = 5; |
33 | int cgit_cache_repo_ttl = 5; | 34 | int cgit_cache_repo_ttl = 5; |
34 | int cgit_cache_dynamic_ttl = 5; | 35 | int cgit_cache_dynamic_ttl = 5; |
35 | int cgit_cache_static_ttl = -1; | 36 | int cgit_cache_static_ttl = -1; |
36 | int cgit_cache_max_create_time = 5; | 37 | int cgit_cache_max_create_time = 5; |
37 | int cgit_summary_log = 0; | 38 | int cgit_summary_log = 0; |
38 | 39 | ||
39 | int cgit_max_msg_len = 60; | 40 | int cgit_max_msg_len = 60; |
40 | int cgit_max_repodesc_len = 60; | 41 | int cgit_max_repodesc_len = 60; |
41 | int cgit_max_commit_count = 50; | 42 | int cgit_max_commit_count = 50; |
42 | 43 | ||
43 | int cgit_query_has_symref = 0; | 44 | int cgit_query_has_symref = 0; |
44 | int cgit_query_has_sha1 = 0; | 45 | int cgit_query_has_sha1 = 0; |
45 | 46 | ||
46 | char *cgit_querystring = NULL; | 47 | char *cgit_querystring = NULL; |
47 | char *cgit_query_repo = NULL; | 48 | char *cgit_query_repo = NULL; |
48 | char *cgit_query_page = NULL; | 49 | char *cgit_query_page = NULL; |
49 | char *cgit_query_head = NULL; | 50 | char *cgit_query_head = NULL; |
50 | char *cgit_query_search = NULL; | 51 | char *cgit_query_search = NULL; |
51 | char *cgit_query_sha1 = NULL; | 52 | char *cgit_query_sha1 = NULL; |
52 | char *cgit_query_sha2 = NULL; | 53 | char *cgit_query_sha2 = NULL; |
53 | char *cgit_query_path = NULL; | 54 | char *cgit_query_path = NULL; |
54 | char *cgit_query_name = NULL; | 55 | char *cgit_query_name = NULL; |
55 | int cgit_query_ofs = 0; | 56 | int cgit_query_ofs = 0; |
56 | 57 | ||
57 | int htmlfd = 0; | 58 | int htmlfd = 0; |
58 | 59 | ||
59 | 60 | ||
60 | int cgit_get_cmd_index(const char *cmd) | 61 | int cgit_get_cmd_index(const char *cmd) |
61 | { | 62 | { |
62 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", | 63 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", |
63 | "snapshot", NULL}; | 64 | "snapshot", NULL}; |
64 | int i; | 65 | int i; |
65 | 66 | ||
66 | for(i = 0; cmds[i]; i++) | 67 | for(i = 0; cmds[i]; i++) |
67 | if (!strcmp(cmd, cmds[i])) | 68 | if (!strcmp(cmd, cmds[i])) |
68 | return i + 1; | 69 | return i + 1; |
69 | return 0; | 70 | return 0; |
70 | } | 71 | } |
71 | 72 | ||
72 | int chk_zero(int result, char *msg) | 73 | int chk_zero(int result, char *msg) |
73 | { | 74 | { |
74 | if (result != 0) | 75 | if (result != 0) |
75 | die("%s: %s", msg, strerror(errno)); | 76 | die("%s: %s", msg, strerror(errno)); |
76 | return result; | 77 | return result; |
77 | } | 78 | } |
78 | 79 | ||
79 | int chk_positive(int result, char *msg) | 80 | int chk_positive(int result, char *msg) |
80 | { | 81 | { |
81 | if (result <= 0) | 82 | if (result <= 0) |
82 | die("%s: %s", msg, strerror(errno)); | 83 | die("%s: %s", msg, strerror(errno)); |
83 | return result; | 84 | return result; |
84 | } | 85 | } |
85 | 86 | ||
86 | struct repoinfo *add_repo(const char *url) | 87 | struct repoinfo *add_repo(const char *url) |
87 | { | 88 | { |
88 | struct repoinfo *ret; | 89 | struct repoinfo *ret; |
89 | 90 | ||
90 | if (++cgit_repolist.count > cgit_repolist.length) { | 91 | if (++cgit_repolist.count > cgit_repolist.length) { |
91 | if (cgit_repolist.length == 0) | 92 | if (cgit_repolist.length == 0) |
92 | cgit_repolist.length = 8; | 93 | cgit_repolist.length = 8; |
93 | else | 94 | else |
94 | cgit_repolist.length *= 2; | 95 | cgit_repolist.length *= 2; |
95 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, | 96 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, |
96 | cgit_repolist.length * | 97 | cgit_repolist.length * |
97 | sizeof(struct repoinfo)); | 98 | sizeof(struct repoinfo)); |
98 | } | 99 | } |
99 | 100 | ||
100 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; | 101 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; |
101 | ret->url = xstrdup(url); | 102 | ret->url = xstrdup(url); |
102 | ret->name = ret->url; | 103 | ret->name = ret->url; |
103 | ret->path = NULL; | 104 | ret->path = NULL; |
104 | ret->desc = NULL; | 105 | ret->desc = NULL; |
105 | ret->owner = NULL; | 106 | ret->owner = NULL; |
106 | ret->group = cgit_repo_group; | 107 | ret->group = cgit_repo_group; |
107 | ret->defbranch = "master"; | 108 | ret->defbranch = "master"; |
108 | ret->snapshots = cgit_snapshots; | 109 | ret->snapshots = cgit_snapshots; |
109 | ret->enable_log_filecount = cgit_enable_log_filecount; | 110 | ret->enable_log_filecount = cgit_enable_log_filecount; |
110 | ret->enable_log_linecount = cgit_enable_log_linecount; | 111 | ret->enable_log_linecount = cgit_enable_log_linecount; |
111 | ret->module_link = cgit_module_link; | 112 | ret->module_link = cgit_module_link; |
112 | ret->readme = NULL; | 113 | ret->readme = NULL; |
113 | return ret; | 114 | return ret; |
114 | } | 115 | } |
115 | 116 | ||
116 | struct repoinfo *cgit_get_repoinfo(const char *url) | 117 | struct repoinfo *cgit_get_repoinfo(const char *url) |
117 | { | 118 | { |
118 | int i; | 119 | int i; |
119 | struct repoinfo *repo; | 120 | struct repoinfo *repo; |
120 | 121 | ||
121 | for (i=0; i<cgit_repolist.count; i++) { | 122 | for (i=0; i<cgit_repolist.count; i++) { |
122 | repo = &cgit_repolist.repos[i]; | 123 | repo = &cgit_repolist.repos[i]; |
123 | if (!strcmp(repo->url, url)) | 124 | if (!strcmp(repo->url, url)) |
124 | return repo; | 125 | return repo; |
125 | } | 126 | } |
126 | return NULL; | 127 | return NULL; |
127 | } | 128 | } |
128 | 129 | ||
129 | void cgit_global_config_cb(const char *name, const char *value) | 130 | void cgit_global_config_cb(const char *name, const char *value) |
130 | { | 131 | { |
131 | if (!strcmp(name, "root-title")) | 132 | if (!strcmp(name, "root-title")) |
132 | cgit_root_title = xstrdup(value); | 133 | cgit_root_title = xstrdup(value); |
133 | else if (!strcmp(name, "css")) | 134 | else if (!strcmp(name, "css")) |
134 | cgit_css = xstrdup(value); | 135 | cgit_css = xstrdup(value); |
135 | else if (!strcmp(name, "logo")) | 136 | else if (!strcmp(name, "logo")) |
136 | cgit_logo = xstrdup(value); | 137 | cgit_logo = xstrdup(value); |
137 | else if (!strcmp(name, "index-header")) | 138 | else if (!strcmp(name, "index-header")) |
138 | cgit_index_header = xstrdup(value); | 139 | cgit_index_header = xstrdup(value); |
139 | else if (!strcmp(name, "logo-link")) | 140 | else if (!strcmp(name, "logo-link")) |
140 | cgit_logo_link = xstrdup(value); | 141 | cgit_logo_link = xstrdup(value); |
141 | else if (!strcmp(name, "module-link")) | 142 | else if (!strcmp(name, "module-link")) |
142 | cgit_module_link = xstrdup(value); | 143 | cgit_module_link = xstrdup(value); |
143 | else if (!strcmp(name, "virtual-root")) | 144 | else if (!strcmp(name, "virtual-root")) |
144 | cgit_virtual_root = xstrdup(value); | 145 | cgit_virtual_root = xstrdup(value); |
145 | else if (!strcmp(name, "nocache")) | 146 | else if (!strcmp(name, "nocache")) |
146 | cgit_nocache = atoi(value); | 147 | cgit_nocache = atoi(value); |
147 | else if (!strcmp(name, "snapshots")) | 148 | else if (!strcmp(name, "snapshots")) |
148 | cgit_snapshots = atoi(value); | 149 | cgit_snapshots = atoi(value); |
150 | else if (!strcmp(name, "enable-index-links")) | ||
151 | cgit_enable_index_links = atoi(value); | ||
149 | else if (!strcmp(name, "enable-log-filecount")) | 152 | else if (!strcmp(name, "enable-log-filecount")) |
150 | cgit_enable_log_filecount = atoi(value); | 153 | cgit_enable_log_filecount = atoi(value); |
151 | else if (!strcmp(name, "enable-log-linecount")) | 154 | else if (!strcmp(name, "enable-log-linecount")) |
152 | cgit_enable_log_linecount = atoi(value); | 155 | cgit_enable_log_linecount = atoi(value); |
153 | else if (!strcmp(name, "cache-root")) | 156 | else if (!strcmp(name, "cache-root")) |
154 | cgit_cache_root = xstrdup(value); | 157 | cgit_cache_root = xstrdup(value); |
155 | else if (!strcmp(name, "cache-root-ttl")) | 158 | else if (!strcmp(name, "cache-root-ttl")) |
156 | cgit_cache_root_ttl = atoi(value); | 159 | cgit_cache_root_ttl = atoi(value); |
157 | else if (!strcmp(name, "cache-repo-ttl")) | 160 | else if (!strcmp(name, "cache-repo-ttl")) |
158 | cgit_cache_repo_ttl = atoi(value); | 161 | cgit_cache_repo_ttl = atoi(value); |
159 | else if (!strcmp(name, "cache-static-ttl")) | 162 | else if (!strcmp(name, "cache-static-ttl")) |
160 | cgit_cache_static_ttl = atoi(value); | 163 | cgit_cache_static_ttl = atoi(value); |
161 | else if (!strcmp(name, "cache-dynamic-ttl")) | 164 | else if (!strcmp(name, "cache-dynamic-ttl")) |
162 | cgit_cache_dynamic_ttl = atoi(value); | 165 | cgit_cache_dynamic_ttl = atoi(value); |
163 | else if (!strcmp(name, "max-message-length")) | 166 | else if (!strcmp(name, "max-message-length")) |
164 | cgit_max_msg_len = atoi(value); | 167 | cgit_max_msg_len = atoi(value); |
165 | else if (!strcmp(name, "max-repodesc-length")) | 168 | else if (!strcmp(name, "max-repodesc-length")) |
166 | cgit_max_repodesc_len = atoi(value); | 169 | cgit_max_repodesc_len = atoi(value); |
167 | else if (!strcmp(name, "max-commit-count")) | 170 | else if (!strcmp(name, "max-commit-count")) |
168 | cgit_max_commit_count = atoi(value); | 171 | cgit_max_commit_count = atoi(value); |
169 | else if (!strcmp(name, "summary-log")) | 172 | else if (!strcmp(name, "summary-log")) |
170 | cgit_summary_log = atoi(value); | 173 | cgit_summary_log = atoi(value); |
171 | else if (!strcmp(name, "agefile")) | 174 | else if (!strcmp(name, "agefile")) |
172 | cgit_agefile = xstrdup(value); | 175 | cgit_agefile = xstrdup(value); |
173 | else if (!strcmp(name, "repo.group")) | 176 | else if (!strcmp(name, "repo.group")) |
174 | cgit_repo_group = xstrdup(value); | 177 | cgit_repo_group = xstrdup(value); |
175 | else if (!strcmp(name, "repo.url")) | 178 | else if (!strcmp(name, "repo.url")) |
176 | cgit_repo = add_repo(value); | 179 | cgit_repo = add_repo(value); |
177 | else if (!strcmp(name, "repo.name")) | 180 | else if (!strcmp(name, "repo.name")) |
178 | cgit_repo->name = xstrdup(value); | 181 | cgit_repo->name = xstrdup(value); |
179 | else if (cgit_repo && !strcmp(name, "repo.path")) | 182 | else if (cgit_repo && !strcmp(name, "repo.path")) |
180 | cgit_repo->path = xstrdup(value); | 183 | cgit_repo->path = xstrdup(value); |
181 | else if (cgit_repo && !strcmp(name, "repo.desc")) | 184 | else if (cgit_repo && !strcmp(name, "repo.desc")) |
182 | cgit_repo->desc = xstrdup(value); | 185 | cgit_repo->desc = xstrdup(value); |
183 | else if (cgit_repo && !strcmp(name, "repo.owner")) | 186 | else if (cgit_repo && !strcmp(name, "repo.owner")) |
184 | cgit_repo->owner = xstrdup(value); | 187 | cgit_repo->owner = xstrdup(value); |
185 | else if (cgit_repo && !strcmp(name, "repo.defbranch")) | 188 | else if (cgit_repo && !strcmp(name, "repo.defbranch")) |
186 | cgit_repo->defbranch = xstrdup(value); | 189 | cgit_repo->defbranch = xstrdup(value); |
187 | else if (cgit_repo && !strcmp(name, "repo.snapshots")) | 190 | else if (cgit_repo && !strcmp(name, "repo.snapshots")) |
188 | cgit_repo->snapshots = cgit_snapshots * atoi(value); | 191 | cgit_repo->snapshots = cgit_snapshots * atoi(value); |
189 | else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount")) | 192 | else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount")) |
190 | cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value); | 193 | cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value); |
191 | else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount")) | 194 | else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount")) |
192 | cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value); | 195 | cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value); |
193 | else if (cgit_repo && !strcmp(name, "repo.module-link")) | 196 | else if (cgit_repo && !strcmp(name, "repo.module-link")) |
194 | cgit_repo->module_link= xstrdup(value); | 197 | cgit_repo->module_link= xstrdup(value); |
195 | else if (cgit_repo && !strcmp(name, "repo.readme") && value != NULL) { | 198 | else if (cgit_repo && !strcmp(name, "repo.readme") && value != NULL) { |
196 | if (*value == '/') | 199 | if (*value == '/') |
197 | cgit_repo->readme = xstrdup(value); | 200 | cgit_repo->readme = xstrdup(value); |
198 | else | 201 | else |
199 | cgit_repo->readme = xstrdup(fmt("%s/%s", cgit_repo->path, value)); | 202 | cgit_repo->readme = xstrdup(fmt("%s/%s", cgit_repo->path, value)); |
200 | } else if (!strcmp(name, "include")) | 203 | } else if (!strcmp(name, "include")) |
201 | cgit_read_config(value, cgit_global_config_cb); | 204 | cgit_read_config(value, cgit_global_config_cb); |
202 | } | 205 | } |
203 | 206 | ||
204 | void cgit_querystring_cb(const char *name, const char *value) | 207 | void cgit_querystring_cb(const char *name, const char *value) |
205 | { | 208 | { |
206 | if (!strcmp(name,"r")) { | 209 | if (!strcmp(name,"r")) { |
207 | cgit_query_repo = xstrdup(value); | 210 | cgit_query_repo = xstrdup(value); |
208 | cgit_repo = cgit_get_repoinfo(value); | 211 | cgit_repo = cgit_get_repoinfo(value); |
209 | } else if (!strcmp(name, "p")) { | 212 | } else if (!strcmp(name, "p")) { |
210 | cgit_query_page = xstrdup(value); | 213 | cgit_query_page = xstrdup(value); |
211 | cgit_cmd = cgit_get_cmd_index(value); | 214 | cgit_cmd = cgit_get_cmd_index(value); |
212 | } else if (!strcmp(name, "url")) { | 215 | } else if (!strcmp(name, "url")) { |
213 | cgit_parse_url(value); | 216 | cgit_parse_url(value); |
214 | } else if (!strcmp(name, "q")) { | 217 | } else if (!strcmp(name, "q")) { |
215 | cgit_query_search = xstrdup(value); | 218 | cgit_query_search = xstrdup(value); |
216 | } else if (!strcmp(name, "h")) { | 219 | } else if (!strcmp(name, "h")) { |
217 | cgit_query_head = xstrdup(value); | 220 | cgit_query_head = xstrdup(value); |
218 | cgit_query_has_symref = 1; | 221 | cgit_query_has_symref = 1; |
219 | } else if (!strcmp(name, "id")) { | 222 | } else if (!strcmp(name, "id")) { |
220 | cgit_query_sha1 = xstrdup(value); | 223 | cgit_query_sha1 = xstrdup(value); |
221 | cgit_query_has_sha1 = 1; | 224 | cgit_query_has_sha1 = 1; |
222 | } else if (!strcmp(name, "id2")) { | 225 | } else if (!strcmp(name, "id2")) { |
223 | cgit_query_sha2 = xstrdup(value); | 226 | cgit_query_sha2 = xstrdup(value); |
224 | cgit_query_has_sha1 = 1; | 227 | cgit_query_has_sha1 = 1; |
225 | } else if (!strcmp(name, "ofs")) { | 228 | } else if (!strcmp(name, "ofs")) { |
226 | cgit_query_ofs = atoi(value); | 229 | cgit_query_ofs = atoi(value); |
227 | } else if (!strcmp(name, "path")) { | 230 | } else if (!strcmp(name, "path")) { |
228 | cgit_query_path = xstrdup(value); | 231 | cgit_query_path = xstrdup(value); |
229 | } else if (!strcmp(name, "name")) { | 232 | } else if (!strcmp(name, "name")) { |
230 | cgit_query_name = xstrdup(value); | 233 | cgit_query_name = xstrdup(value); |
231 | } | 234 | } |
232 | } | 235 | } |
233 | 236 | ||
234 | void *cgit_free_commitinfo(struct commitinfo *info) | 237 | void *cgit_free_commitinfo(struct commitinfo *info) |
235 | { | 238 | { |
236 | free(info->author); | 239 | free(info->author); |
237 | free(info->author_email); | 240 | free(info->author_email); |
238 | free(info->committer); | 241 | free(info->committer); |
239 | free(info->committer_email); | 242 | free(info->committer_email); |
240 | free(info->subject); | 243 | free(info->subject); |
241 | free(info); | 244 | free(info); |
242 | return NULL; | 245 | return NULL; |
243 | } | 246 | } |
244 | 247 | ||
245 | int hextoint(char c) | 248 | int hextoint(char c) |
246 | { | 249 | { |
247 | if (c >= 'a' && c <= 'f') | 250 | if (c >= 'a' && c <= 'f') |
248 | return 10 + c - 'a'; | 251 | return 10 + c - 'a'; |
249 | else if (c >= 'A' && c <= 'F') | 252 | else if (c >= 'A' && c <= 'F') |
250 | return 10 + c - 'A'; | 253 | return 10 + c - 'A'; |
251 | else if (c >= '0' && c <= '9') | 254 | else if (c >= '0' && c <= '9') |
252 | return c - '0'; | 255 | return c - '0'; |
253 | else | 256 | else |
254 | return -1; | 257 | return -1; |
255 | } | 258 | } |
256 | 259 | ||
257 | void cgit_diff_tree_cb(struct diff_queue_struct *q, | 260 | void cgit_diff_tree_cb(struct diff_queue_struct *q, |
258 | struct diff_options *options, void *data) | 261 | struct diff_options *options, void *data) |
259 | { | 262 | { |
260 | int i; | 263 | int i; |
261 | 264 | ||
262 | for (i = 0; i < q->nr; i++) { | 265 | for (i = 0; i < q->nr; i++) { |
263 | if (q->queue[i]->status == 'U') | 266 | if (q->queue[i]->status == 'U') |
264 | continue; | 267 | continue; |
265 | ((filepair_fn)data)(q->queue[i]); | 268 | ((filepair_fn)data)(q->queue[i]); |
266 | } | 269 | } |
267 | } | 270 | } |
268 | 271 | ||
269 | static int load_mmfile(mmfile_t *file, const unsigned char *sha1) | 272 | static int load_mmfile(mmfile_t *file, const unsigned char *sha1) |
270 | { | 273 | { |
271 | enum object_type type; | 274 | enum object_type type; |
272 | 275 | ||
273 | if (is_null_sha1(sha1)) { | 276 | if (is_null_sha1(sha1)) { |
274 | file->ptr = (char *)""; | 277 | file->ptr = (char *)""; |
275 | file->size = 0; | 278 | file->size = 0; |
276 | } else { | 279 | } else { |
277 | file->ptr = read_sha1_file(sha1, &type, &file->size); | 280 | file->ptr = read_sha1_file(sha1, &type, &file->size); |
278 | } | 281 | } |
279 | return 1; | 282 | return 1; |
280 | } | 283 | } |
281 | 284 | ||
282 | /* | 285 | /* |
283 | * Receive diff-buffers from xdiff and concatenate them as | 286 | * Receive diff-buffers from xdiff and concatenate them as |
284 | * needed across multiple callbacks. | 287 | * needed across multiple callbacks. |
285 | * | 288 | * |
286 | * This is basically a copy of xdiff-interface.c/xdiff_outf(), | 289 | * This is basically a copy of xdiff-interface.c/xdiff_outf(), |
287 | * ripped from git and modified to use globals instead of | 290 | * ripped from git and modified to use globals instead of |
288 | * a special callback-struct. | 291 | * a special callback-struct. |
289 | */ | 292 | */ |
290 | char *diffbuf = NULL; | 293 | char *diffbuf = NULL; |
291 | int buflen = 0; | 294 | int buflen = 0; |
292 | 295 | ||
293 | int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf) | 296 | int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf) |
294 | { | 297 | { |
295 | int i; | 298 | int i; |
296 | 299 | ||
297 | for (i = 0; i < nbuf; i++) { | 300 | for (i = 0; i < nbuf; i++) { |
298 | if (mb[i].ptr[mb[i].size-1] != '\n') { | 301 | if (mb[i].ptr[mb[i].size-1] != '\n') { |
299 | /* Incomplete line */ | 302 | /* Incomplete line */ |
300 | diffbuf = xrealloc(diffbuf, buflen + mb[i].size); | 303 | diffbuf = xrealloc(diffbuf, buflen + mb[i].size); |
301 | memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); | 304 | memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); |
302 | buflen += mb[i].size; | 305 | buflen += mb[i].size; |
303 | continue; | 306 | continue; |
304 | } | 307 | } |
305 | 308 | ||
306 | /* we have a complete line */ | 309 | /* we have a complete line */ |
307 | if (!diffbuf) { | 310 | if (!diffbuf) { |
308 | ((linediff_fn)priv)(mb[i].ptr, mb[i].size); | 311 | ((linediff_fn)priv)(mb[i].ptr, mb[i].size); |
309 | continue; | 312 | continue; |
310 | } | 313 | } |
311 | diffbuf = xrealloc(diffbuf, buflen + mb[i].size); | 314 | diffbuf = xrealloc(diffbuf, buflen + mb[i].size); |
312 | memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); | 315 | memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); |
313 | ((linediff_fn)priv)(diffbuf, buflen + mb[i].size); | 316 | ((linediff_fn)priv)(diffbuf, buflen + mb[i].size); |
314 | free(diffbuf); | 317 | free(diffbuf); |
315 | diffbuf = NULL; | 318 | diffbuf = NULL; |
316 | buflen = 0; | 319 | buflen = 0; |
317 | } | 320 | } |
318 | if (diffbuf) { | 321 | if (diffbuf) { |
319 | ((linediff_fn)priv)(diffbuf, buflen); | 322 | ((linediff_fn)priv)(diffbuf, buflen); |
320 | free(diffbuf); | 323 | free(diffbuf); |
321 | diffbuf = NULL; | 324 | diffbuf = NULL; |
322 | buflen = 0; | 325 | buflen = 0; |
323 | } | 326 | } |
324 | return 0; | 327 | return 0; |
325 | } | 328 | } |
326 | 329 | ||
327 | int cgit_diff_files(const unsigned char *old_sha1, | 330 | int cgit_diff_files(const unsigned char *old_sha1, |
328 | const unsigned char *new_sha1, | 331 | const unsigned char *new_sha1, |
329 | linediff_fn fn) | 332 | linediff_fn fn) |
330 | { | 333 | { |
331 | mmfile_t file1, file2; | 334 | mmfile_t file1, file2; |
332 | xpparam_t diff_params; | 335 | xpparam_t diff_params; |
333 | xdemitconf_t emit_params; | 336 | xdemitconf_t emit_params; |
334 | xdemitcb_t emit_cb; | 337 | xdemitcb_t emit_cb; |
335 | 338 | ||
336 | if (!load_mmfile(&file1, old_sha1) || !load_mmfile(&file2, new_sha1)) | 339 | if (!load_mmfile(&file1, old_sha1) || !load_mmfile(&file2, new_sha1)) |
337 | return 1; | 340 | return 1; |
338 | 341 | ||
339 | diff_params.flags = XDF_NEED_MINIMAL; | 342 | diff_params.flags = XDF_NEED_MINIMAL; |
340 | emit_params.ctxlen = 3; | 343 | emit_params.ctxlen = 3; |
341 | emit_params.flags = XDL_EMIT_FUNCNAMES; | 344 | emit_params.flags = XDL_EMIT_FUNCNAMES; |
342 | emit_cb.outf = filediff_cb; | 345 | emit_cb.outf = filediff_cb; |
343 | emit_cb.priv = fn; | 346 | emit_cb.priv = fn; |
344 | xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); | 347 | xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); |
345 | return 0; | 348 | return 0; |
346 | } | 349 | } |
347 | 350 | ||
348 | void cgit_diff_tree(const unsigned char *old_sha1, | 351 | void cgit_diff_tree(const unsigned char *old_sha1, |
349 | const unsigned char *new_sha1, | 352 | const unsigned char *new_sha1, |
350 | filepair_fn fn) | 353 | filepair_fn fn) |
351 | { | 354 | { |
352 | struct diff_options opt; | 355 | struct diff_options opt; |
353 | int ret; | 356 | int ret; |
354 | 357 | ||
355 | diff_setup(&opt); | 358 | diff_setup(&opt); |
356 | opt.output_format = DIFF_FORMAT_CALLBACK; | 359 | opt.output_format = DIFF_FORMAT_CALLBACK; |
357 | opt.detect_rename = 1; | 360 | opt.detect_rename = 1; |
358 | opt.recursive = 1; | 361 | opt.recursive = 1; |
359 | opt.format_callback = cgit_diff_tree_cb; | 362 | opt.format_callback = cgit_diff_tree_cb; |
360 | opt.format_callback_data = fn; | 363 | opt.format_callback_data = fn; |
361 | diff_setup_done(&opt); | 364 | diff_setup_done(&opt); |
362 | 365 | ||
363 | if (old_sha1 && !is_null_sha1(old_sha1)) | 366 | if (old_sha1 && !is_null_sha1(old_sha1)) |
364 | ret = diff_tree_sha1(old_sha1, new_sha1, "", &opt); | 367 | ret = diff_tree_sha1(old_sha1, new_sha1, "", &opt); |
365 | else | 368 | else |
366 | ret = diff_root_tree_sha1(new_sha1, "", &opt); | 369 | ret = diff_root_tree_sha1(new_sha1, "", &opt); |
367 | diffcore_std(&opt); | 370 | diffcore_std(&opt); |
368 | diff_flush(&opt); | 371 | diff_flush(&opt); |
369 | } | 372 | } |
370 | 373 | ||
371 | void cgit_diff_commit(struct commit *commit, filepair_fn fn) | 374 | void cgit_diff_commit(struct commit *commit, filepair_fn fn) |
372 | { | 375 | { |
373 | unsigned char *old_sha1 = NULL; | 376 | unsigned char *old_sha1 = NULL; |
374 | 377 | ||
375 | if (commit->parents) | 378 | if (commit->parents) |
376 | old_sha1 = commit->parents->item->object.sha1; | 379 | old_sha1 = commit->parents->item->object.sha1; |
377 | cgit_diff_tree(old_sha1, commit->object.sha1, fn); | 380 | cgit_diff_tree(old_sha1, commit->object.sha1, fn); |
378 | } | 381 | } |
diff --git a/ui-repolist.c b/ui-repolist.c index 4f820a8..c735368 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
@@ -1,98 +1,109 @@ | |||
1 | /* ui-repolist.c: functions for generating the repolist page | 1 | /* ui-repolist.c: functions for generating the repolist page |
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 | #include <time.h> | 10 | #include <time.h> |
11 | 11 | ||
12 | 12 | ||
13 | time_t read_agefile(char *path) | 13 | time_t read_agefile(char *path) |
14 | { | 14 | { |
15 | FILE *f; | 15 | FILE *f; |
16 | static char buf[64], buf2[64]; | 16 | static char buf[64], buf2[64]; |
17 | 17 | ||
18 | if (!(f = fopen(path, "r"))) | 18 | if (!(f = fopen(path, "r"))) |
19 | return -1; | 19 | return -1; |
20 | fgets(buf, sizeof(buf), f); | 20 | fgets(buf, sizeof(buf), f); |
21 | fclose(f); | 21 | fclose(f); |
22 | if (parse_date(buf, buf2, sizeof(buf2))) | 22 | if (parse_date(buf, buf2, sizeof(buf2))) |
23 | return strtoul(buf2, NULL, 10); | 23 | return strtoul(buf2, NULL, 10); |
24 | else | 24 | else |
25 | return 0; | 25 | return 0; |
26 | } | 26 | } |
27 | 27 | ||
28 | static void print_modtime(struct repoinfo *repo) | 28 | static void print_modtime(struct repoinfo *repo) |
29 | { | 29 | { |
30 | char *path; | 30 | char *path; |
31 | struct stat s; | 31 | struct stat s; |
32 | 32 | ||
33 | path = fmt("%s/%s", repo->path, cgit_agefile); | 33 | path = fmt("%s/%s", repo->path, cgit_agefile); |
34 | if (stat(path, &s) == 0) { | 34 | if (stat(path, &s) == 0) { |
35 | cgit_print_age(read_agefile(path), -1, NULL); | 35 | cgit_print_age(read_agefile(path), -1, NULL); |
36 | return; | 36 | return; |
37 | } | 37 | } |
38 | 38 | ||
39 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); | 39 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); |
40 | if (stat(path, &s) != 0) | 40 | if (stat(path, &s) != 0) |
41 | return; | 41 | return; |
42 | cgit_print_age(s.st_mtime, -1, NULL); | 42 | cgit_print_age(s.st_mtime, -1, NULL); |
43 | } | 43 | } |
44 | 44 | ||
45 | void cgit_print_repolist(struct cacheitem *item) | 45 | void cgit_print_repolist(struct cacheitem *item) |
46 | { | 46 | { |
47 | int i; | 47 | int i, columns = 4; |
48 | char *last_group = NULL; | 48 | char *last_group = NULL; |
49 | 49 | ||
50 | if (cgit_enable_index_links) | ||
51 | columns++; | ||
52 | |||
50 | cgit_print_docstart(cgit_root_title, item); | 53 | cgit_print_docstart(cgit_root_title, item); |
51 | cgit_print_pageheader(cgit_root_title, 0); | 54 | cgit_print_pageheader(cgit_root_title, 0); |
52 | 55 | ||
53 | html("<table class='list nowrap'>"); | 56 | html("<table class='list nowrap'>"); |
54 | if (cgit_index_header) { | 57 | if (cgit_index_header) { |
55 | html("<tr class='nohover'><td colspan='5' class='include-block'>"); | 58 | htmlf("<tr class='nohover'><td colspan='%d' class='include-block'>", |
59 | columns); | ||
56 | html_include(cgit_index_header); | 60 | html_include(cgit_index_header); |
57 | html("</td></tr>"); | 61 | html("</td></tr>"); |
58 | } | 62 | } |
59 | html("<tr class='nohover'>" | 63 | html("<tr class='nohover'>" |
60 | "<th class='left'>Name</th>" | 64 | "<th class='left'>Name</th>" |
61 | "<th class='left'>Description</th>" | 65 | "<th class='left'>Description</th>" |
62 | "<th class='left'>Owner</th>" | 66 | "<th class='left'>Owner</th>" |
63 | "<th class='left'>Idle</th>" | 67 | "<th class='left'>Idle</th>"); |
64 | "<th>Links</th></tr>\n"); | 68 | if (cgit_enable_index_links) |
69 | html("<th>Links</th>"); | ||
70 | html("</tr>\n"); | ||
65 | 71 | ||
66 | for (i=0; i<cgit_repolist.count; i++) { | 72 | for (i=0; i<cgit_repolist.count; i++) { |
67 | cgit_repo = &cgit_repolist.repos[i]; | 73 | cgit_repo = &cgit_repolist.repos[i]; |
68 | if ((last_group == NULL && cgit_repo->group != NULL) || | 74 | if ((last_group == NULL && cgit_repo->group != NULL) || |
69 | (last_group != NULL && cgit_repo->group == NULL) || | 75 | (last_group != NULL && cgit_repo->group == NULL) || |
70 | (last_group != NULL && cgit_repo->group != NULL && | 76 | (last_group != NULL && cgit_repo->group != NULL && |
71 | strcmp(cgit_repo->group, last_group))) { | 77 | strcmp(cgit_repo->group, last_group))) { |
72 | html("<tr class='nohover'><td colspan='4' class='repogroup'>"); | 78 | htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", |
79 | columns); | ||
73 | html_txt(cgit_repo->group); | 80 | html_txt(cgit_repo->group); |
74 | html("</td></tr>"); | 81 | html("</td></tr>"); |
75 | last_group = cgit_repo->group; | 82 | last_group = cgit_repo->group; |
76 | } | 83 | } |
77 | htmlf("<tr><td class='%s'>", | 84 | htmlf("<tr><td class='%s'>", |
78 | cgit_repo->group ? "sublevel-repo" : "toplevel-repo"); | 85 | cgit_repo->group ? "sublevel-repo" : "toplevel-repo"); |
79 | html_link_open(cgit_repourl(cgit_repo->url), NULL, NULL); | 86 | html_link_open(cgit_repourl(cgit_repo->url), NULL, NULL); |
80 | html_txt(cgit_repo->name); | 87 | html_txt(cgit_repo->name); |
81 | html_link_close(); | 88 | html_link_close(); |
82 | html("</td><td>"); | 89 | html("</td><td>"); |
83 | html_ntxt(cgit_max_repodesc_len, cgit_repo->desc); | 90 | html_ntxt(cgit_max_repodesc_len, cgit_repo->desc); |
84 | html("</td><td>"); | 91 | html("</td><td>"); |
85 | html_txt(cgit_repo->owner); | 92 | html_txt(cgit_repo->owner); |
86 | html("</td><td>"); | 93 | html("</td><td>"); |
87 | print_modtime(cgit_repo); | 94 | print_modtime(cgit_repo); |
88 | html("</td><td>"); | 95 | html("</td>"); |
89 | html_link_open(cgit_repourl(cgit_repo->url), | 96 | if (cgit_enable_index_links) { |
90 | NULL, "button"); | 97 | html("<td>"); |
91 | html("summary</a>"); | 98 | html_link_open(cgit_repourl(cgit_repo->url), |
92 | cgit_log_link("log", NULL, "button", NULL, NULL, NULL); | 99 | NULL, "button"); |
93 | cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); | 100 | html("summary</a>"); |
94 | html("</td></tr>\n"); | 101 | cgit_log_link("log", NULL, "button", NULL, NULL, NULL); |
102 | cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); | ||
103 | html("</td>"); | ||
104 | } | ||
105 | html("</tr>\n"); | ||
95 | } | 106 | } |
96 | html("</table>"); | 107 | html("</table>"); |
97 | cgit_print_docend(); | 108 | cgit_print_docend(); |
98 | } | 109 | } |