diff options
-rw-r--r-- | cgit.c | 2 | ||||
-rw-r--r-- | cgit.h | 4 | ||||
-rw-r--r-- | ui-commit.c | 9 | ||||
-rw-r--r-- | ui-snapshot.c | 77 |
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 | |||
@@ -68,7 +68,7 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
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 | } |
diff --git a/cgit.h b/cgit.h index 2ff5340..f01f6c9 100644 --- a/cgit.h +++ b/cgit.h | |||
@@ -230,7 +230,7 @@ extern void cgit_print_tree(const char *rev, char *path); | |||
230 | extern void cgit_print_commit(char *hex); | 230 | extern void cgit_print_commit(char *hex); |
231 | extern void cgit_print_diff(const char *new_hex, const char *old_hex); | 231 | extern void cgit_print_diff(const char *new_hex, const char *old_hex); |
232 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, | 232 | extern 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); | 234 | extern 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 | |||
@@ -139,7 +139,6 @@ void cgit_print_commit(char *hex) | |||
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 | ||
@@ -196,11 +195,9 @@ void cgit_print_commit(char *hex) | |||
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&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'>"); |
diff --git a/ui-snapshot.c b/ui-snapshot.c index 2257d6b..eb5f1cd 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c | |||
@@ -8,40 +8,61 @@ | |||
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | static void cgit_print_zip(struct cacheitem *item, const char *hex, | 11 | static 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 | |||
20 | void 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 | 57 | void cgit_print_snapshot_links(const char *repo,const char *hex) | |
38 | void 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&name=%s",hex,filename)), filename); | ||
67 | } | ||
47 | } | 68 | } |