summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2007-07-21 11:13:40 (UTC)
committer Michael Krelin <hacker@klever.net>2007-07-21 11:13:40 (UTC)
commit0df096f6e146187e55e2203ea1c017442cc2c8c6 (patch) (unidiff)
treec3daea456db5424bbddee326c1479a2b759d551a
parent86ca02231fc42a629c50abebcae3ea9d4d692979 (diff)
downloadcgit-0df096f6e146187e55e2203ea1c017442cc2c8c6.zip
cgit-0df096f6e146187e55e2203ea1c017442cc2c8c6.tar.gz
cgit-0df096f6e146187e55e2203ea1c017442cc2c8c6.tar.bz2
added snapshot filename to the link
- changed cgit_pageurl into cgit_fileurl with the filename parameter - rewritten cgit_pageurl as a wrapper around cgit_fileurl Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.h2
-rw-r--r--ui-shared.c17
-rw-r--r--ui-snapshot.c2
3 files changed, 16 insertions, 5 deletions
diff --git a/cgit.h b/cgit.h
index 6937c42..aabf725 100644
--- a/cgit.h
+++ b/cgit.h
@@ -156,82 +156,84 @@ extern void cgit_repo_config_cb(const char *name, const char *value);
156extern void cgit_querystring_cb(const char *name, const char *value); 156extern void cgit_querystring_cb(const char *name, const char *value);
157 157
158extern int chk_zero(int result, char *msg); 158extern int chk_zero(int result, char *msg);
159extern int chk_positive(int result, char *msg); 159extern int chk_positive(int result, char *msg);
160extern int chk_non_negative(int result, char *msg); 160extern int chk_non_negative(int result, char *msg);
161 161
162extern int hextoint(char c); 162extern int hextoint(char c);
163extern char *trim_end(const char *str, char c); 163extern char *trim_end(const char *str, char c);
164 164
165extern void *cgit_free_commitinfo(struct commitinfo *info); 165extern void *cgit_free_commitinfo(struct commitinfo *info);
166 166
167extern int cgit_diff_files(const unsigned char *old_sha1, 167extern int cgit_diff_files(const unsigned char *old_sha1,
168 const unsigned char *new_sha1, 168 const unsigned char *new_sha1,
169 linediff_fn fn); 169 linediff_fn fn);
170 170
171extern void cgit_diff_tree(const unsigned char *old_sha1, 171extern void cgit_diff_tree(const unsigned char *old_sha1,
172 const unsigned char *new_sha1, 172 const unsigned char *new_sha1,
173 filepair_fn fn); 173 filepair_fn fn);
174 174
175extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); 175extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
176 176
177extern char *fmt(const char *format,...); 177extern char *fmt(const char *format,...);
178 178
179extern void html(const char *txt); 179extern void html(const char *txt);
180extern void htmlf(const char *format,...); 180extern void htmlf(const char *format,...);
181extern void html_txt(char *txt); 181extern void html_txt(char *txt);
182extern void html_ntxt(int len, char *txt); 182extern void html_ntxt(int len, char *txt);
183extern void html_attr(char *txt); 183extern void html_attr(char *txt);
184extern void html_hidden(char *name, char *value); 184extern void html_hidden(char *name, char *value);
185extern void html_link_open(char *url, char *title, char *class); 185extern void html_link_open(char *url, char *title, char *class);
186extern void html_link_close(void); 186extern void html_link_close(void);
187extern void html_filemode(unsigned short mode); 187extern void html_filemode(unsigned short mode);
188extern int html_include(const char *filename); 188extern int html_include(const char *filename);
189 189
190extern int cgit_read_config(const char *filename, configfn fn); 190extern int cgit_read_config(const char *filename, configfn fn);
191extern int cgit_parse_query(char *txt, configfn fn); 191extern int cgit_parse_query(char *txt, configfn fn);
192extern struct commitinfo *cgit_parse_commit(struct commit *commit); 192extern struct commitinfo *cgit_parse_commit(struct commit *commit);
193extern struct taginfo *cgit_parse_tag(struct tag *tag); 193extern struct taginfo *cgit_parse_tag(struct tag *tag);
194extern void cgit_parse_url(const char *url); 194extern void cgit_parse_url(const char *url);
195 195
196extern char *cache_safe_filename(const char *unsafe); 196extern char *cache_safe_filename(const char *unsafe);
197extern int cache_lock(struct cacheitem *item); 197extern int cache_lock(struct cacheitem *item);
198extern int cache_unlock(struct cacheitem *item); 198extern int cache_unlock(struct cacheitem *item);
199extern int cache_cancel_lock(struct cacheitem *item); 199extern int cache_cancel_lock(struct cacheitem *item);
200extern int cache_exist(struct cacheitem *item); 200extern int cache_exist(struct cacheitem *item);
201extern int cache_expired(struct cacheitem *item); 201extern int cache_expired(struct cacheitem *item);
202 202
203extern char *cgit_repourl(const char *reponame); 203extern char *cgit_repourl(const char *reponame);
204extern char *cgit_fileurl(const char *reponame, const char *pagename,
205 const char *filename, const char *query);
204extern char *cgit_pageurl(const char *reponame, const char *pagename, 206extern char *cgit_pageurl(const char *reponame, const char *pagename,
205 const char *query); 207 const char *query);
206 208
207extern void cgit_tree_link(char *name, char *title, char *class, char *head, 209extern void cgit_tree_link(char *name, char *title, char *class, char *head,
208 char *rev, char *path); 210 char *rev, char *path);
209extern void cgit_log_link(char *name, char *title, char *class, char *head, 211extern void cgit_log_link(char *name, char *title, char *class, char *head,
210 char *rev, char *path, int ofs); 212 char *rev, char *path, int ofs);
211extern void cgit_commit_link(char *name, char *title, char *class, char *head, 213extern void cgit_commit_link(char *name, char *title, char *class, char *head,
212 char *rev); 214 char *rev);
213extern void cgit_diff_link(char *name, char *title, char *class, char *head, 215extern void cgit_diff_link(char *name, char *title, char *class, char *head,
214 char *new_rev, char *old_rev, char *path); 216 char *new_rev, char *old_rev, char *path);
215 217
216extern void cgit_print_error(char *msg); 218extern void cgit_print_error(char *msg);
217extern void cgit_print_date(time_t secs, char *format); 219extern void cgit_print_date(time_t secs, char *format);
218extern void cgit_print_age(time_t t, time_t max_relative, char *format); 220extern void cgit_print_age(time_t t, time_t max_relative, char *format);
219extern void cgit_print_docstart(char *title, struct cacheitem *item); 221extern void cgit_print_docstart(char *title, struct cacheitem *item);
220extern void cgit_print_docend(); 222extern void cgit_print_docend();
221extern void cgit_print_pageheader(char *title, int show_search); 223extern void cgit_print_pageheader(char *title, int show_search);
222extern void cgit_print_snapshot_start(const char *mimetype, 224extern void cgit_print_snapshot_start(const char *mimetype,
223 const char *filename, 225 const char *filename,
224 struct cacheitem *item); 226 struct cacheitem *item);
225 227
226extern void cgit_print_repolist(struct cacheitem *item); 228extern void cgit_print_repolist(struct cacheitem *item);
227extern void cgit_print_summary(); 229extern void cgit_print_summary();
228extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); 230extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager);
229extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); 231extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path);
230extern void cgit_print_tree(const char *rev, char *path); 232extern void cgit_print_tree(const char *rev, char *path);
231extern void cgit_print_commit(char *hex); 233extern void cgit_print_commit(char *hex);
232extern void cgit_print_diff(const char *new_hex, const char *old_hex); 234extern void cgit_print_diff(const char *new_hex, const char *old_hex);
233extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, 235extern void cgit_print_snapshot(struct cacheitem *item, const char *hex,
234 const char *prefix, const char *filename); 236 const char *prefix, const char *filename);
235extern void cgit_print_snapshot_links(const char *repo, const char *hex); 237extern void cgit_print_snapshot_links(const char *repo, const char *hex);
236 238
237#endif /* CGIT_H */ 239#endif /* CGIT_H */
diff --git a/ui-shared.c b/ui-shared.c
index d4376ce..1c1415e 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -12,114 +12,121 @@ const char cgit_doctype[] =
12"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" 12"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
13" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; 13" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
14 14
15static char *http_date(time_t t) 15static char *http_date(time_t t)
16{ 16{
17 static char day[][4] = 17 static char day[][4] =
18 {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; 18 {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
19 static char month[][4] = 19 static char month[][4] =
20 {"Jan", "Feb", "Mar", "Apr", "May", "Jun", 20 {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
21 "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; 21 "Jul", "Aug", "Sep", "Oct", "Now", "Dec"};
22 struct tm *tm = gmtime(&t); 22 struct tm *tm = gmtime(&t);
23 return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], 23 return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday],
24 tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, 24 tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year,
25 tm->tm_hour, tm->tm_min, tm->tm_sec); 25 tm->tm_hour, tm->tm_min, tm->tm_sec);
26} 26}
27 27
28static long ttl_seconds(long ttl) 28static long ttl_seconds(long ttl)
29{ 29{
30 if (ttl<0) 30 if (ttl<0)
31 return 60 * 60 * 24 * 365; 31 return 60 * 60 * 24 * 365;
32 else 32 else
33 return ttl * 60; 33 return ttl * 60;
34} 34}
35 35
36void cgit_print_error(char *msg) 36void cgit_print_error(char *msg)
37{ 37{
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
43char *cgit_rooturl() 43char *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
51char *cgit_repourl(const char *reponame) 51char *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
60char *cgit_pageurl(const char *reponame, const char *pagename, 60char *cgit_fileurl(const char *reponame, const char *pagename,
61 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", cgit_virtual_root, reponame, 65 return fmt("%s/%s/%s/%s?%s", cgit_virtual_root, reponame,
66 pagename, 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&amp;p=%s&amp;%s", reponame, pagename, query); 72 return fmt("?r=%s&amp;p=%s&amp;%s", reponame, pagename, query);
73 else 73 else
74 return fmt("?r=%s&amp;p=%s", reponame, pagename); 74 return fmt("?r=%s&amp;p=%s", reponame, pagename);
75 } 75 }
76} 76}
77 77
78char *cgit_pageurl(const char *reponame, const char *pagename,
79 const char *query)
80{
81 return cgit_fileurl(reponame,pagename,0,query);
82}
83
84
78char *cgit_currurl() 85char *cgit_currurl()
79{ 86{
80 if (!cgit_virtual_root) 87 if (!cgit_virtual_root)
81 return cgit_script_name; 88 return cgit_script_name;
82 else if (cgit_query_page) 89 else if (cgit_query_page)
83 return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); 90 return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page);
84 else if (cgit_query_repo) 91 else if (cgit_query_repo)
85 return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); 92 return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo);
86 else 93 else
87 return fmt("%s/", cgit_virtual_root); 94 return fmt("%s/", cgit_virtual_root);
88} 95}
89 96
90static char *repolink(char *title, char *class, char *page, char *head, 97static char *repolink(char *title, char *class, char *page, char *head,
91 char *path) 98 char *path)
92{ 99{
93 char *delim = "?"; 100 char *delim = "?";
94 101
95 html("<a"); 102 html("<a");
96 if (title) { 103 if (title) {
97 html(" title='"); 104 html(" title='");
98 html_attr(title); 105 html_attr(title);
99 html("'"); 106 html("'");
100 } 107 }
101 if (class) { 108 if (class) {
102 html(" class='"); 109 html(" class='");
103 html_attr(class); 110 html_attr(class);
104 html("'"); 111 html("'");
105 } 112 }
106 html(" href='"); 113 html(" href='");
107 if (cgit_virtual_root) { 114 if (cgit_virtual_root) {
108 html_attr(cgit_virtual_root); 115 html_attr(cgit_virtual_root);
109 if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') 116 if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/')
110 html("/"); 117 html("/");
111 html_attr(cgit_repo->url); 118 html_attr(cgit_repo->url);
112 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') 119 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/')
113 html("/"); 120 html("/");
114 if (page) { 121 if (page) {
115 html(page); 122 html(page);
116 html("/"); 123 html("/");
117 if (path) 124 if (path)
118 html_attr(path); 125 html_attr(path);
119 } 126 }
120 } else { 127 } else {
121 html(cgit_script_name); 128 html(cgit_script_name);
122 html("?url="); 129 html("?url=");
123 html_attr(cgit_repo->url); 130 html_attr(cgit_repo->url);
124 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') 131 if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/')
125 html("/"); 132 html("/");
@@ -323,48 +330,50 @@ void cgit_print_pageheader(char *title, int show_search)
323 cgit_tree_link("tree", NULL, NULL, cgit_query_head, 330 cgit_tree_link("tree", NULL, NULL, cgit_query_head,
324 cgit_query_sha1, NULL); 331 cgit_query_sha1, NULL);
325 html(" "); 332 html(" ");
326 cgit_commit_link("commit", NULL, NULL, cgit_query_head, 333 cgit_commit_link("commit", NULL, NULL, cgit_query_head,
327 cgit_query_sha1); 334 cgit_query_sha1);
328 html(" "); 335 html(" ");
329 cgit_diff_link("diff", NULL, NULL, cgit_query_head, 336 cgit_diff_link("diff", NULL, NULL, cgit_query_head,
330 cgit_query_sha1, cgit_query_sha2, 337 cgit_query_sha1, cgit_query_sha2,
331 cgit_query_path); 338 cgit_query_path);
332 } else { 339 } else {
333 html_txt("Index of repositories"); 340 html_txt("Index of repositories");
334 } 341 }
335 html("</td>"); 342 html("</td>");
336 html("<td id='search'>"); 343 html("<td id='search'>");
337 if (show_search) { 344 if (show_search) {
338 html("<form method='get' action='"); 345 html("<form method='get' action='");
339 html_attr(cgit_currurl()); 346 html_attr(cgit_currurl());
340 html("'>"); 347 html("'>");
341 if (!cgit_virtual_root) { 348 if (!cgit_virtual_root) {
342 if (cgit_query_repo) 349 if (cgit_query_repo)
343 html_hidden("r", cgit_query_repo); 350 html_hidden("r", cgit_query_repo);
344 if (cgit_query_page) 351 if (cgit_query_page)
345 html_hidden("p", cgit_query_page); 352 html_hidden("p", cgit_query_page);
346 } 353 }
347 if (cgit_query_head) 354 if (cgit_query_head)
348 html_hidden("h", cgit_query_head); 355 html_hidden("h", cgit_query_head);
349 if (cgit_query_sha1) 356 if (cgit_query_sha1)
350 html_hidden("id", cgit_query_sha1); 357 html_hidden("id", cgit_query_sha1);
351 if (cgit_query_sha2) 358 if (cgit_query_sha2)
352 html_hidden("id2", cgit_query_sha2); 359 html_hidden("id2", cgit_query_sha2);
353 html("<input type='text' name='q' value='"); 360 html("<input type='text' name='q' value='");
354 html_attr(cgit_query_search); 361 html_attr(cgit_query_search);
355 html("'/></form>"); 362 html("'/></form>");
356 } 363 }
357 html("</td></tr>"); 364 html("</td></tr>");
358 html("<tr><td id='content' colspan='2'>"); 365 html("<tr><td id='content' colspan='2'>");
359} 366}
360 367
361void cgit_print_snapshot_start(const char *mimetype, const char *filename, 368void cgit_print_snapshot_start(const char *mimetype, const char *filename,
362 struct cacheitem *item) 369 struct cacheitem *item)
363{ 370{
364 htmlf("Content-Type: %s\n", mimetype); 371 htmlf("Content-Type: %s\n", mimetype);
365 htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); 372 htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename);
366 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); 373 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime));
367 htmlf("Expires: %s\n", http_date(item->st.st_mtime + 374 htmlf("Expires: %s\n", http_date(item->st.st_mtime +
368 ttl_seconds(item->ttl))); 375 ttl_seconds(item->ttl)));
369 html("\n"); 376 html("\n");
370} 377}
378
379/* vim:set sw=8: */
diff --git a/ui-snapshot.c b/ui-snapshot.c
index 84bf8f7..7076b50 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -64,53 +64,53 @@ static const struct snapshot_archive_t {
64 { ".tar", "application/x-tar", write_tar_archive } 64 { ".tar", "application/x-tar", write_tar_archive }
65}; 65};
66 66
67void cgit_print_snapshot(struct cacheitem *item, const char *hex, 67void cgit_print_snapshot(struct cacheitem *item, const char *hex,
68 const char *prefix, const char *filename) 68 const char *prefix, const char *filename)
69{ 69{
70 int fnl = strlen(filename); 70 int fnl = strlen(filename);
71 int f; 71 int f;
72 for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { 72 for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) {
73 const struct snapshot_archive_t* sat = &snapshot_archives[f]; 73 const struct snapshot_archive_t* sat = &snapshot_archives[f];
74 int sl = strlen(sat->suffix); 74 int sl = strlen(sat->suffix);
75 if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix)) 75 if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix))
76 continue; 76 continue;
77 77
78 struct archiver_args args; 78 struct archiver_args args;
79 struct commit *commit; 79 struct commit *commit;
80 unsigned char sha1[20]; 80 unsigned char sha1[20];
81 81
82 if(get_sha1(hex, sha1)) { 82 if(get_sha1(hex, sha1)) {
83 cgit_print_error(fmt("Bad object id: %s", hex)); 83 cgit_print_error(fmt("Bad object id: %s", hex));
84 return; 84 return;
85 } 85 }
86 commit = lookup_commit_reference(sha1); 86 commit = lookup_commit_reference(sha1);
87 87
88 if(!commit) { 88 if(!commit) {
89 cgit_print_error(fmt("Not a commit reference: %s", hex)); 89 cgit_print_error(fmt("Not a commit reference: %s", hex));
90 return;; 90 return;;
91 } 91 }
92 92
93 memset(&args,0,sizeof(args)); 93 memset(&args,0,sizeof(args));
94 args.base = fmt("%s/", prefix); 94 args.base = fmt("%s/", prefix);
95 args.tree = commit->tree; 95 args.tree = commit->tree;
96 96
97 cgit_print_snapshot_start(sat->mimetype, filename, item); 97 cgit_print_snapshot_start(sat->mimetype, filename, item);
98 (*sat->write_func)(&args); 98 (*sat->write_func)(&args);
99 return; 99 return;
100 } 100 }
101 cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); 101 cgit_print_error(fmt("Unsupported snapshot format: %s", filename));
102} 102}
103 103
104void cgit_print_snapshot_links(const char *repo,const char *hex) 104void cgit_print_snapshot_links(const char *repo,const char *hex)
105{ 105{
106 char *filename; 106 char *filename;
107 int f; 107 int f;
108 for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { 108 for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) {
109 const struct snapshot_archive_t* sat = &snapshot_archives[f]; 109 const struct snapshot_archive_t* sat = &snapshot_archives[f];
110 filename = fmt("%s-%s%s",repo,hex,sat->suffix); 110 filename = fmt("%s-%s%s",repo,hex,sat->suffix);
111 htmlf("<a href='%s'>%s</a><br/>", 111 htmlf("<a href='%s'>%s</a><br/>",
112 cgit_pageurl(repo,"snapshot", 112 cgit_fileurl(repo,"snapshot",filename,
113 fmt("id=%s&amp;name=%s",hex,filename)), filename); 113 fmt("id=%s&amp;name=%s",hex,filename)), filename);
114 } 114 }
115} 115}
116/* vim:set sw=8: */ 116/* vim:set sw=8: */