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
@@ -72,3 +72,4 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
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; |
@@ -237,4 +237,6 @@ 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 | ||
@@ -10,3 +10,4 @@ | |||
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 |
@@ -115,3 +116,3 @@ | |||
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 |
@@ -157,3 +157,3 @@ void cgit_global_config_cb(const char *name, const char *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")) |
@@ -199,3 +199,3 @@ void cgit_global_config_cb(const char *name, const char *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")) |
diff --git a/ui-commit.c b/ui-commit.c index bf5e6dc..50e9e11 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -198,3 +198,3 @@ void cgit_print_commit(char *hex) | |||
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>"); |
diff --git a/ui-snapshot.c b/ui-snapshot.c index 053fd48..d6be55b 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c | |||
@@ -59,7 +59,8 @@ static const struct snapshot_archive_t { | |||
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 | }; |
@@ -67,3 +68,4 @@ static const struct snapshot_archive_t { | |||
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 | { |
@@ -73,3 +75,5 @@ void cgit_print_snapshot(struct cacheitem *item, const char *hex, | |||
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)) |
@@ -103,3 +107,3 @@ void cgit_print_snapshot(struct cacheitem *item, const char *hex, | |||
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 | { |
@@ -109,2 +113,3 @@ void cgit_print_snapshot_links(const char *repo,const char *hex) | |||
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); |
@@ -115,2 +120,26 @@ void cgit_print_snapshot_links(const char *repo,const char *hex) | |||
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: */ |