summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2007-07-18 12:40:03 (UTC)
committer Michael Krelin <hacker@klever.net>2007-07-18 12:40:03 (UTC)
commitf97c707a3b975d32910331f72783ec3044e3c0ee (patch) (unidiff)
tree632239a8a644036bd08fbb6f202278de068097b5
parent71ebcbe23ab548e5c0ad40aa8be5741654ed3201 (diff)
downloadcgit-f97c707a3b975d32910331f72783ec3044e3c0ee.zip
cgit-f97c707a3b975d32910331f72783ec3044e3c0ee.tar.gz
cgit-f97c707a3b975d32910331f72783ec3044e3c0ee.tar.bz2
add support for snapshot tarballs
- reworked cgit_print_snapshot to use a list of supported archivers and pick one for the suffix supplied - moved printing of snaphot links into ui-snapshot and make it iterate through the said list
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c2
-rw-r--r--cgit.h4
-rw-r--r--ui-commit.c9
-rw-r--r--ui-snapshot.c77
4 files changed, 55 insertions, 37 deletions
diff --git a/cgit.c b/cgit.c
index 1281bfa..a0f88ad 100644
--- a/cgit.c
+++ b/cgit.c
@@ -65,13 +65,13 @@ static void cgit_print_repo_page(struct cacheitem *item)
65 65
66 title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); 66 title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc);
67 show_search = 0; 67 show_search = 0;
68 setenv("GIT_DIR", cgit_repo->path, 1); 68 setenv("GIT_DIR", cgit_repo->path, 1);
69 69
70 if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) { 70 if ((cgit_cmd == CMD_SNAPSHOT) && cgit_repo->snapshots) {
71 cgit_print_snapshot(item, cgit_query_sha1, "zip", 71 cgit_print_snapshot(item, cgit_query_sha1,
72 cgit_repo->url, cgit_query_name); 72 cgit_repo->url, cgit_query_name);
73 return; 73 return;
74 } 74 }
75 75
76 if (cgit_cmd == CMD_BLOB) { 76 if (cgit_cmd == CMD_BLOB) {
77 cgit_print_blob(item, cgit_query_sha1, cgit_query_path); 77 cgit_print_blob(item, cgit_query_sha1, cgit_query_path);
diff --git a/cgit.h b/cgit.h
index 2ff5340..f01f6c9 100644
--- a/cgit.h
+++ b/cgit.h
@@ -227,10 +227,10 @@ extern void cgit_print_summary();
227extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); 227extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager);
228extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); 228extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path);
229extern void cgit_print_tree(const char *rev, char *path); 229extern void cgit_print_tree(const char *rev, char *path);
230extern void cgit_print_commit(char *hex); 230extern void cgit_print_commit(char *hex);
231extern void cgit_print_diff(const char *new_hex, const char *old_hex); 231extern void cgit_print_diff(const char *new_hex, const char *old_hex);
232extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, 232extern void cgit_print_snapshot(struct cacheitem *item, const char *hex,
233 const char *format, const char *prefix, 233 const char *prefix, const char *filename);
234 const char *filename); 234extern void cgit_print_snapshot_links(const char *repo, const char *hex);
235 235
236#endif /* CGIT_H */ 236#endif /* CGIT_H */
diff --git a/ui-commit.c b/ui-commit.c
index 2679b59..bf5e6dc 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -136,13 +136,12 @@ void inspect_filepair(struct diff_filepair *pair)
136void cgit_print_commit(char *hex) 136void cgit_print_commit(char *hex)
137{ 137{
138 struct commit *commit, *parent; 138 struct commit *commit, *parent;
139 struct commitinfo *info; 139 struct commitinfo *info;
140 struct commit_list *p; 140 struct commit_list *p;
141 unsigned char sha1[20]; 141 unsigned char sha1[20];
142 char *filename;
143 char *tmp; 142 char *tmp;
144 int i; 143 int i;
145 144
146 if (!hex) 145 if (!hex)
147 hex = cgit_query_head; 146 hex = cgit_query_head;
148 curr_rev = hex; 147 curr_rev = hex;
@@ -193,17 +192,15 @@ void cgit_print_commit(char *hex)
193 html(" ("); 192 html(" (");
194 cgit_diff_link("diff", NULL, NULL, cgit_query_head, hex, 193 cgit_diff_link("diff", NULL, NULL, cgit_query_head, hex,
195 sha1_to_hex(p->item->object.sha1), NULL); 194 sha1_to_hex(p->item->object.sha1), NULL);
196 html(")</td></tr>"); 195 html(")</td></tr>");
197 } 196 }
198 if (cgit_repo->snapshots) { 197 if (cgit_repo->snapshots) {
199 htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='"); 198 html("<tr><th>download</th><td colspan='2' class='sha1'>");
200 filename = fmt("%s-%s.zip", cgit_query_repo, hex); 199 cgit_print_snapshot_links(cgit_query_repo,hex);
201 html_attr(cgit_pageurl(cgit_query_repo, "snapshot", 200 html("</td></tr>");
202 fmt("id=%s&amp;name=%s", hex, filename)));
203 htmlf("'>%s</a></td></tr>", filename);
204 } 201 }
205 html("</table>\n"); 202 html("</table>\n");
206 html("<div class='commit-subject'>"); 203 html("<div class='commit-subject'>");
207 html_txt(info->subject); 204 html_txt(info->subject);
208 html("</div>"); 205 html("</div>");
209 html("<div class='commit-msg'>"); 206 html("<div class='commit-msg'>");
diff --git a/ui-snapshot.c b/ui-snapshot.c
index 2257d6b..eb5f1cd 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -5,43 +5,64 @@
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
11static void cgit_print_zip(struct cacheitem *item, const char *hex, 11static const struct snapshot_archive_t {
12 const char *prefix, const char *filename) 12 const char *suffix;
13 const char *mimetype;
14 write_archive_fn_t write_func;
15 }snapshot_archives[] = {
16 { ".zip", "application/x-zip", write_zip_archive },
17 { ".tar.gz", "application/x-gzip", write_tar_archive }
18};
19
20void cgit_print_snapshot(struct cacheitem *item, const char *hex,
21 const char *prefix, const char *filename)
13{ 22{
14 struct archiver_args args; 23 int fnl = strlen(filename);
15 struct commit *commit; 24 int f;
16 unsigned char sha1[20]; 25 for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) {
26 const struct snapshot_archive_t* sat = &snapshot_archives[f];
27 int sl = strlen(sat->suffix);
28 if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix))
29 continue;
17 30
18 if (get_sha1(hex, sha1)) { 31 struct archiver_args args;
19 cgit_print_error(fmt("Bad object id: %s", hex)); 32 struct commit *commit;
20 return; 33 unsigned char sha1[20];
21 } 34
22 commit = lookup_commit_reference(sha1); 35 if(get_sha1(hex, sha1)) {
36 cgit_print_error(fmt("Bad object id: %s", hex));
37 return;
38 }
39 commit = lookup_commit_reference(sha1);
40
41 if(!commit) {
42 cgit_print_error(fmt("Not a commit reference: %s", hex));
43 return;;
44 }
23 45
24 if (!commit) { 46 memset(&args,0,sizeof(args));
25 cgit_print_error(fmt("Not a commit reference: %s", hex)); 47 args.base = fmt("%s/", prefix);
48 args.tree = commit->tree;
49
50 cgit_print_snapshot_start(sat->mimetype, filename, item);
51 (*sat->write_func)(&args);
26 return; 52 return;
27 } 53 }
28 54 cgit_print_error(fmt("Unsupported snapshot format: %s", filename));
29 memset(&args, 0, sizeof(args));
30 args.base = fmt("%s/", prefix);
31 args.tree = commit->tree;
32
33 cgit_print_snapshot_start("application/x-zip", filename, item);
34 write_zip_archive(&args);
35} 55}
36 56
37 57void cgit_print_snapshot_links(const char *repo,const char *hex)
38void cgit_print_snapshot(struct cacheitem *item, const char *hex,
39 const char *format, const char *prefix,
40 const char *filename)
41{ 58{
42 if (!strcmp(format, "zip")) 59 char *filename;
43 cgit_print_zip(item, hex, prefix, filename); 60 int f;
44 else 61 for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) {
45 cgit_print_error(fmt("Unsupported snapshot format: %s", 62 const struct snapshot_archive_t* sat = &snapshot_archives[f];
46 format)); 63 filename = fmt("%s-%s%s",repo,hex,sat->suffix);
64 htmlf("<a href='%s'>%s</a><br/>",
65 cgit_pageurl(repo,"snapshot",
66 fmt("id=%s&amp;name=%s",hex,filename)), filename);
67 }
47} 68}