summaryrefslogtreecommitdiffabout
path: root/ui-snapshot.c
Unidiff
Diffstat (limited to 'ui-snapshot.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-snapshot.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/ui-snapshot.c b/ui-snapshot.c
index d6be55b..f9879ed 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -56,75 +56,85 @@ static int write_tar_bzip2_archive(struct archiver_args *args)
56static const struct snapshot_archive_t { 56static const struct snapshot_archive_t {
57 const char *suffix; 57 const char *suffix;
58 const char *mimetype; 58 const char *mimetype;
59 write_archive_fn_t write_func; 59 write_archive_fn_t write_func;
60 int bit; 60 int bit;
61 }snapshot_archives[] = { 61 }snapshot_archives[] = {
62 { ".zip", "application/x-zip", write_zip_archive, 0x1 }, 62 { ".zip", "application/x-zip", write_zip_archive, 0x1 },
63 { ".tar.gz", "application/x-tar", write_tar_gzip_archive, 0x2 }, 63 { ".tar.gz", "application/x-tar", write_tar_gzip_archive, 0x2 },
64 { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive, 0x4 }, 64 { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive, 0x4 },
65 { ".tar", "application/x-tar", write_tar_archive, 0x8 } 65 { ".tar", "application/x-tar", write_tar_archive, 0x8 }
66}; 66};
67 67
68void cgit_print_snapshot(struct cacheitem *item, const char *hex, 68void cgit_print_snapshot(struct cacheitem *item, const char *head,
69 const char *prefix, const char *filename, 69 const char *hex, const char *prefix,
70 int snapshots) 70 const char *filename, int snapshots)
71{ 71{
72 int fnl = strlen(filename); 72 int fnl = strlen(filename);
73 int f; 73 int f, n;
74 for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { 74
75 n = sizeof(snapshot_archives) / sizeof(*snapshot_archives);
76 for(f=0; f<n; f++) {
75 const struct snapshot_archive_t* sat = &snapshot_archives[f]; 77 const struct snapshot_archive_t* sat = &snapshot_archives[f];
76 int sl; 78 int sl;
77 if(!(snapshots&sat->bit)) continue; 79 if(!(snapshots & sat->bit))
80 continue;
78 sl = strlen(sat->suffix); 81 sl = strlen(sat->suffix);
79 if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix)) 82 if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix))
80 continue; 83 continue;
81 84
82 struct archiver_args args; 85 struct archiver_args args;
83 struct commit *commit; 86 struct commit *commit;
84 unsigned char sha1[20]; 87 unsigned char sha1[20];
85 88
89 if (!hex)
90 hex = head;
86 if(get_sha1(hex, sha1)) { 91 if(get_sha1(hex, sha1)) {
87 cgit_print_error(fmt("Bad object id: %s", hex)); 92 cgit_print_error(fmt("Bad object id: %s", hex));
88 return; 93 return;
89 } 94 }
90 commit = lookup_commit_reference(sha1); 95 commit = lookup_commit_reference(sha1);
91 96
92 if(!commit) { 97 if(!commit) {
93 cgit_print_error(fmt("Not a commit reference: %s", hex)); 98 cgit_print_error(fmt("Not a commit reference: %s", hex));
94 return;; 99 return;;
95 } 100 }
96 101
97 memset(&args,0,sizeof(args)); 102 memset(&args,0,sizeof(args));
98 args.base = fmt("%s/", prefix); 103 args.base = fmt("%s/", prefix);
99 args.tree = commit->tree; 104 args.tree = commit->tree;
100 105
101 cgit_print_snapshot_start(sat->mimetype, filename, item); 106 cgit_print_snapshot_start(sat->mimetype, filename, item);
102 (*sat->write_func)(&args); 107 (*sat->write_func)(&args);
103 return; 108 return;
104 } 109 }
105 cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); 110 cgit_print_error(fmt("Unsupported snapshot format: %s", filename));
106} 111}
107 112
108void cgit_print_snapshot_links(const char *repo,const char *hex,int snapshots) 113void cgit_print_snapshot_links(const char *repo, const char *head,
114 const char *hex, int snapshots)
109{ 115{
110 char *filename; 116 char *filename;
111 int f; 117 int f, n;
112 for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { 118
119 n = sizeof(snapshot_archives) / sizeof(*snapshot_archives);
120 for(f=0; f<n ;f++) {
113 const struct snapshot_archive_t* sat = &snapshot_archives[f]; 121 const struct snapshot_archive_t* sat = &snapshot_archives[f];
114 if(!(snapshots&sat->bit)) continue; 122 if(!(snapshots & sat->bit))
115 filename = fmt("%s-%s%s",cgit_repobasename(repo),hex,sat->suffix); 123 continue;
116 htmlf("<a href='%s'>%s</a><br/>", 124 filename = fmt("%s-%s%s", cgit_repobasename(repo), hex,
117 cgit_fileurl(repo,"snapshot",filename, 125 sat->suffix);
118 fmt("id=%s&amp;name=%s",hex,filename)), filename); 126 cgit_snapshot_link(filename, NULL, NULL, (char *)head,
127 (char *)hex, filename);
128 html("<br/>");
119 } 129 }
120} 130}
121 131
122int cgit_parse_snapshots_mask(const char *str) 132int cgit_parse_snapshots_mask(const char *str)
123{ 133{
124 static const char *delim = " \t,:/|;"; 134 static const char *delim = " \t,:/|;";
125 int f, tl, rv = 0; 135 int f, tl, rv = 0;
126 /* favor legacy setting */ 136 /* favor legacy setting */
127 if(atoi(str)) return 1; 137 if(atoi(str)) return 1;
128 for(;;) { 138 for(;;) {
129 str += strspn(str,delim); 139 str += strspn(str,delim);
130 tl = strcspn(str,delim); 140 tl = strcspn(str,delim);