aboutsummaryrefslogtreecommitdiffstats
path: root/ui-snapshot.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui-snapshot.c')
-rw-r--r--ui-snapshot.c43
1 files changed, 36 insertions, 7 deletions
diff --git a/ui-snapshot.c b/ui-snapshot.c
index 053fd48..d6be55b 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -57,21 +57,25 @@ static 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} snapshot_archives[] = { 61} snapshot_archives[] = {
61 { ".zip", "application/x-zip", write_zip_archive }, 62 { ".zip", "application/x-zip", write_zip_archive, 0x1 },
62 { ".tar.gz", "application/x-tar", write_tar_gzip_archive }, 63 { ".tar.gz", "application/x-tar", write_tar_gzip_archive, 0x2 },
63 { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive }, 64 { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive, 0x4 },
64 { ".tar", "application/x-tar", write_tar_archive } 65 { ".tar", "application/x-tar", write_tar_archive, 0x8 }
65}; 66};
66 67
67void cgit_print_snapshot(struct cacheitem *item, const char *hex, 68void cgit_print_snapshot(struct cacheitem *item, const char *hex,
68 const char *prefix, const char *filename) 69 const char *prefix, const char *filename,
70 int snapshots)
69{ 71{
70 int fnl = strlen(filename); 72 int fnl = strlen(filename);
71 int f; 73 int f;
72 for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { 74 for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) {
73 const struct snapshot_archive_t* sat = &snapshot_archives[f]; 75 const struct snapshot_archive_t* sat = &snapshot_archives[f];
74 int sl = strlen(sat->suffix); 76 int sl;
77 if(!(snapshots&sat->bit)) continue;
78 sl = strlen(sat->suffix);
75 if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix)) 79 if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix))
76 continue; 80 continue;
77 81
@@ -101,16 +105,41 @@ void cgit_print_snapshot(struct cacheitem *item, const char *hex,
101 cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); 105 cgit_print_error(fmt("Unsupported snapshot format: %s", filename));
102} 106}
103 107
104void cgit_print_snapshot_links(const char *repo,const char *hex) 108void cgit_print_snapshot_links(const char *repo,const char *hex,int snapshots)
105{ 109{
106 char *filename; 110 char *filename;
107 int f; 111 int f;
108 for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { 112 for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) {
109 const struct snapshot_archive_t* sat = &snapshot_archives[f]; 113 const struct snapshot_archive_t* sat = &snapshot_archives[f];
114 if(!(snapshots&sat->bit)) continue;
110 filename = fmt("%s-%s%s",cgit_repobasename(repo),hex,sat->suffix); 115 filename = fmt("%s-%s%s",cgit_repobasename(repo),hex,sat->suffix);
111 htmlf("<a href='%s'>%s</a><br/>", 116 htmlf("<a href='%s'>%s</a><br/>",
112 cgit_fileurl(repo,"snapshot",filename, 117 cgit_fileurl(repo,"snapshot",filename,
113 fmt("id=%s&amp;name=%s",hex,filename)), filename); 118 fmt("id=%s&amp;name=%s",hex,filename)), filename);
114 } 119 }
115} 120}
121
122int cgit_parse_snapshots_mask(const char *str)
123{
124 static const char *delim = " \t,:/|;";
125 int f, tl, rv = 0;
126 /* favor legacy setting */
127 if(atoi(str)) return 1;
128 for(;;) {
129 str += strspn(str,delim);
130 tl = strcspn(str,delim);
131 if(!tl)
132 break;
133 for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) {
134 const struct snapshot_archive_t* sat = &snapshot_archives[f];
135 if(! ( strncmp(sat->suffix,str,tl) && strncmp(sat->suffix+1,str,tl-1) ) ) {
136 rv |= sat->bit;
137 break;
138 }
139 }
140 str += tl;
141 }
142 return rv;
143}
144
116/* vim:set sw=8: */ 145/* vim:set sw=8: */