author | Lars Hjemli <hjemli@gmail.com> | 2007-10-27 08:47:44 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-10-27 08:53:28 (UTC) |
commit | ac1f493b6bbc589327e9ba3303f112fcd323c6b6 (patch) (unidiff) | |
tree | 4729ecc84e0b24b044131546ff39bdd55a6cd9a6 | |
parent | 7937d06090dd5e19145ec6fa8befc5770954b30c (diff) | |
download | cgit-ac1f493b6bbc589327e9ba3303f112fcd323c6b6.zip cgit-ac1f493b6bbc589327e9ba3303f112fcd323c6b6.tar.gz cgit-ac1f493b6bbc589327e9ba3303f112fcd323c6b6.tar.bz2 |
Add links to the new refs page from summary page
If either branches or tags are filtered on the summary page, add a link to
refs/heads and/or refs/tags right below the last branch/tag.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | ui-shared.c | 6 | ||||
-rw-r--r-- | ui-summary.c | 13 |
3 files changed, 21 insertions, 0 deletions
@@ -47,228 +47,230 @@ | |||
47 | #define TM_YEAR (TM_DAY * 365) | 47 | #define TM_YEAR (TM_DAY * 365) |
48 | #define TM_MONTH (TM_YEAR / 12.0) | 48 | #define TM_MONTH (TM_YEAR / 12.0) |
49 | 49 | ||
50 | 50 | ||
51 | typedef void (*configfn)(const char *name, const char *value); | 51 | typedef void (*configfn)(const char *name, const char *value); |
52 | typedef void (*filepair_fn)(struct diff_filepair *pair); | 52 | typedef void (*filepair_fn)(struct diff_filepair *pair); |
53 | typedef void (*linediff_fn)(char *line, int len); | 53 | typedef void (*linediff_fn)(char *line, int len); |
54 | 54 | ||
55 | struct cacheitem { | 55 | struct cacheitem { |
56 | char *name; | 56 | char *name; |
57 | struct stat st; | 57 | struct stat st; |
58 | int ttl; | 58 | int ttl; |
59 | int fd; | 59 | int fd; |
60 | }; | 60 | }; |
61 | 61 | ||
62 | struct repoinfo { | 62 | struct repoinfo { |
63 | char *url; | 63 | char *url; |
64 | char *name; | 64 | char *name; |
65 | char *path; | 65 | char *path; |
66 | char *desc; | 66 | char *desc; |
67 | char *owner; | 67 | char *owner; |
68 | char *defbranch; | 68 | char *defbranch; |
69 | char *group; | 69 | char *group; |
70 | char *module_link; | 70 | char *module_link; |
71 | char *readme; | 71 | char *readme; |
72 | int snapshots; | 72 | int snapshots; |
73 | int enable_log_filecount; | 73 | int enable_log_filecount; |
74 | int enable_log_linecount; | 74 | int enable_log_linecount; |
75 | }; | 75 | }; |
76 | 76 | ||
77 | struct repolist { | 77 | struct repolist { |
78 | int length; | 78 | int length; |
79 | int count; | 79 | int count; |
80 | struct repoinfo *repos; | 80 | struct repoinfo *repos; |
81 | }; | 81 | }; |
82 | 82 | ||
83 | struct commitinfo { | 83 | struct commitinfo { |
84 | struct commit *commit; | 84 | struct commit *commit; |
85 | char *author; | 85 | char *author; |
86 | char *author_email; | 86 | char *author_email; |
87 | unsigned long author_date; | 87 | unsigned long author_date; |
88 | char *committer; | 88 | char *committer; |
89 | char *committer_email; | 89 | char *committer_email; |
90 | unsigned long committer_date; | 90 | unsigned long committer_date; |
91 | char *subject; | 91 | char *subject; |
92 | char *msg; | 92 | char *msg; |
93 | }; | 93 | }; |
94 | 94 | ||
95 | struct taginfo { | 95 | struct taginfo { |
96 | char *tagger; | 96 | char *tagger; |
97 | char *tagger_email; | 97 | char *tagger_email; |
98 | int tagger_date; | 98 | int tagger_date; |
99 | char *msg; | 99 | char *msg; |
100 | }; | 100 | }; |
101 | 101 | ||
102 | struct refinfo { | 102 | struct refinfo { |
103 | const char *refname; | 103 | const char *refname; |
104 | struct object *object; | 104 | struct object *object; |
105 | union { | 105 | union { |
106 | struct taginfo *tag; | 106 | struct taginfo *tag; |
107 | struct commitinfo *commit; | 107 | struct commitinfo *commit; |
108 | }; | 108 | }; |
109 | }; | 109 | }; |
110 | 110 | ||
111 | struct reflist { | 111 | struct reflist { |
112 | struct refinfo **refs; | 112 | struct refinfo **refs; |
113 | int alloc; | 113 | int alloc; |
114 | int count; | 114 | int count; |
115 | }; | 115 | }; |
116 | 116 | ||
117 | extern const char *cgit_version; | 117 | extern const char *cgit_version; |
118 | 118 | ||
119 | extern struct repolist cgit_repolist; | 119 | extern struct repolist cgit_repolist; |
120 | extern struct repoinfo *cgit_repo; | 120 | extern struct repoinfo *cgit_repo; |
121 | extern int cgit_cmd; | 121 | extern int cgit_cmd; |
122 | 122 | ||
123 | extern char *cgit_root_title; | 123 | extern char *cgit_root_title; |
124 | extern char *cgit_css; | 124 | extern char *cgit_css; |
125 | extern char *cgit_logo; | 125 | extern char *cgit_logo; |
126 | extern char *cgit_index_header; | 126 | extern char *cgit_index_header; |
127 | extern char *cgit_logo_link; | 127 | extern char *cgit_logo_link; |
128 | extern char *cgit_module_link; | 128 | extern char *cgit_module_link; |
129 | extern char *cgit_agefile; | 129 | extern char *cgit_agefile; |
130 | extern char *cgit_virtual_root; | 130 | extern char *cgit_virtual_root; |
131 | extern char *cgit_script_name; | 131 | extern char *cgit_script_name; |
132 | extern char *cgit_cache_root; | 132 | extern char *cgit_cache_root; |
133 | extern char *cgit_repo_group; | 133 | extern char *cgit_repo_group; |
134 | 134 | ||
135 | extern int cgit_nocache; | 135 | extern int cgit_nocache; |
136 | extern int cgit_snapshots; | 136 | extern int cgit_snapshots; |
137 | extern int cgit_enable_index_links; | 137 | extern int cgit_enable_index_links; |
138 | extern int cgit_enable_log_filecount; | 138 | extern int cgit_enable_log_filecount; |
139 | extern int cgit_enable_log_linecount; | 139 | extern int cgit_enable_log_linecount; |
140 | extern int cgit_max_lock_attempts; | 140 | extern int cgit_max_lock_attempts; |
141 | extern int cgit_cache_root_ttl; | 141 | extern int cgit_cache_root_ttl; |
142 | extern int cgit_cache_repo_ttl; | 142 | extern int cgit_cache_repo_ttl; |
143 | extern int cgit_cache_dynamic_ttl; | 143 | extern int cgit_cache_dynamic_ttl; |
144 | extern int cgit_cache_static_ttl; | 144 | extern int cgit_cache_static_ttl; |
145 | extern int cgit_cache_max_create_time; | 145 | extern int cgit_cache_max_create_time; |
146 | extern int cgit_summary_log; | 146 | extern int cgit_summary_log; |
147 | extern int cgit_summary_tags; | 147 | extern int cgit_summary_tags; |
148 | extern int cgit_summary_branches; | 148 | extern int cgit_summary_branches; |
149 | 149 | ||
150 | extern int cgit_max_msg_len; | 150 | extern int cgit_max_msg_len; |
151 | extern int cgit_max_repodesc_len; | 151 | extern int cgit_max_repodesc_len; |
152 | extern int cgit_max_commit_count; | 152 | extern int cgit_max_commit_count; |
153 | 153 | ||
154 | extern int cgit_query_has_symref; | 154 | extern int cgit_query_has_symref; |
155 | extern int cgit_query_has_sha1; | 155 | extern int cgit_query_has_sha1; |
156 | 156 | ||
157 | extern char *cgit_querystring; | 157 | extern char *cgit_querystring; |
158 | extern char *cgit_query_repo; | 158 | extern char *cgit_query_repo; |
159 | extern char *cgit_query_page; | 159 | extern char *cgit_query_page; |
160 | extern char *cgit_query_search; | 160 | extern char *cgit_query_search; |
161 | extern char *cgit_query_head; | 161 | extern char *cgit_query_head; |
162 | extern char *cgit_query_sha1; | 162 | extern char *cgit_query_sha1; |
163 | extern char *cgit_query_sha2; | 163 | extern char *cgit_query_sha2; |
164 | extern char *cgit_query_path; | 164 | extern char *cgit_query_path; |
165 | extern char *cgit_query_name; | 165 | extern char *cgit_query_name; |
166 | extern int cgit_query_ofs; | 166 | extern int cgit_query_ofs; |
167 | 167 | ||
168 | extern int htmlfd; | 168 | extern int htmlfd; |
169 | 169 | ||
170 | extern int cgit_get_cmd_index(const char *cmd); | 170 | extern int cgit_get_cmd_index(const char *cmd); |
171 | extern struct repoinfo *cgit_get_repoinfo(const char *url); | 171 | extern struct repoinfo *cgit_get_repoinfo(const char *url); |
172 | extern void cgit_global_config_cb(const char *name, const char *value); | 172 | extern void cgit_global_config_cb(const char *name, const char *value); |
173 | extern void cgit_repo_config_cb(const char *name, const char *value); | 173 | extern void cgit_repo_config_cb(const char *name, const char *value); |
174 | extern void cgit_querystring_cb(const char *name, const char *value); | 174 | extern void cgit_querystring_cb(const char *name, const char *value); |
175 | 175 | ||
176 | extern int chk_zero(int result, char *msg); | 176 | extern int chk_zero(int result, char *msg); |
177 | extern int chk_positive(int result, char *msg); | 177 | extern int chk_positive(int result, char *msg); |
178 | extern int chk_non_negative(int result, char *msg); | 178 | extern int chk_non_negative(int result, char *msg); |
179 | 179 | ||
180 | extern int hextoint(char c); | 180 | extern int hextoint(char c); |
181 | extern char *trim_end(const char *str, char c); | 181 | extern char *trim_end(const char *str, char c); |
182 | 182 | ||
183 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); | 183 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); |
184 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, | 184 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, |
185 | int flags, void *cb_data); | 185 | int flags, void *cb_data); |
186 | 186 | ||
187 | extern void *cgit_free_commitinfo(struct commitinfo *info); | 187 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
188 | 188 | ||
189 | extern int cgit_diff_files(const unsigned char *old_sha1, | 189 | extern int cgit_diff_files(const unsigned char *old_sha1, |
190 | const unsigned char *new_sha1, | 190 | const unsigned char *new_sha1, |
191 | linediff_fn fn); | 191 | linediff_fn fn); |
192 | 192 | ||
193 | extern void cgit_diff_tree(const unsigned char *old_sha1, | 193 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
194 | const unsigned char *new_sha1, | 194 | const unsigned char *new_sha1, |
195 | filepair_fn fn, const char *prefix); | 195 | filepair_fn fn, const char *prefix); |
196 | 196 | ||
197 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); | 197 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
198 | 198 | ||
199 | extern char *fmt(const char *format,...); | 199 | extern char *fmt(const char *format,...); |
200 | 200 | ||
201 | extern void html(const char *txt); | 201 | extern void html(const char *txt); |
202 | extern void htmlf(const char *format,...); | 202 | extern void htmlf(const char *format,...); |
203 | extern void html_txt(char *txt); | 203 | extern void html_txt(char *txt); |
204 | extern void html_ntxt(int len, char *txt); | 204 | extern void html_ntxt(int len, char *txt); |
205 | extern void html_attr(char *txt); | 205 | extern void html_attr(char *txt); |
206 | extern void html_hidden(char *name, char *value); | 206 | extern void html_hidden(char *name, char *value); |
207 | extern void html_link_open(char *url, char *title, char *class); | 207 | extern void html_link_open(char *url, char *title, char *class); |
208 | extern void html_link_close(void); | 208 | extern void html_link_close(void); |
209 | extern void html_filemode(unsigned short mode); | 209 | extern void html_filemode(unsigned short mode); |
210 | extern int html_include(const char *filename); | 210 | extern int html_include(const char *filename); |
211 | 211 | ||
212 | extern int cgit_read_config(const char *filename, configfn fn); | 212 | extern int cgit_read_config(const char *filename, configfn fn); |
213 | extern int cgit_parse_query(char *txt, configfn fn); | 213 | extern int cgit_parse_query(char *txt, configfn fn); |
214 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 214 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
215 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 215 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
216 | extern void cgit_parse_url(const char *url); | 216 | extern void cgit_parse_url(const char *url); |
217 | 217 | ||
218 | extern char *cache_safe_filename(const char *unsafe); | 218 | extern char *cache_safe_filename(const char *unsafe); |
219 | extern int cache_lock(struct cacheitem *item); | 219 | extern int cache_lock(struct cacheitem *item); |
220 | extern int cache_unlock(struct cacheitem *item); | 220 | extern int cache_unlock(struct cacheitem *item); |
221 | extern int cache_cancel_lock(struct cacheitem *item); | 221 | extern int cache_cancel_lock(struct cacheitem *item); |
222 | extern int cache_exist(struct cacheitem *item); | 222 | extern int cache_exist(struct cacheitem *item); |
223 | extern int cache_expired(struct cacheitem *item); | 223 | extern int cache_expired(struct cacheitem *item); |
224 | 224 | ||
225 | extern char *cgit_repourl(const char *reponame); | 225 | extern char *cgit_repourl(const char *reponame); |
226 | extern char *cgit_fileurl(const char *reponame, const char *pagename, | 226 | extern char *cgit_fileurl(const char *reponame, const char *pagename, |
227 | const char *filename, const char *query); | 227 | const char *filename, const char *query); |
228 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 228 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
229 | const char *query); | 229 | const char *query); |
230 | 230 | ||
231 | extern const char *cgit_repobasename(const char *reponame); | 231 | extern const char *cgit_repobasename(const char *reponame); |
232 | 232 | ||
233 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, | 233 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, |
234 | char *rev, char *path); | 234 | char *rev, char *path); |
235 | extern void cgit_log_link(char *name, char *title, char *class, char *head, | 235 | extern void cgit_log_link(char *name, char *title, char *class, char *head, |
236 | char *rev, char *path, int ofs); | 236 | char *rev, char *path, int ofs); |
237 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, | 237 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, |
238 | char *rev); | 238 | char *rev); |
239 | extern void cgit_refs_link(char *name, char *title, char *class, char *head, | ||
240 | char *rev, char *path); | ||
239 | extern void cgit_snapshot_link(char *name, char *title, char *class, | 241 | extern void cgit_snapshot_link(char *name, char *title, char *class, |
240 | char *head, char *rev, char *archivename); | 242 | char *head, char *rev, char *archivename); |
241 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, | 243 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, |
242 | char *new_rev, char *old_rev, char *path); | 244 | char *new_rev, char *old_rev, char *path); |
243 | 245 | ||
244 | extern void cgit_object_link(struct object *obj); | 246 | extern void cgit_object_link(struct object *obj); |
245 | 247 | ||
246 | extern void cgit_print_error(char *msg); | 248 | extern void cgit_print_error(char *msg); |
247 | extern void cgit_print_date(time_t secs, char *format); | 249 | extern void cgit_print_date(time_t secs, char *format); |
248 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 250 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
249 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 251 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
250 | extern void cgit_print_docend(); | 252 | extern void cgit_print_docend(); |
251 | extern void cgit_print_pageheader(char *title, int show_search); | 253 | extern void cgit_print_pageheader(char *title, int show_search); |
252 | extern void cgit_print_snapshot_start(const char *mimetype, | 254 | extern void cgit_print_snapshot_start(const char *mimetype, |
253 | const char *filename, | 255 | const char *filename, |
254 | struct cacheitem *item); | 256 | struct cacheitem *item); |
255 | extern void cgit_print_branches(int maxcount); | 257 | extern void cgit_print_branches(int maxcount); |
256 | extern void cgit_print_tags(int maxcount); | 258 | extern void cgit_print_tags(int maxcount); |
257 | 259 | ||
258 | extern void cgit_print_repolist(struct cacheitem *item); | 260 | extern void cgit_print_repolist(struct cacheitem *item); |
259 | extern void cgit_print_summary(); | 261 | extern void cgit_print_summary(); |
260 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); | 262 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); |
261 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); | 263 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
262 | extern void cgit_print_tree(const char *rev, char *path); | 264 | extern void cgit_print_tree(const char *rev, char *path); |
263 | extern void cgit_print_commit(char *hex); | 265 | extern void cgit_print_commit(char *hex); |
264 | extern void cgit_print_refs(); | 266 | extern void cgit_print_refs(); |
265 | extern void cgit_print_tag(char *revname); | 267 | extern void cgit_print_tag(char *revname); |
266 | extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix); | 268 | extern void cgit_print_diff(const char *new_hex, const char *old_hex, const char *prefix); |
267 | extern void cgit_print_snapshot(struct cacheitem *item, const char *head, | 269 | extern void cgit_print_snapshot(struct cacheitem *item, const char *head, |
268 | const char *hex, const char *prefix, | 270 | const char *hex, const char *prefix, |
269 | const char *filename, int snapshot); | 271 | const char *filename, int snapshot); |
270 | extern void cgit_print_snapshot_links(const char *repo, const char *head, | 272 | extern void cgit_print_snapshot_links(const char *repo, const char *head, |
271 | const char *hex, int snapshots); | 273 | const char *hex, int snapshots); |
272 | extern int cgit_parse_snapshots_mask(const char *str); | 274 | extern int cgit_parse_snapshots_mask(const char *str); |
273 | 275 | ||
274 | #endif /* CGIT_H */ | 276 | #endif /* CGIT_H */ |
diff --git a/ui-shared.c b/ui-shared.c index 5c5bcf3..e4bb98f 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -38,384 +38,390 @@ void cgit_print_error(char *msg) | |||
38 | html("<div class='error'>"); | 38 | html("<div class='error'>"); |
39 | html_txt(msg); | 39 | html_txt(msg); |
40 | html("</div>\n"); | 40 | html("</div>\n"); |
41 | } | 41 | } |
42 | 42 | ||
43 | char *cgit_rooturl() | 43 | char *cgit_rooturl() |
44 | { | 44 | { |
45 | if (cgit_virtual_root) | 45 | if (cgit_virtual_root) |
46 | return fmt("%s/", cgit_virtual_root); | 46 | return fmt("%s/", cgit_virtual_root); |
47 | else | 47 | else |
48 | return cgit_script_name; | 48 | return cgit_script_name; |
49 | } | 49 | } |
50 | 50 | ||
51 | char *cgit_repourl(const char *reponame) | 51 | char *cgit_repourl(const char *reponame) |
52 | { | 52 | { |
53 | if (cgit_virtual_root) { | 53 | if (cgit_virtual_root) { |
54 | return fmt("%s/%s/", cgit_virtual_root, reponame); | 54 | return fmt("%s/%s/", cgit_virtual_root, reponame); |
55 | } else { | 55 | } else { |
56 | return fmt("?r=%s", reponame); | 56 | return fmt("?r=%s", reponame); |
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | char *cgit_fileurl(const char *reponame, const char *pagename, | 60 | char *cgit_fileurl(const char *reponame, const char *pagename, |
61 | const char *filename, const char *query) | 61 | const char *filename, const char *query) |
62 | { | 62 | { |
63 | if (cgit_virtual_root) { | 63 | if (cgit_virtual_root) { |
64 | if (query) | 64 | if (query) |
65 | return fmt("%s/%s/%s/%s?%s", cgit_virtual_root, reponame, | 65 | return fmt("%s/%s/%s/%s?%s", cgit_virtual_root, reponame, |
66 | pagename, filename?filename:"", query); | 66 | pagename, filename?filename:"", query); |
67 | else | 67 | else |
68 | return fmt("%s/%s/%s/", cgit_virtual_root, reponame, | 68 | return fmt("%s/%s/%s/", cgit_virtual_root, reponame, |
69 | pagename); | 69 | pagename); |
70 | } else { | 70 | } else { |
71 | if (query) | 71 | if (query) |
72 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); | 72 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); |
73 | else | 73 | else |
74 | return fmt("?r=%s&p=%s", reponame, pagename); | 74 | return fmt("?r=%s&p=%s", reponame, pagename); |
75 | } | 75 | } |
76 | } | 76 | } |
77 | 77 | ||
78 | char *cgit_pageurl(const char *reponame, const char *pagename, | 78 | char *cgit_pageurl(const char *reponame, const char *pagename, |
79 | const char *query) | 79 | const char *query) |
80 | { | 80 | { |
81 | return cgit_fileurl(reponame,pagename,0,query); | 81 | return cgit_fileurl(reponame,pagename,0,query); |
82 | } | 82 | } |
83 | 83 | ||
84 | const char *cgit_repobasename(const char *reponame) | 84 | const char *cgit_repobasename(const char *reponame) |
85 | { | 85 | { |
86 | /* I assume we don't need to store more than one repo basename */ | 86 | /* I assume we don't need to store more than one repo basename */ |
87 | static char rvbuf[1024]; | 87 | static char rvbuf[1024]; |
88 | int p; | 88 | int p; |
89 | const char *rv; | 89 | const char *rv; |
90 | strncpy(rvbuf,reponame,sizeof(rvbuf)); | 90 | strncpy(rvbuf,reponame,sizeof(rvbuf)); |
91 | if(rvbuf[sizeof(rvbuf)-1]) | 91 | if(rvbuf[sizeof(rvbuf)-1]) |
92 | die("cgit_repobasename: truncated repository name '%s'", reponame); | 92 | die("cgit_repobasename: truncated repository name '%s'", reponame); |
93 | p = strlen(rvbuf)-1; | 93 | p = strlen(rvbuf)-1; |
94 | /* strip trailing slashes */ | 94 | /* strip trailing slashes */ |
95 | while(p && rvbuf[p]=='/') rvbuf[p--]=0; | 95 | while(p && rvbuf[p]=='/') rvbuf[p--]=0; |
96 | /* strip trailing .git */ | 96 | /* strip trailing .git */ |
97 | if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { | 97 | if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { |
98 | p -= 3; rvbuf[p--] = 0; | 98 | p -= 3; rvbuf[p--] = 0; |
99 | } | 99 | } |
100 | /* strip more trailing slashes if any */ | 100 | /* strip more trailing slashes if any */ |
101 | while( p && rvbuf[p]=='/') rvbuf[p--]=0; | 101 | while( p && rvbuf[p]=='/') rvbuf[p--]=0; |
102 | /* find last slash in the remaining string */ | 102 | /* find last slash in the remaining string */ |
103 | rv = strrchr(rvbuf,'/'); | 103 | rv = strrchr(rvbuf,'/'); |
104 | if(rv) | 104 | if(rv) |
105 | return ++rv; | 105 | return ++rv; |
106 | return rvbuf; | 106 | return rvbuf; |
107 | } | 107 | } |
108 | 108 | ||
109 | char *cgit_currurl() | 109 | char *cgit_currurl() |
110 | { | 110 | { |
111 | if (!cgit_virtual_root) | 111 | if (!cgit_virtual_root) |
112 | return cgit_script_name; | 112 | return cgit_script_name; |
113 | else if (cgit_query_page) | 113 | else if (cgit_query_page) |
114 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); | 114 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); |
115 | else if (cgit_query_repo) | 115 | else if (cgit_query_repo) |
116 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); | 116 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); |
117 | else | 117 | else |
118 | return fmt("%s/", cgit_virtual_root); | 118 | return fmt("%s/", cgit_virtual_root); |
119 | } | 119 | } |
120 | 120 | ||
121 | static char *repolink(char *title, char *class, char *page, char *head, | 121 | static char *repolink(char *title, char *class, char *page, char *head, |
122 | char *path) | 122 | char *path) |
123 | { | 123 | { |
124 | char *delim = "?"; | 124 | char *delim = "?"; |
125 | 125 | ||
126 | html("<a"); | 126 | html("<a"); |
127 | if (title) { | 127 | if (title) { |
128 | html(" title='"); | 128 | html(" title='"); |
129 | html_attr(title); | 129 | html_attr(title); |
130 | html("'"); | 130 | html("'"); |
131 | } | 131 | } |
132 | if (class) { | 132 | if (class) { |
133 | html(" class='"); | 133 | html(" class='"); |
134 | html_attr(class); | 134 | html_attr(class); |
135 | html("'"); | 135 | html("'"); |
136 | } | 136 | } |
137 | html(" href='"); | 137 | html(" href='"); |
138 | if (cgit_virtual_root) { | 138 | if (cgit_virtual_root) { |
139 | html_attr(cgit_virtual_root); | 139 | html_attr(cgit_virtual_root); |
140 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') | 140 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') |
141 | html("/"); | 141 | html("/"); |
142 | html_attr(cgit_repo->url); | 142 | html_attr(cgit_repo->url); |
143 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 143 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') |
144 | html("/"); | 144 | html("/"); |
145 | if (page) { | 145 | if (page) { |
146 | html(page); | 146 | html(page); |
147 | html("/"); | 147 | html("/"); |
148 | if (path) | 148 | if (path) |
149 | html_attr(path); | 149 | html_attr(path); |
150 | } | 150 | } |
151 | } else { | 151 | } else { |
152 | html(cgit_script_name); | 152 | html(cgit_script_name); |
153 | html("?url="); | 153 | html("?url="); |
154 | html_attr(cgit_repo->url); | 154 | html_attr(cgit_repo->url); |
155 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 155 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') |
156 | html("/"); | 156 | html("/"); |
157 | if (page) { | 157 | if (page) { |
158 | html(page); | 158 | html(page); |
159 | html("/"); | 159 | html("/"); |
160 | if (path) | 160 | if (path) |
161 | html_attr(path); | 161 | html_attr(path); |
162 | } | 162 | } |
163 | delim = "&"; | 163 | delim = "&"; |
164 | } | 164 | } |
165 | if (head && strcmp(head, cgit_repo->defbranch)) { | 165 | if (head && strcmp(head, cgit_repo->defbranch)) { |
166 | html(delim); | 166 | html(delim); |
167 | html("h="); | 167 | html("h="); |
168 | html_attr(head); | 168 | html_attr(head); |
169 | delim = "&"; | 169 | delim = "&"; |
170 | } | 170 | } |
171 | return fmt("%s", delim); | 171 | return fmt("%s", delim); |
172 | } | 172 | } |
173 | 173 | ||
174 | static void reporevlink(char *page, char *name, char *title, char *class, | 174 | static void reporevlink(char *page, char *name, char *title, char *class, |
175 | char *head, char *rev, char *path) | 175 | char *head, char *rev, char *path) |
176 | { | 176 | { |
177 | char *delim; | 177 | char *delim; |
178 | 178 | ||
179 | delim = repolink(title, class, page, head, path); | 179 | delim = repolink(title, class, page, head, path); |
180 | if (rev && strcmp(rev, cgit_query_head)) { | 180 | if (rev && strcmp(rev, cgit_query_head)) { |
181 | html(delim); | 181 | html(delim); |
182 | html("id="); | 182 | html("id="); |
183 | html_attr(rev); | 183 | html_attr(rev); |
184 | } | 184 | } |
185 | html("'>"); | 185 | html("'>"); |
186 | html_txt(name); | 186 | html_txt(name); |
187 | html("</a>"); | 187 | html("</a>"); |
188 | } | 188 | } |
189 | 189 | ||
190 | void cgit_tree_link(char *name, char *title, char *class, char *head, | 190 | void cgit_tree_link(char *name, char *title, char *class, char *head, |
191 | char *rev, char *path) | 191 | char *rev, char *path) |
192 | { | 192 | { |
193 | reporevlink("tree", name, title, class, head, rev, path); | 193 | reporevlink("tree", name, title, class, head, rev, path); |
194 | } | 194 | } |
195 | 195 | ||
196 | void cgit_log_link(char *name, char *title, char *class, char *head, | 196 | void cgit_log_link(char *name, char *title, char *class, char *head, |
197 | char *rev, char *path, int ofs) | 197 | char *rev, char *path, int ofs) |
198 | { | 198 | { |
199 | char *delim; | 199 | char *delim; |
200 | 200 | ||
201 | delim = repolink(title, class, "log", head, path); | 201 | delim = repolink(title, class, "log", head, path); |
202 | if (rev && strcmp(rev, cgit_query_head)) { | 202 | if (rev && strcmp(rev, cgit_query_head)) { |
203 | html(delim); | 203 | html(delim); |
204 | html("id="); | 204 | html("id="); |
205 | html_attr(rev); | 205 | html_attr(rev); |
206 | delim = "&"; | 206 | delim = "&"; |
207 | } | 207 | } |
208 | if (ofs > 0) { | 208 | if (ofs > 0) { |
209 | html(delim); | 209 | html(delim); |
210 | html("ofs="); | 210 | html("ofs="); |
211 | htmlf("%d", ofs); | 211 | htmlf("%d", ofs); |
212 | } | 212 | } |
213 | html("'>"); | 213 | html("'>"); |
214 | html_txt(name); | 214 | html_txt(name); |
215 | html("</a>"); | 215 | html("</a>"); |
216 | } | 216 | } |
217 | 217 | ||
218 | void cgit_commit_link(char *name, char *title, char *class, char *head, | 218 | void cgit_commit_link(char *name, char *title, char *class, char *head, |
219 | char *rev) | 219 | char *rev) |
220 | { | 220 | { |
221 | if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { | 221 | if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { |
222 | name[cgit_max_msg_len] = '\0'; | 222 | name[cgit_max_msg_len] = '\0'; |
223 | name[cgit_max_msg_len - 1] = '.'; | 223 | name[cgit_max_msg_len - 1] = '.'; |
224 | name[cgit_max_msg_len - 2] = '.'; | 224 | name[cgit_max_msg_len - 2] = '.'; |
225 | name[cgit_max_msg_len - 3] = '.'; | 225 | name[cgit_max_msg_len - 3] = '.'; |
226 | } | 226 | } |
227 | reporevlink("commit", name, title, class, head, rev, NULL); | 227 | reporevlink("commit", name, title, class, head, rev, NULL); |
228 | } | 228 | } |
229 | 229 | ||
230 | void cgit_refs_link(char *name, char *title, char *class, char *head, | ||
231 | char *rev, char *path) | ||
232 | { | ||
233 | reporevlink("refs", name, title, class, head, rev, path); | ||
234 | } | ||
235 | |||
230 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, | 236 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, |
231 | char *rev, char *archivename) | 237 | char *rev, char *archivename) |
232 | { | 238 | { |
233 | reporevlink("snapshot", name, title, class, head, rev, archivename); | 239 | reporevlink("snapshot", name, title, class, head, rev, archivename); |
234 | } | 240 | } |
235 | 241 | ||
236 | void cgit_diff_link(char *name, char *title, char *class, char *head, | 242 | void cgit_diff_link(char *name, char *title, char *class, char *head, |
237 | char *new_rev, char *old_rev, char *path) | 243 | char *new_rev, char *old_rev, char *path) |
238 | { | 244 | { |
239 | char *delim; | 245 | char *delim; |
240 | 246 | ||
241 | delim = repolink(title, class, "diff", head, path); | 247 | delim = repolink(title, class, "diff", head, path); |
242 | if (new_rev && strcmp(new_rev, cgit_query_head)) { | 248 | if (new_rev && strcmp(new_rev, cgit_query_head)) { |
243 | html(delim); | 249 | html(delim); |
244 | html("id="); | 250 | html("id="); |
245 | html_attr(new_rev); | 251 | html_attr(new_rev); |
246 | delim = "&"; | 252 | delim = "&"; |
247 | } | 253 | } |
248 | if (old_rev) { | 254 | if (old_rev) { |
249 | html(delim); | 255 | html(delim); |
250 | html("id2="); | 256 | html("id2="); |
251 | html_attr(old_rev); | 257 | html_attr(old_rev); |
252 | } | 258 | } |
253 | html("'>"); | 259 | html("'>"); |
254 | html_txt(name); | 260 | html_txt(name); |
255 | html("</a>"); | 261 | html("</a>"); |
256 | } | 262 | } |
257 | 263 | ||
258 | void cgit_object_link(struct object *obj) | 264 | void cgit_object_link(struct object *obj) |
259 | { | 265 | { |
260 | char *page, *arg, *url; | 266 | char *page, *arg, *url; |
261 | 267 | ||
262 | if (obj->type == OBJ_COMMIT) { | 268 | if (obj->type == OBJ_COMMIT) { |
263 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, | 269 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, |
264 | cgit_query_head, sha1_to_hex(obj->sha1)); | 270 | cgit_query_head, sha1_to_hex(obj->sha1)); |
265 | return; | 271 | return; |
266 | } else if (obj->type == OBJ_TREE) { | 272 | } else if (obj->type == OBJ_TREE) { |
267 | page = "tree"; | 273 | page = "tree"; |
268 | arg = "id"; | 274 | arg = "id"; |
269 | } else { | 275 | } else { |
270 | page = "blob"; | 276 | page = "blob"; |
271 | arg = "id"; | 277 | arg = "id"; |
272 | } | 278 | } |
273 | 279 | ||
274 | url = cgit_pageurl(cgit_query_repo, page, | 280 | url = cgit_pageurl(cgit_query_repo, page, |
275 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); | 281 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); |
276 | html_link_open(url, NULL, NULL); | 282 | html_link_open(url, NULL, NULL); |
277 | htmlf("%s %s", typename(obj->type), | 283 | htmlf("%s %s", typename(obj->type), |
278 | sha1_to_hex(obj->sha1)); | 284 | sha1_to_hex(obj->sha1)); |
279 | html_link_close(); | 285 | html_link_close(); |
280 | } | 286 | } |
281 | 287 | ||
282 | void cgit_print_date(time_t secs, char *format) | 288 | void cgit_print_date(time_t secs, char *format) |
283 | { | 289 | { |
284 | char buf[64]; | 290 | char buf[64]; |
285 | struct tm *time; | 291 | struct tm *time; |
286 | 292 | ||
287 | time = gmtime(&secs); | 293 | time = gmtime(&secs); |
288 | strftime(buf, sizeof(buf)-1, format, time); | 294 | strftime(buf, sizeof(buf)-1, format, time); |
289 | html_txt(buf); | 295 | html_txt(buf); |
290 | } | 296 | } |
291 | 297 | ||
292 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 298 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
293 | { | 299 | { |
294 | time_t now, secs; | 300 | time_t now, secs; |
295 | 301 | ||
296 | time(&now); | 302 | time(&now); |
297 | secs = now - t; | 303 | secs = now - t; |
298 | 304 | ||
299 | if (secs > max_relative && max_relative >= 0) { | 305 | if (secs > max_relative && max_relative >= 0) { |
300 | cgit_print_date(t, format); | 306 | cgit_print_date(t, format); |
301 | return; | 307 | return; |
302 | } | 308 | } |
303 | 309 | ||
304 | if (secs < TM_HOUR * 2) { | 310 | if (secs < TM_HOUR * 2) { |
305 | htmlf("<span class='age-mins'>%.0f min.</span>", | 311 | htmlf("<span class='age-mins'>%.0f min.</span>", |
306 | secs * 1.0 / TM_MIN); | 312 | secs * 1.0 / TM_MIN); |
307 | return; | 313 | return; |
308 | } | 314 | } |
309 | if (secs < TM_DAY * 2) { | 315 | if (secs < TM_DAY * 2) { |
310 | htmlf("<span class='age-hours'>%.0f hours</span>", | 316 | htmlf("<span class='age-hours'>%.0f hours</span>", |
311 | secs * 1.0 / TM_HOUR); | 317 | secs * 1.0 / TM_HOUR); |
312 | return; | 318 | return; |
313 | } | 319 | } |
314 | if (secs < TM_WEEK * 2) { | 320 | if (secs < TM_WEEK * 2) { |
315 | htmlf("<span class='age-days'>%.0f days</span>", | 321 | htmlf("<span class='age-days'>%.0f days</span>", |
316 | secs * 1.0 / TM_DAY); | 322 | secs * 1.0 / TM_DAY); |
317 | return; | 323 | return; |
318 | } | 324 | } |
319 | if (secs < TM_MONTH * 2) { | 325 | if (secs < TM_MONTH * 2) { |
320 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 326 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
321 | secs * 1.0 / TM_WEEK); | 327 | secs * 1.0 / TM_WEEK); |
322 | return; | 328 | return; |
323 | } | 329 | } |
324 | if (secs < TM_YEAR * 2) { | 330 | if (secs < TM_YEAR * 2) { |
325 | htmlf("<span class='age-months'>%.0f months</span>", | 331 | htmlf("<span class='age-months'>%.0f months</span>", |
326 | secs * 1.0 / TM_MONTH); | 332 | secs * 1.0 / TM_MONTH); |
327 | return; | 333 | return; |
328 | } | 334 | } |
329 | htmlf("<span class='age-years'>%.0f years</span>", | 335 | htmlf("<span class='age-years'>%.0f years</span>", |
330 | secs * 1.0 / TM_YEAR); | 336 | secs * 1.0 / TM_YEAR); |
331 | } | 337 | } |
332 | 338 | ||
333 | void cgit_print_docstart(char *title, struct cacheitem *item) | 339 | void cgit_print_docstart(char *title, struct cacheitem *item) |
334 | { | 340 | { |
335 | html("Content-Type: text/html; charset=utf-8\n"); | 341 | html("Content-Type: text/html; charset=utf-8\n"); |
336 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 342 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
337 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 343 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
338 | ttl_seconds(item->ttl))); | 344 | ttl_seconds(item->ttl))); |
339 | html("\n"); | 345 | html("\n"); |
340 | html(cgit_doctype); | 346 | html(cgit_doctype); |
341 | html("<html>\n"); | 347 | html("<html>\n"); |
342 | html("<head>\n"); | 348 | html("<head>\n"); |
343 | html("<title>"); | 349 | html("<title>"); |
344 | html_txt(title); | 350 | html_txt(title); |
345 | html("</title>\n"); | 351 | html("</title>\n"); |
346 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 352 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
347 | html("<link rel='stylesheet' type='text/css' href='"); | 353 | html("<link rel='stylesheet' type='text/css' href='"); |
348 | html_attr(cgit_css); | 354 | html_attr(cgit_css); |
349 | html("'/>\n"); | 355 | html("'/>\n"); |
350 | html("</head>\n"); | 356 | html("</head>\n"); |
351 | html("<body>\n"); | 357 | html("<body>\n"); |
352 | } | 358 | } |
353 | 359 | ||
354 | void cgit_print_docend() | 360 | void cgit_print_docend() |
355 | { | 361 | { |
356 | html("</td></tr></table>"); | 362 | html("</td></tr></table>"); |
357 | html("</body>\n</html>\n"); | 363 | html("</body>\n</html>\n"); |
358 | } | 364 | } |
359 | 365 | ||
360 | void cgit_print_pageheader(char *title, int show_search) | 366 | void cgit_print_pageheader(char *title, int show_search) |
361 | { | 367 | { |
362 | html("<table id='layout'>"); | 368 | html("<table id='layout'>"); |
363 | html("<tr><td id='header'><a href='"); | 369 | html("<tr><td id='header'><a href='"); |
364 | html_attr(cgit_rooturl()); | 370 | html_attr(cgit_rooturl()); |
365 | html("'>"); | 371 | html("'>"); |
366 | html_txt(cgit_root_title); | 372 | html_txt(cgit_root_title); |
367 | html("</a></td><td id='logo'>"); | 373 | html("</a></td><td id='logo'>"); |
368 | html("<a href='"); | 374 | html("<a href='"); |
369 | html_attr(cgit_logo_link); | 375 | html_attr(cgit_logo_link); |
370 | htmlf("'><img src='%s' alt='logo'/></a>", cgit_logo); | 376 | htmlf("'><img src='%s' alt='logo'/></a>", cgit_logo); |
371 | html("</td></tr>"); | 377 | html("</td></tr>"); |
372 | html("<tr><td id='crumb'>"); | 378 | html("<tr><td id='crumb'>"); |
373 | if (cgit_query_repo) { | 379 | if (cgit_query_repo) { |
374 | html_txt(cgit_repo->name); | 380 | html_txt(cgit_repo->name); |
375 | html(" ("); | 381 | html(" ("); |
376 | html_txt(cgit_query_head); | 382 | html_txt(cgit_query_head); |
377 | html(") : "); | 383 | html(") : "); |
378 | reporevlink(NULL, "summary", NULL, NULL, cgit_query_head, | 384 | reporevlink(NULL, "summary", NULL, NULL, cgit_query_head, |
379 | NULL, NULL); | 385 | NULL, NULL); |
380 | html(" "); | 386 | html(" "); |
381 | cgit_log_link("log", NULL, NULL, cgit_query_head, | 387 | cgit_log_link("log", NULL, NULL, cgit_query_head, |
382 | cgit_query_sha1, cgit_query_path, 0); | 388 | cgit_query_sha1, cgit_query_path, 0); |
383 | html(" "); | 389 | html(" "); |
384 | cgit_tree_link("tree", NULL, NULL, cgit_query_head, | 390 | cgit_tree_link("tree", NULL, NULL, cgit_query_head, |
385 | cgit_query_sha1, NULL); | 391 | cgit_query_sha1, NULL); |
386 | html(" "); | 392 | html(" "); |
387 | cgit_commit_link("commit", NULL, NULL, cgit_query_head, | 393 | cgit_commit_link("commit", NULL, NULL, cgit_query_head, |
388 | cgit_query_sha1); | 394 | cgit_query_sha1); |
389 | html(" "); | 395 | html(" "); |
390 | cgit_diff_link("diff", NULL, NULL, cgit_query_head, | 396 | cgit_diff_link("diff", NULL, NULL, cgit_query_head, |
391 | cgit_query_sha1, cgit_query_sha2, | 397 | cgit_query_sha1, cgit_query_sha2, |
392 | cgit_query_path); | 398 | cgit_query_path); |
393 | } else { | 399 | } else { |
394 | html_txt("Index of repositories"); | 400 | html_txt("Index of repositories"); |
395 | } | 401 | } |
396 | html("</td>"); | 402 | html("</td>"); |
397 | html("<td id='search'>"); | 403 | html("<td id='search'>"); |
398 | if (show_search) { | 404 | if (show_search) { |
399 | html("<form method='get' action='"); | 405 | html("<form method='get' action='"); |
400 | html_attr(cgit_currurl()); | 406 | html_attr(cgit_currurl()); |
401 | html("'>"); | 407 | html("'>"); |
402 | if (!cgit_virtual_root) { | 408 | if (!cgit_virtual_root) { |
403 | if (cgit_query_repo) | 409 | if (cgit_query_repo) |
404 | html_hidden("r", cgit_query_repo); | 410 | html_hidden("r", cgit_query_repo); |
405 | if (cgit_query_page) | 411 | if (cgit_query_page) |
406 | html_hidden("p", cgit_query_page); | 412 | html_hidden("p", cgit_query_page); |
407 | } | 413 | } |
408 | if (cgit_query_head) | 414 | if (cgit_query_head) |
409 | html_hidden("h", cgit_query_head); | 415 | html_hidden("h", cgit_query_head); |
410 | if (cgit_query_sha1) | 416 | if (cgit_query_sha1) |
411 | html_hidden("id", cgit_query_sha1); | 417 | html_hidden("id", cgit_query_sha1); |
412 | if (cgit_query_sha2) | 418 | if (cgit_query_sha2) |
413 | html_hidden("id2", cgit_query_sha2); | 419 | html_hidden("id2", cgit_query_sha2); |
414 | html("<input type='text' name='q' value='"); | 420 | html("<input type='text' name='q' value='"); |
415 | html_attr(cgit_query_search); | 421 | html_attr(cgit_query_search); |
416 | html("'/></form>"); | 422 | html("'/></form>"); |
417 | } | 423 | } |
418 | html("</td></tr>"); | 424 | html("</td></tr>"); |
419 | html("<tr><td id='content' colspan='2'>"); | 425 | html("<tr><td id='content' colspan='2'>"); |
420 | } | 426 | } |
421 | 427 | ||
diff --git a/ui-summary.c b/ui-summary.c index 97f1b57..016fea2 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -1,245 +1,258 @@ | |||
1 | /* ui-summary.c: functions for generating repo summary page | 1 | /* ui-summary.c: functions for generating repo summary 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 | 10 | ||
11 | static int header; | 11 | static int header; |
12 | 12 | ||
13 | static int cmp_age(int age1, int age2) | 13 | static int cmp_age(int age1, int age2) |
14 | { | 14 | { |
15 | if (age1 != 0 && age2 != 0) | 15 | if (age1 != 0 && age2 != 0) |
16 | return age2 - age1; | 16 | return age2 - age1; |
17 | 17 | ||
18 | if (age1 == 0 && age2 == 0) | 18 | if (age1 == 0 && age2 == 0) |
19 | return 0; | 19 | return 0; |
20 | 20 | ||
21 | if (age1 == 0) | 21 | if (age1 == 0) |
22 | return +1; | 22 | return +1; |
23 | 23 | ||
24 | return -1; | 24 | return -1; |
25 | } | 25 | } |
26 | 26 | ||
27 | static int cmp_ref_name(const void *a, const void *b) | 27 | static int cmp_ref_name(const void *a, const void *b) |
28 | { | 28 | { |
29 | struct refinfo *r1 = *(struct refinfo **)a; | 29 | struct refinfo *r1 = *(struct refinfo **)a; |
30 | struct refinfo *r2 = *(struct refinfo **)b; | 30 | struct refinfo *r2 = *(struct refinfo **)b; |
31 | 31 | ||
32 | return strcmp(r1->refname, r2->refname); | 32 | return strcmp(r1->refname, r2->refname); |
33 | } | 33 | } |
34 | 34 | ||
35 | static int cmp_branch_age(const void *a, const void *b) | 35 | static int cmp_branch_age(const void *a, const void *b) |
36 | { | 36 | { |
37 | struct refinfo *r1 = *(struct refinfo **)a; | 37 | struct refinfo *r1 = *(struct refinfo **)a; |
38 | struct refinfo *r2 = *(struct refinfo **)b; | 38 | struct refinfo *r2 = *(struct refinfo **)b; |
39 | 39 | ||
40 | return cmp_age(r1->commit->committer_date, r2->commit->committer_date); | 40 | return cmp_age(r1->commit->committer_date, r2->commit->committer_date); |
41 | } | 41 | } |
42 | 42 | ||
43 | static int cmp_tag_age(const void *a, const void *b) | 43 | static int cmp_tag_age(const void *a, const void *b) |
44 | { | 44 | { |
45 | struct refinfo *r1 = *(struct refinfo **)a; | 45 | struct refinfo *r1 = *(struct refinfo **)a; |
46 | struct refinfo *r2 = *(struct refinfo **)b; | 46 | struct refinfo *r2 = *(struct refinfo **)b; |
47 | 47 | ||
48 | return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date); | 48 | return cmp_age(r1->tag->tagger_date, r2->tag->tagger_date); |
49 | } | 49 | } |
50 | 50 | ||
51 | static void cgit_print_branch(struct refinfo *ref) | 51 | static void cgit_print_branch(struct refinfo *ref) |
52 | { | 52 | { |
53 | struct commit *commit; | 53 | struct commit *commit; |
54 | struct commitinfo *info; | 54 | struct commitinfo *info; |
55 | char *name = (char *)ref->refname; | 55 | char *name = (char *)ref->refname; |
56 | 56 | ||
57 | commit = lookup_commit(ref->object->sha1); | 57 | commit = lookup_commit(ref->object->sha1); |
58 | // object is not really parsed at this point, because of some fallout | 58 | // object is not really parsed at this point, because of some fallout |
59 | // from previous calls to git functions in cgit_print_log() | 59 | // from previous calls to git functions in cgit_print_log() |
60 | commit->object.parsed = 0; | 60 | commit->object.parsed = 0; |
61 | if (commit && !parse_commit(commit)){ | 61 | if (commit && !parse_commit(commit)){ |
62 | info = cgit_parse_commit(commit); | 62 | info = cgit_parse_commit(commit); |
63 | html("<tr><td>"); | 63 | html("<tr><td>"); |
64 | cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0); | 64 | cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0); |
65 | html("</td><td>"); | 65 | html("</td><td>"); |
66 | cgit_print_age(commit->date, -1, NULL); | 66 | cgit_print_age(commit->date, -1, NULL); |
67 | html("</td><td>"); | 67 | html("</td><td>"); |
68 | html_txt(info->author); | 68 | html_txt(info->author); |
69 | html("</td><td>"); | 69 | html("</td><td>"); |
70 | cgit_commit_link(info->subject, NULL, NULL, name, NULL); | 70 | cgit_commit_link(info->subject, NULL, NULL, name, NULL); |
71 | html("</td></tr>\n"); | 71 | html("</td></tr>\n"); |
72 | cgit_free_commitinfo(info); | 72 | cgit_free_commitinfo(info); |
73 | } else { | 73 | } else { |
74 | html("<tr><td>"); | 74 | html("<tr><td>"); |
75 | html_txt(name); | 75 | html_txt(name); |
76 | html("</td><td colspan='3'>"); | 76 | html("</td><td colspan='3'>"); |
77 | htmlf("*** bad ref %s ***", sha1_to_hex(ref->object->sha1)); | 77 | htmlf("*** bad ref %s ***", sha1_to_hex(ref->object->sha1)); |
78 | html("</td></tr>\n"); | 78 | html("</td></tr>\n"); |
79 | } | 79 | } |
80 | } | 80 | } |
81 | 81 | ||
82 | static void print_tag_header() | 82 | static void print_tag_header() |
83 | { | 83 | { |
84 | html("<tr class='nohover'><th class='left'>Tag</th>" | 84 | html("<tr class='nohover'><th class='left'>Tag</th>" |
85 | "<th class='left'>Age</th>" | 85 | "<th class='left'>Age</th>" |
86 | "<th class='left'>Author</th>" | 86 | "<th class='left'>Author</th>" |
87 | "<th class='left'>Reference</th></tr>\n"); | 87 | "<th class='left'>Reference</th></tr>\n"); |
88 | header = 1; | 88 | header = 1; |
89 | } | 89 | } |
90 | 90 | ||
91 | static int print_tag(struct refinfo *ref) | 91 | static int print_tag(struct refinfo *ref) |
92 | { | 92 | { |
93 | struct tag *tag; | 93 | struct tag *tag; |
94 | struct taginfo *info; | 94 | struct taginfo *info; |
95 | char *url, *name = (char *)ref->refname; | 95 | char *url, *name = (char *)ref->refname; |
96 | 96 | ||
97 | if (ref->object->type == OBJ_TAG) { | 97 | if (ref->object->type == OBJ_TAG) { |
98 | tag = lookup_tag(ref->object->sha1); | 98 | tag = lookup_tag(ref->object->sha1); |
99 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 99 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
100 | return 2; | 100 | return 2; |
101 | html("<tr><td>"); | 101 | html("<tr><td>"); |
102 | url = cgit_pageurl(cgit_query_repo, "tag", | 102 | url = cgit_pageurl(cgit_query_repo, "tag", |
103 | fmt("id=%s", name)); | 103 | fmt("id=%s", name)); |
104 | html_link_open(url, NULL, NULL); | 104 | html_link_open(url, NULL, NULL); |
105 | html_txt(name); | 105 | html_txt(name); |
106 | html_link_close(); | 106 | html_link_close(); |
107 | html("</td><td>"); | 107 | html("</td><td>"); |
108 | if (info->tagger_date > 0) | 108 | if (info->tagger_date > 0) |
109 | cgit_print_age(info->tagger_date, -1, NULL); | 109 | cgit_print_age(info->tagger_date, -1, NULL); |
110 | html("</td><td>"); | 110 | html("</td><td>"); |
111 | if (info->tagger) | 111 | if (info->tagger) |
112 | html(info->tagger); | 112 | html(info->tagger); |
113 | html("</td><td>"); | 113 | html("</td><td>"); |
114 | cgit_object_link(tag->tagged); | 114 | cgit_object_link(tag->tagged); |
115 | html("</td></tr>\n"); | 115 | html("</td></tr>\n"); |
116 | } else { | 116 | } else { |
117 | if (!header) | 117 | if (!header) |
118 | print_tag_header(); | 118 | print_tag_header(); |
119 | html("<tr><td>"); | 119 | html("<tr><td>"); |
120 | html_txt(name); | 120 | html_txt(name); |
121 | html("</td><td colspan='2'/><td>"); | 121 | html("</td><td colspan='2'/><td>"); |
122 | cgit_object_link(ref->object); | 122 | cgit_object_link(ref->object); |
123 | html("</td></tr>\n"); | 123 | html("</td></tr>\n"); |
124 | } | 124 | } |
125 | return 0; | 125 | return 0; |
126 | } | 126 | } |
127 | 127 | ||
128 | static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, | 128 | static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1, |
129 | int flags, void *cb_data) | 129 | int flags, void *cb_data) |
130 | { | 130 | { |
131 | struct tag *tag; | 131 | struct tag *tag; |
132 | struct taginfo *info; | 132 | struct taginfo *info; |
133 | struct object *obj; | 133 | struct object *obj; |
134 | char buf[256], *url; | 134 | char buf[256], *url; |
135 | unsigned char fileid[20]; | 135 | unsigned char fileid[20]; |
136 | 136 | ||
137 | if (prefixcmp(refname, "refs/archives")) | 137 | if (prefixcmp(refname, "refs/archives")) |
138 | return 0; | 138 | return 0; |
139 | strncpy(buf, refname+14, sizeof(buf)); | 139 | strncpy(buf, refname+14, sizeof(buf)); |
140 | obj = parse_object(sha1); | 140 | obj = parse_object(sha1); |
141 | if (!obj) | 141 | if (!obj) |
142 | return 1; | 142 | return 1; |
143 | if (obj->type == OBJ_TAG) { | 143 | if (obj->type == OBJ_TAG) { |
144 | tag = lookup_tag(sha1); | 144 | tag = lookup_tag(sha1); |
145 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 145 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
146 | return 0; | 146 | return 0; |
147 | hashcpy(fileid, tag->tagged->sha1); | 147 | hashcpy(fileid, tag->tagged->sha1); |
148 | } else if (obj->type != OBJ_BLOB) { | 148 | } else if (obj->type != OBJ_BLOB) { |
149 | return 0; | 149 | return 0; |
150 | } else { | 150 | } else { |
151 | hashcpy(fileid, sha1); | 151 | hashcpy(fileid, sha1); |
152 | } | 152 | } |
153 | if (!header) { | 153 | if (!header) { |
154 | html("<table id='downloads'>"); | 154 | html("<table id='downloads'>"); |
155 | html("<tr><th>Downloads</th></tr>"); | 155 | html("<tr><th>Downloads</th></tr>"); |
156 | header = 1; | 156 | header = 1; |
157 | } | 157 | } |
158 | html("<tr><td>"); | 158 | html("<tr><td>"); |
159 | url = cgit_pageurl(cgit_query_repo, "blob", | 159 | url = cgit_pageurl(cgit_query_repo, "blob", |
160 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 160 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
161 | buf)); | 161 | buf)); |
162 | html_link_open(url, NULL, NULL); | 162 | html_link_open(url, NULL, NULL); |
163 | html_txt(buf); | 163 | html_txt(buf); |
164 | html_link_close(); | 164 | html_link_close(); |
165 | html("</td></tr>"); | 165 | html("</td></tr>"); |
166 | return 0; | 166 | return 0; |
167 | } | 167 | } |
168 | 168 | ||
169 | static void print_refs_link(char *path) | ||
170 | { | ||
171 | html("<tr class='nohover'><td colspan='4'>"); | ||
172 | cgit_refs_link("[...]", NULL, NULL, cgit_query_head, NULL, path); | ||
173 | html("</td></tr>"); | ||
174 | } | ||
175 | |||
169 | void cgit_print_branches(int maxcount) | 176 | void cgit_print_branches(int maxcount) |
170 | { | 177 | { |
171 | struct reflist list; | 178 | struct reflist list; |
172 | int i; | 179 | int i; |
173 | 180 | ||
174 | html("<tr class='nohover'><th class='left'>Branch</th>" | 181 | html("<tr class='nohover'><th class='left'>Branch</th>" |
175 | "<th class='left'>Idle</th>" | 182 | "<th class='left'>Idle</th>" |
176 | "<th class='left'>Author</th>" | 183 | "<th class='left'>Author</th>" |
177 | "<th class='left'>Head commit</th></tr>\n"); | 184 | "<th class='left'>Head commit</th></tr>\n"); |
178 | 185 | ||
179 | list.refs = NULL; | 186 | list.refs = NULL; |
180 | list.alloc = list.count = 0; | 187 | list.alloc = list.count = 0; |
181 | for_each_branch_ref(cgit_refs_cb, &list); | 188 | for_each_branch_ref(cgit_refs_cb, &list); |
182 | 189 | ||
183 | if (maxcount == 0 || maxcount > list.count) | 190 | if (maxcount == 0 || maxcount > list.count) |
184 | maxcount = list.count; | 191 | maxcount = list.count; |
185 | 192 | ||
186 | if (maxcount < list.count) { | 193 | if (maxcount < list.count) { |
187 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age); | 194 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age); |
188 | qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name); | 195 | qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name); |
189 | } | 196 | } |
190 | 197 | ||
191 | for(i=0; i<maxcount; i++) | 198 | for(i=0; i<maxcount; i++) |
192 | cgit_print_branch(list.refs[i]); | 199 | cgit_print_branch(list.refs[i]); |
200 | |||
201 | if (maxcount < list.count) | ||
202 | print_refs_link("heads"); | ||
193 | } | 203 | } |
194 | 204 | ||
195 | void cgit_print_tags(int maxcount) | 205 | void cgit_print_tags(int maxcount) |
196 | { | 206 | { |
197 | struct reflist list; | 207 | struct reflist list; |
198 | int i; | 208 | int i; |
199 | 209 | ||
200 | header = 0; | 210 | header = 0; |
201 | list.refs = NULL; | 211 | list.refs = NULL; |
202 | list.alloc = list.count = 0; | 212 | list.alloc = list.count = 0; |
203 | for_each_tag_ref(cgit_refs_cb, &list); | 213 | for_each_tag_ref(cgit_refs_cb, &list); |
204 | if (list.count == 0) | 214 | if (list.count == 0) |
205 | return; | 215 | return; |
206 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); | 216 | qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age); |
207 | if (!maxcount) | 217 | if (!maxcount) |
208 | maxcount = list.count; | 218 | maxcount = list.count; |
209 | else if (maxcount > list.count) | 219 | else if (maxcount > list.count) |
210 | maxcount = list.count; | 220 | maxcount = list.count; |
211 | print_tag_header(); | 221 | print_tag_header(); |
212 | for(i=0; i<maxcount; i++) | 222 | for(i=0; i<maxcount; i++) |
213 | print_tag(list.refs[i]); | 223 | print_tag(list.refs[i]); |
224 | |||
225 | if (maxcount < list.count) | ||
226 | print_refs_link("tags"); | ||
214 | } | 227 | } |
215 | 228 | ||
216 | static void cgit_print_archives() | 229 | static void cgit_print_archives() |
217 | { | 230 | { |
218 | header = 0; | 231 | header = 0; |
219 | for_each_ref(cgit_print_archive_cb, NULL); | 232 | for_each_ref(cgit_print_archive_cb, NULL); |
220 | if (header) | 233 | if (header) |
221 | html("</table>"); | 234 | html("</table>"); |
222 | } | 235 | } |
223 | 236 | ||
224 | void cgit_print_summary() | 237 | void cgit_print_summary() |
225 | { | 238 | { |
226 | html("<div id='summary'>"); | 239 | html("<div id='summary'>"); |
227 | cgit_print_archives(); | 240 | cgit_print_archives(); |
228 | html("<h2>"); | 241 | html("<h2>"); |
229 | html_txt(cgit_repo->name); | 242 | html_txt(cgit_repo->name); |
230 | html(" - "); | 243 | html(" - "); |
231 | html_txt(cgit_repo->desc); | 244 | html_txt(cgit_repo->desc); |
232 | html("</h2>"); | 245 | html("</h2>"); |
233 | if (cgit_repo->readme) | 246 | if (cgit_repo->readme) |
234 | html_include(cgit_repo->readme); | 247 | html_include(cgit_repo->readme); |
235 | html("</div>"); | 248 | html("</div>"); |
236 | if (cgit_summary_log > 0) | 249 | if (cgit_summary_log > 0) |
237 | cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0); | 250 | cgit_print_log(cgit_query_head, 0, cgit_summary_log, NULL, NULL, 0); |
238 | html("<table class='list nowrap'>"); | 251 | html("<table class='list nowrap'>"); |
239 | if (cgit_summary_log > 0) | 252 | if (cgit_summary_log > 0) |
240 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 253 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
241 | cgit_print_branches(cgit_summary_branches); | 254 | cgit_print_branches(cgit_summary_branches); |
242 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); | 255 | html("<tr class='nohover'><td colspan='4'> </td></tr>"); |
243 | cgit_print_tags(cgit_summary_tags); | 256 | cgit_print_tags(cgit_summary_tags); |
244 | html("</table>"); | 257 | html("</table>"); |
245 | } | 258 | } |