aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
@@ -70,7 +70,8 @@ static void cgit_print_repo_page(struct cacheitem *item)
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
diff --git a/cgit.h b/cgit.h
index 1dbf901..ea61be7 100644
--- a/cgit.h
+++ b/cgit.h
@@ -235,7 +235,9 @@ extern void cgit_print_tree(const char *rev, char *path);
235extern void cgit_print_commit(char *hex); 235extern 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
@@ -8,7 +8,8 @@
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
@@ -113,7 +114,7 @@
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
diff --git a/shared.c b/shared.c
index 65fc8b2..ccbde27 100644
--- a/shared.c
+++ b/shared.c
@@ -155,7 +155,7 @@ void cgit_global_config_cb(const char *name, const char *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"))
@@ -197,7 +197,7 @@ void cgit_global_config_cb(const char *name, const char *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"))
diff --git a/ui-commit.c b/ui-commit.c
index bf5e6dc..50e9e11 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -196,7 +196,7 @@ void cgit_print_commit(char *hex)
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");
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: */