1 /* ui-snapshot.c: generate snapshot of a commit
3 * Copyright (C) 2006 Lars Hjemli
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
11 static const struct snapshot_archive_t {
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 }
20 void cgit_print_snapshot(struct cacheitem *item, const char *hex,
21 const char *prefix, const char *filename)
23 int fnl = strlen(filename);
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))
31 struct archiver_args args;
32 struct commit *commit;
33 unsigned char sha1[20];
35 if(get_sha1(hex, sha1)) {
36 cgit_print_error(fmt("Bad object id: %s", hex));
39 commit = lookup_commit_reference(sha1);
42 cgit_print_error(fmt("Not a commit reference: %s", hex));
46 memset(&args,0,sizeof(args));
47 args.base = fmt("%s/", prefix);
48 args.tree = commit->tree;
50 cgit_print_snapshot_start(sat->mimetype, filename, item);
51 (*sat->write_func)(&args);
54 cgit_print_error(fmt("Unsupported snapshot format: %s", filename));
57 void cgit_print_snapshot_links(const char *repo,const char *hex)
61 for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) {
62 const struct snapshot_archive_t* sat = &snapshot_archives[f];
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);