summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c3
-rw-r--r--cgit.h6
-rw-r--r--cgitrc5
-rw-r--r--shared.c4
-rw-r--r--ui-commit.c2
-rw-r--r--ui-snapshot.c43
6 files changed, 48 insertions, 15 deletions
diff --git a/cgit.c b/cgit.c
index 7b55b7b..8795bbc 100644
--- a/cgit.c
+++ b/cgit.c
@@ -71,5 +71,6 @@ static void cgit_print_repo_page(struct cacheitem *item)
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 }
diff --git a/cgit.h b/cgit.h
index 1dbf901..ea61be7 100644
--- a/cgit.h
+++ b/cgit.h
@@ -236,6 +236,8 @@ extern void cgit_print_commit(char *hex);
236extern void cgit_print_diff(const char *new_hex, const char *old_hex); 236extern void cgit_print_diff(const char *new_hex, const char *old_hex);
237extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, 237extern void cgit_print_snapshot(struct cacheitem *item, const char *hex,
238 const char *prefix, const char *filename); 238 const char *prefix, const char *filename,
239extern void cgit_print_snapshot_links(const char *repo, const char *hex); 239 int snapshot);
240extern void cgit_print_snapshot_links(const char *repo, const char *hex,int snapshots);
241extern int cgit_parse_snapshots_mask(const char *str);
240 242
241#endif /* CGIT_H */ 243#endif /* CGIT_H */
diff --git a/cgitrc b/cgitrc
index 40877f8..1040997 100644
--- a/cgitrc
+++ b/cgitrc
@@ -9,5 +9,6 @@
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
@@ -114,5 +115,5 @@
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
diff --git a/shared.c b/shared.c
index 65fc8b2..ccbde27 100644
--- a/shared.c
+++ b/shared.c
@@ -156,5 +156,5 @@ void cgit_global_config_cb(const char *name, const char *value)
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);
@@ -198,5 +198,5 @@ void cgit_global_config_cb(const char *name, const char *value)
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);
diff --git a/ui-commit.c b/ui-commit.c
index bf5e6dc..50e9e11 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -197,5 +197,5 @@ void cgit_print_commit(char *hex)
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 }
diff --git a/ui-snapshot.c b/ui-snapshot.c
index 053fd48..d6be55b 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -58,13 +58,15 @@ static const struct snapshot_archive_t {
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);
@@ -72,5 +74,7 @@ void cgit_print_snapshot(struct cacheitem *item, const char *hex,
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;
@@ -102,5 +106,5 @@ void cgit_print_snapshot(struct cacheitem *item, const char *hex,
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;
@@ -108,4 +112,5 @@ void cgit_print_snapshot_links(const char *repo,const char *hex)
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/>",
@@ -114,3 +119,27 @@ void cgit_print_snapshot_links(const char *repo,const char *hex)
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: */