aboutsummaryrefslogtreecommitdiffstats
path: root/ui-snapshot.c
diff options
context:
space:
mode:
authorGravatar Michael Krelin <hacker@klever.net>2007-07-18 21:40:03 (JST)
committerGravatar Michael Krelin <hacker@klever.net>2007-07-18 21:40:03 (JST)
commitf97c707a3b975d32910331f72783ec3044e3c0ee (patch)
tree632239a8a644036bd08fbb6f202278de068097b5 /ui-snapshot.c
parent71ebcbe23ab548e5c0ad40aa8be5741654ed3201 (diff)
downloadcgit-f97c707a3b975d32910331f72783ec3044e3c0ee.zip
cgit-f97c707a3b975d32910331f72783ec3044e3c0ee.tar.gz
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 (limited to 'ui-snapshot.c')
-rw-r--r--ui-snapshot.c77
1 files changed, 49 insertions, 28 deletions
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
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}