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 /ui-snapshot.c | |
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-- | ui-snapshot.c | 43 |
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 | |||
@@ -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: */ |