author | Michael Krelin <hacker@klever.net> | 2007-07-21 16:00:53 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-21 16:00:53 (UTC) |
commit | dc3c9b5bc48779f37f2fbcbadce8865eaf4a360e (patch) (unidiff) | |
tree | e42607f85bfb3ca33dff761a3966c502cdd6868e | |
parent | 97c025ae8ecf9764fd6996c81c51c3de4adb837c (diff) | |
download | cgit-dc3c9b5bc48779f37f2fbcbadce8865eaf4a360e.zip cgit-dc3c9b5bc48779f37f2fbcbadce8865eaf4a360e.tar.gz cgit-dc3c9b5bc48779f37f2fbcbadce8865eaf4a360e.tar.bz2 |
allow selective enabling of snapshots
snapshot configuration parameter now can be a
space/slash/comma/colon/semicolon/pipe-separated list of snaphot suffixes as
listed in ui-snapshot.c
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | cgit.c | 3 | ||||
-rw-r--r-- | cgit.h | 6 | ||||
-rw-r--r-- | cgitrc | 5 | ||||
-rw-r--r-- | shared.c | 4 | ||||
-rw-r--r-- | ui-commit.c | 2 | ||||
-rw-r--r-- | ui-snapshot.c | 43 |
6 files changed, 48 insertions, 15 deletions
@@ -57,33 +57,34 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
57 | title = fmt("%s - %s", cgit_root_title, "Bad request"); | 57 | title = fmt("%s - %s", cgit_root_title, "Bad request"); |
58 | cgit_print_docstart(title, item); | 58 | cgit_print_docstart(title, item); |
59 | cgit_print_pageheader(title, 0); | 59 | cgit_print_pageheader(title, 0); |
60 | cgit_print_error(fmt("Unable to scan repository: %s", | 60 | cgit_print_error(fmt("Unable to scan repository: %s", |
61 | strerror(errno))); | 61 | strerror(errno))); |
62 | cgit_print_docend(); | 62 | cgit_print_docend(); |
63 | return; | 63 | return; |
64 | } | 64 | } |
65 | 65 | ||
66 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); | 66 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); |
67 | show_search = 0; | 67 | show_search = 0; |
68 | setenv("GIT_DIR", cgit_repo->path, 1); | 68 | setenv("GIT_DIR", cgit_repo->path, 1); |
69 | 69 | ||
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, | 71 | cgit_print_snapshot(item, cgit_query_sha1, |
72 | cgit_repobasename(cgit_repo->url), | 72 | cgit_repobasename(cgit_repo->url), |
73 | cgit_query_name); | 73 | cgit_query_name, |
74 | cgit_repo->snapshots ); | ||
74 | return; | 75 | return; |
75 | } | 76 | } |
76 | 77 | ||
77 | if (cgit_cmd == CMD_BLOB) { | 78 | if (cgit_cmd == CMD_BLOB) { |
78 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); | 79 | cgit_print_blob(item, cgit_query_sha1, cgit_query_path); |
79 | return; | 80 | return; |
80 | } | 81 | } |
81 | 82 | ||
82 | show_search = (cgit_cmd == CMD_LOG); | 83 | show_search = (cgit_cmd == CMD_LOG); |
83 | cgit_print_docstart(title, item); | 84 | cgit_print_docstart(title, item); |
84 | if (!cgit_cmd) { | 85 | if (!cgit_cmd) { |
85 | cgit_print_pageheader("summary", show_search); | 86 | cgit_print_pageheader("summary", show_search); |
86 | cgit_print_summary(); | 87 | cgit_print_summary(); |
87 | cgit_print_docend(); | 88 | cgit_print_docend(); |
88 | return; | 89 | return; |
89 | } | 90 | } |
@@ -222,20 +222,22 @@ extern void cgit_print_date(time_t secs, char *format); | |||
222 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 222 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
223 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 223 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
224 | extern void cgit_print_docend(); | 224 | extern void cgit_print_docend(); |
225 | extern void cgit_print_pageheader(char *title, int show_search); | 225 | extern void cgit_print_pageheader(char *title, int show_search); |
226 | extern void cgit_print_snapshot_start(const char *mimetype, | 226 | extern void cgit_print_snapshot_start(const char *mimetype, |
227 | const char *filename, | 227 | const char *filename, |
228 | struct cacheitem *item); | 228 | struct cacheitem *item); |
229 | 229 | ||
230 | extern void cgit_print_repolist(struct cacheitem *item); | 230 | extern void cgit_print_repolist(struct cacheitem *item); |
231 | extern void cgit_print_summary(); | 231 | extern void cgit_print_summary(); |
232 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); | 232 | extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager); |
233 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); | 233 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
234 | extern void cgit_print_tree(const char *rev, char *path); | 234 | extern void cgit_print_tree(const char *rev, char *path); |
235 | extern void cgit_print_commit(char *hex); | 235 | extern void cgit_print_commit(char *hex); |
236 | extern void cgit_print_diff(const char *new_hex, const char *old_hex); | 236 | extern void cgit_print_diff(const char *new_hex, const char *old_hex); |
237 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, | 237 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, |
238 | const char *prefix, const char *filename); | 238 | const char *prefix, const char *filename, |
239 | extern void cgit_print_snapshot_links(const char *repo, const char *hex); | 239 | int snapshot); |
240 | extern void cgit_print_snapshot_links(const char *repo, const char *hex,int snapshots); | ||
241 | extern int cgit_parse_snapshots_mask(const char *str); | ||
240 | 242 | ||
241 | #endif /* CGIT_H */ | 243 | #endif /* CGIT_H */ |
@@ -1,27 +1,28 @@ | |||
1 | ## | 1 | ## |
2 | ## cgitrc: template for /etc/cgitrc | 2 | ## cgitrc: template for /etc/cgitrc |
3 | ## | 3 | ## |
4 | 4 | ||
5 | 5 | ||
6 | ## Uncomment and set to 1 to deactivate caching of generated pages. Mostly | 6 | ## Uncomment and set to 1 to deactivate caching of generated pages. Mostly |
7 | ## usefull for testing. | 7 | ## usefull for testing. |
8 | #nocache=0 | 8 | #nocache=0 |
9 | 9 | ||
10 | 10 | ||
11 | ## Enable/disable snapshots by default. This can be overridden per repo | 11 | ## Set allowed snapshot types by default. Can be overridden per repo |
12 | # can be any combination of zip/tar.gz/tar.bz2/tar | ||
12 | #snapshots=0 | 13 | #snapshots=0 |
13 | 14 | ||
14 | 15 | ||
15 | ## Enable/disable extra links to summary/log/tree per repo on index page | 16 | ## Enable/disable extra links to summary/log/tree per repo on index page |
16 | #enable-index-links=0 | 17 | #enable-index-links=0 |
17 | 18 | ||
18 | 19 | ||
19 | ## Enable/disable display of 'number of files changed' in log view | 20 | ## Enable/disable display of 'number of files changed' in log view |
20 | #enable-log-filecount=0 | 21 | #enable-log-filecount=0 |
21 | 22 | ||
22 | 23 | ||
23 | ## Enable/disable display of 'number of lines changed' in log view | 24 | ## Enable/disable display of 'number of lines changed' in log view |
24 | #enable-log-linecount=0 | 25 | #enable-log-linecount=0 |
25 | 26 | ||
26 | 27 | ||
27 | ## Enable/disable display of HEAD shortlog in summary view. Set it to maximum | 28 | ## Enable/disable display of HEAD shortlog in summary view. Set it to maximum |
@@ -100,21 +101,21 @@ | |||
100 | 101 | ||
101 | ## ttl for other dynamic pages | 102 | ## ttl for other dynamic pages |
102 | #cache-dynamic-ttl=5 | 103 | #cache-dynamic-ttl=5 |
103 | 104 | ||
104 | ## ttl for static pages (addressed by SHA-1) | 105 | ## ttl for static pages (addressed by SHA-1) |
105 | #cache-static-ttl=-1 | 106 | #cache-static-ttl=-1 |
106 | 107 | ||
107 | 108 | ||
108 | 109 | ||
109 | ## Example repository entry. Required values are repo.url and repo.path (each | 110 | ## Example repository entry. Required values are repo.url and repo.path (each |
110 | ## repository section must start with repo.url). | 111 | ## repository section must start with repo.url). |
111 | #repo.url=cgit | 112 | #repo.url=cgit |
112 | #repo.name=cgit | 113 | #repo.name=cgit |
113 | #repo.desc=the caching cgi for git | 114 | #repo.desc=the caching cgi for git |
114 | #repo.path=/pub/git/cgit | 115 | #repo.path=/pub/git/cgit |
115 | #repo.owner=Lars Hjemli | 116 | #repo.owner=Lars Hjemli |
116 | #repo.snapshots=1 # override a sitewide snapshot-setting | 117 | #repo.snapshots=tar.bz2 # override a sitewide snapshot-setting |
117 | #repo.enable-log-filecount=0 # override the default filecount setting | 118 | #repo.enable-log-filecount=0 # override the default filecount setting |
118 | #repo.enable-log-linecount=0 # override the default linecount setting | 119 | #repo.enable-log-linecount=0 # override the default linecount setting |
119 | #repo.module-link=/git/%s/commit/?id=%s # override the standard module-link | 120 | #repo.module-link=/git/%s/commit/?id=%s # override the standard module-link |
120 | #repo.readme=info/web/readme # specify a file to include on summary page | 121 | #repo.readme=info/web/readme # specify a file to include on summary page |
@@ -142,33 +142,33 @@ void cgit_global_config_cb(const char *name, const char *value) | |||
142 | cgit_root_title = xstrdup(value); | 142 | cgit_root_title = xstrdup(value); |
143 | else if (!strcmp(name, "css")) | 143 | else if (!strcmp(name, "css")) |
144 | cgit_css = xstrdup(value); | 144 | cgit_css = xstrdup(value); |
145 | else if (!strcmp(name, "logo")) | 145 | else if (!strcmp(name, "logo")) |
146 | cgit_logo = xstrdup(value); | 146 | cgit_logo = xstrdup(value); |
147 | else if (!strcmp(name, "index-header")) | 147 | else if (!strcmp(name, "index-header")) |
148 | cgit_index_header = xstrdup(value); | 148 | cgit_index_header = xstrdup(value); |
149 | else if (!strcmp(name, "logo-link")) | 149 | else if (!strcmp(name, "logo-link")) |
150 | cgit_logo_link = xstrdup(value); | 150 | cgit_logo_link = xstrdup(value); |
151 | else if (!strcmp(name, "module-link")) | 151 | else if (!strcmp(name, "module-link")) |
152 | cgit_module_link = xstrdup(value); | 152 | cgit_module_link = xstrdup(value); |
153 | else if (!strcmp(name, "virtual-root")) | 153 | else if (!strcmp(name, "virtual-root")) |
154 | cgit_virtual_root = xstrdup(value); | 154 | cgit_virtual_root = xstrdup(value); |
155 | else if (!strcmp(name, "nocache")) | 155 | else if (!strcmp(name, "nocache")) |
156 | cgit_nocache = atoi(value); | 156 | cgit_nocache = atoi(value); |
157 | else if (!strcmp(name, "snapshots")) | 157 | else if (!strcmp(name, "snapshots")) |
158 | cgit_snapshots = atoi(value); | 158 | cgit_snapshots = cgit_parse_snapshots_mask(value); |
159 | else if (!strcmp(name, "enable-index-links")) | 159 | else if (!strcmp(name, "enable-index-links")) |
160 | cgit_enable_index_links = atoi(value); | 160 | cgit_enable_index_links = atoi(value); |
161 | else if (!strcmp(name, "enable-log-filecount")) | 161 | else if (!strcmp(name, "enable-log-filecount")) |
162 | cgit_enable_log_filecount = atoi(value); | 162 | cgit_enable_log_filecount = atoi(value); |
163 | else if (!strcmp(name, "enable-log-linecount")) | 163 | else if (!strcmp(name, "enable-log-linecount")) |
164 | cgit_enable_log_linecount = atoi(value); | 164 | cgit_enable_log_linecount = atoi(value); |
165 | else if (!strcmp(name, "cache-root")) | 165 | else if (!strcmp(name, "cache-root")) |
166 | cgit_cache_root = xstrdup(value); | 166 | cgit_cache_root = xstrdup(value); |
167 | else if (!strcmp(name, "cache-root-ttl")) | 167 | else if (!strcmp(name, "cache-root-ttl")) |
168 | cgit_cache_root_ttl = atoi(value); | 168 | cgit_cache_root_ttl = atoi(value); |
169 | else if (!strcmp(name, "cache-repo-ttl")) | 169 | else if (!strcmp(name, "cache-repo-ttl")) |
170 | cgit_cache_repo_ttl = atoi(value); | 170 | cgit_cache_repo_ttl = atoi(value); |
171 | else if (!strcmp(name, "cache-static-ttl")) | 171 | else if (!strcmp(name, "cache-static-ttl")) |
172 | cgit_cache_static_ttl = atoi(value); | 172 | cgit_cache_static_ttl = atoi(value); |
173 | else if (!strcmp(name, "cache-dynamic-ttl")) | 173 | else if (!strcmp(name, "cache-dynamic-ttl")) |
174 | cgit_cache_dynamic_ttl = atoi(value); | 174 | cgit_cache_dynamic_ttl = atoi(value); |
@@ -184,33 +184,33 @@ void cgit_global_config_cb(const char *name, const char *value) | |||
184 | cgit_agefile = xstrdup(value); | 184 | cgit_agefile = xstrdup(value); |
185 | else if (!strcmp(name, "repo.group")) | 185 | else if (!strcmp(name, "repo.group")) |
186 | cgit_repo_group = xstrdup(value); | 186 | cgit_repo_group = xstrdup(value); |
187 | else if (!strcmp(name, "repo.url")) | 187 | else if (!strcmp(name, "repo.url")) |
188 | cgit_repo = add_repo(value); | 188 | cgit_repo = add_repo(value); |
189 | else if (!strcmp(name, "repo.name")) | 189 | else if (!strcmp(name, "repo.name")) |
190 | cgit_repo->name = xstrdup(value); | 190 | cgit_repo->name = xstrdup(value); |
191 | else if (cgit_repo && !strcmp(name, "repo.path")) | 191 | else if (cgit_repo && !strcmp(name, "repo.path")) |
192 | cgit_repo->path = xstrdup(value); | 192 | cgit_repo->path = xstrdup(value); |
193 | else if (cgit_repo && !strcmp(name, "repo.desc")) | 193 | else if (cgit_repo && !strcmp(name, "repo.desc")) |
194 | cgit_repo->desc = xstrdup(value); | 194 | cgit_repo->desc = xstrdup(value); |
195 | else if (cgit_repo && !strcmp(name, "repo.owner")) | 195 | else if (cgit_repo && !strcmp(name, "repo.owner")) |
196 | cgit_repo->owner = xstrdup(value); | 196 | cgit_repo->owner = xstrdup(value); |
197 | else if (cgit_repo && !strcmp(name, "repo.defbranch")) | 197 | else if (cgit_repo && !strcmp(name, "repo.defbranch")) |
198 | cgit_repo->defbranch = xstrdup(value); | 198 | cgit_repo->defbranch = xstrdup(value); |
199 | else if (cgit_repo && !strcmp(name, "repo.snapshots")) | 199 | else if (cgit_repo && !strcmp(name, "repo.snapshots")) |
200 | cgit_repo->snapshots = cgit_snapshots * atoi(value); | 200 | cgit_repo->snapshots = cgit_snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ |
201 | else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount")) | 201 | else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount")) |
202 | cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value); | 202 | cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value); |
203 | else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount")) | 203 | else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount")) |
204 | cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value); | 204 | cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value); |
205 | else if (cgit_repo && !strcmp(name, "repo.module-link")) | 205 | else if (cgit_repo && !strcmp(name, "repo.module-link")) |
206 | cgit_repo->module_link= xstrdup(value); | 206 | cgit_repo->module_link= xstrdup(value); |
207 | else if (cgit_repo && !strcmp(name, "repo.readme") && value != NULL) { | 207 | else if (cgit_repo && !strcmp(name, "repo.readme") && value != NULL) { |
208 | if (*value == '/') | 208 | if (*value == '/') |
209 | cgit_repo->readme = xstrdup(value); | 209 | cgit_repo->readme = xstrdup(value); |
210 | else | 210 | else |
211 | cgit_repo->readme = xstrdup(fmt("%s/%s", cgit_repo->path, value)); | 211 | cgit_repo->readme = xstrdup(fmt("%s/%s", cgit_repo->path, value)); |
212 | } else if (!strcmp(name, "include")) | 212 | } else if (!strcmp(name, "include")) |
213 | cgit_read_config(value, cgit_global_config_cb); | 213 | cgit_read_config(value, cgit_global_config_cb); |
214 | } | 214 | } |
215 | 215 | ||
216 | void cgit_querystring_cb(const char *name, const char *value) | 216 | void cgit_querystring_cb(const char *name, const char *value) |
diff --git a/ui-commit.c b/ui-commit.c index bf5e6dc..50e9e11 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -183,33 +183,33 @@ void cgit_print_commit(char *hex) | |||
183 | html("<tr><td colspan='3'>"); | 183 | html("<tr><td colspan='3'>"); |
184 | cgit_print_error("Error reading parent commit"); | 184 | cgit_print_error("Error reading parent commit"); |
185 | html("</td></tr>"); | 185 | html("</td></tr>"); |
186 | continue; | 186 | continue; |
187 | } | 187 | } |
188 | html("<tr><th>parent</th>" | 188 | html("<tr><th>parent</th>" |
189 | "<td colspan='2' class='sha1'>"); | 189 | "<td colspan='2' class='sha1'>"); |
190 | cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, | 190 | cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, |
191 | cgit_query_head, sha1_to_hex(p->item->object.sha1)); | 191 | cgit_query_head, sha1_to_hex(p->item->object.sha1)); |
192 | html(" ("); | 192 | html(" ("); |
193 | cgit_diff_link("diff", NULL, NULL, cgit_query_head, hex, | 193 | cgit_diff_link("diff", NULL, NULL, cgit_query_head, hex, |
194 | sha1_to_hex(p->item->object.sha1), NULL); | 194 | sha1_to_hex(p->item->object.sha1), NULL); |
195 | html(")</td></tr>"); | 195 | html(")</td></tr>"); |
196 | } | 196 | } |
197 | if (cgit_repo->snapshots) { | 197 | if (cgit_repo->snapshots) { |
198 | html("<tr><th>download</th><td colspan='2' class='sha1'>"); | 198 | html("<tr><th>download</th><td colspan='2' class='sha1'>"); |
199 | cgit_print_snapshot_links(cgit_query_repo,hex); | 199 | cgit_print_snapshot_links(cgit_query_repo,hex,cgit_repo->snapshots); |
200 | html("</td></tr>"); | 200 | html("</td></tr>"); |
201 | } | 201 | } |
202 | html("</table>\n"); | 202 | html("</table>\n"); |
203 | html("<div class='commit-subject'>"); | 203 | html("<div class='commit-subject'>"); |
204 | html_txt(info->subject); | 204 | html_txt(info->subject); |
205 | html("</div>"); | 205 | html("</div>"); |
206 | html("<div class='commit-msg'>"); | 206 | html("<div class='commit-msg'>"); |
207 | html_txt(info->msg); | 207 | html_txt(info->msg); |
208 | html("</div>"); | 208 | html("</div>"); |
209 | if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { | 209 | if (!(commit->parents && commit->parents->next && commit->parents->next->next)) { |
210 | html("<div class='diffstat-header'>Diffstat</div>"); | 210 | html("<div class='diffstat-header'>Diffstat</div>"); |
211 | html("<table class='diffstat'>"); | 211 | html("<table class='diffstat'>"); |
212 | max_changes = 0; | 212 | max_changes = 0; |
213 | cgit_diff_commit(commit, inspect_filepair); | 213 | cgit_diff_commit(commit, inspect_filepair); |
214 | for(i = 0; i<files; i++) | 214 | for(i = 0; i<files; i++) |
215 | print_fileinfo(&items[i]); | 215 | print_fileinfo(&items[i]); |
diff --git a/ui-snapshot.c b/ui-snapshot.c index 053fd48..d6be55b 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c | |||
@@ -44,73 +44,102 @@ static int write_compressed_tar_archive(struct archiver_args *args,const char *f | |||
44 | return rv; | 44 | return rv; |
45 | } | 45 | } |
46 | 46 | ||
47 | static int write_tar_gzip_archive(struct archiver_args *args) | 47 | static int write_tar_gzip_archive(struct archiver_args *args) |
48 | { | 48 | { |
49 | return write_compressed_tar_archive(args,"gzip"); | 49 | return write_compressed_tar_archive(args,"gzip"); |
50 | } | 50 | } |
51 | static int write_tar_bzip2_archive(struct archiver_args *args) | 51 | static int write_tar_bzip2_archive(struct archiver_args *args) |
52 | { | 52 | { |
53 | return write_compressed_tar_archive(args,"bzip2"); | 53 | return write_compressed_tar_archive(args,"bzip2"); |
54 | } | 54 | } |
55 | 55 | ||
56 | static const struct snapshot_archive_t { | 56 | 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 | ||
67 | void cgit_print_snapshot(struct cacheitem *item, const char *hex, | 68 | void 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 | ||
78 | struct archiver_args args; | 82 | struct archiver_args args; |
79 | struct commit *commit; | 83 | struct commit *commit; |
80 | unsigned char sha1[20]; | 84 | unsigned char sha1[20]; |
81 | 85 | ||
82 | if(get_sha1(hex, sha1)) { | 86 | if(get_sha1(hex, sha1)) { |
83 | cgit_print_error(fmt("Bad object id: %s", hex)); | 87 | cgit_print_error(fmt("Bad object id: %s", hex)); |
84 | return; | 88 | return; |
85 | } | 89 | } |
86 | commit = lookup_commit_reference(sha1); | 90 | commit = lookup_commit_reference(sha1); |
87 | 91 | ||
88 | if(!commit) { | 92 | if(!commit) { |
89 | cgit_print_error(fmt("Not a commit reference: %s", hex)); | 93 | cgit_print_error(fmt("Not a commit reference: %s", hex)); |
90 | return;; | 94 | return;; |
91 | } | 95 | } |
92 | 96 | ||
93 | memset(&args,0,sizeof(args)); | 97 | memset(&args,0,sizeof(args)); |
94 | args.base = fmt("%s/", prefix); | 98 | args.base = fmt("%s/", prefix); |
95 | args.tree = commit->tree; | 99 | args.tree = commit->tree; |
96 | 100 | ||
97 | cgit_print_snapshot_start(sat->mimetype, filename, item); | 101 | cgit_print_snapshot_start(sat->mimetype, filename, item); |
98 | (*sat->write_func)(&args); | 102 | (*sat->write_func)(&args); |
99 | return; | 103 | return; |
100 | } | 104 | } |
101 | cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); | 105 | cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); |
102 | } | 106 | } |
103 | 107 | ||
104 | void cgit_print_snapshot_links(const char *repo,const char *hex) | 108 | void 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&name=%s",hex,filename)), filename); | 118 | fmt("id=%s&name=%s",hex,filename)), filename); |
114 | } | 119 | } |
115 | } | 120 | } |
121 | |||
122 | int 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: */ |