-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
@@ -70,3 +70,3 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
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); |
@@ -232,4 +232,4 @@ 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 | ||
diff --git a/ui-commit.c b/ui-commit.c index 2679b59..bf5e6dc 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -141,3 +141,2 @@ void cgit_print_commit(char *hex) | |||
141 | unsigned char sha1[20]; | 141 | unsigned char sha1[20]; |
142 | char *filename; | ||
143 | char *tmp; | 142 | char *tmp; |
@@ -198,7 +197,5 @@ void cgit_print_commit(char *hex) | |||
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 | } |
diff --git a/ui-snapshot.c b/ui-snapshot.c index 2257d6b..eb5f1cd 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c | |||
@@ -10,38 +10,59 @@ | |||
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 | } |